Could not get unknown property 'ANDROID_SDK_VERSION' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler


#1

I have the following

/my-app/config.xml

...
<engine name="android" spec="^6.4.0" />
    <plugin name="cordova-plugin-device" spec="^1.1.7" />
    <plugin name="cordova-plugin-facebook4" spec="^2.4.0">
        <variable name="APP_ID" value="123456789" />
        <variable name="APP_NAME" value="my-app" />
    </plugin>
    <plugin name="cordova-plugin-ionic-webview" spec="^1.2.1" />
    <plugin name="cordova-plugin-splashscreen" spec="^4.1.0" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
    <plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
...

/my-app/package.json

...
"cordova": {
        "plugins": {
            "cordova-plugin-facebook4": {
                "APP_ID": "123456789",
                "APP_NAME": "my-app"
            },
            "cordova-plugin-device": {},
            "cordova-plugin-ionic-webview": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {}
        },
        "platforms": [
            "android"
        ]
    }
...

ionic info

cli packages: (/usr/lib/node_modules)

@ionic/cli-utils  : 1.9.2
ionic (Ionic CLI) : 3.9.2

global packages:

Cordova CLI : 7.0.1 

local packages:

@ionic/app-scripts : 3.1.0
Cordova Platforms  : android 6.4.0
Ionic Framework    : ionic-angular 3.9.2

System:

Node : v8.11.4
npm  : 5.6.0 
OS   : Linux 4.15

Context:
When I run :ionic cordova build android

> ionic cordova prepare
> cordova prepare
✔ Running command - done!

> cordova build android
✖ Running command - failed!
[ERROR] An error occurred while running cordova build android (exit code 1):

        
        ANDROID_HOME=/home/rreyes/android-sdk-linux
        JAVA_HOME=/usr/lib/jvm/java-8-oracle
        Subproject Path: CordovaLib
        The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use 
        Task.doLast(Action) instead.
        	at build_8oeka4t56dp9oa43kn5u8er7z.run(/home/rreyes/workspace/my-app/platforms/android/build.gradle:141)
        
        FAILURE: Build failed with an exception.
        
        * Where:
        Build file '/home/rreyes/workspace/tennis-up-app/platforms/android/build.gradle' line: 255
        
        * What went wrong:
        A problem occurred evaluating root project 'android'.
        > Could not get unknown property 'ANDROID_SDK_VERSION' for object of type 
        org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
        
        * Try:
        Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
        
        * Get more help at https://help.gradle.org
        
        BUILD FAILED in 2s
        Error: /home/rreyes/workspace/my-app/platforms/android/gradlew: Command failed with exit code 1 Error 
        output:
        FAILURE: Build failed with an exception.
        
        * Where:
        Build file '/home/rreyes/workspace/my-app/platforms/android/build.gradle' line: 255
        
        * What went wrong:
        A problem occurred evaluating root project 'android'.
        > Could not get unknown property 'ANDROID_SDK_VERSION' for object of type 
        org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
        
        * Try:
        Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
        
        * Get more help at https://help.gradle.org
        
        BUILD FAILED in 2s

I did set an env variable for ANDROID_SDK_VESION =“4.+”

Question: What I need to do to get a build success running ionic cordova build android?


#2

look like the installation didn’t picked ANDROID_SDK_VERSION when you installed it, try to reinstall it with explicitly specifying it

ionic cordova plugin rm cordova-plugin-facebook4 --save
ionic cordova plugin add cordova-plugin-facebook4 --variable ANDROID_SDK_VERSION="4.+” --variable --variable APP_ID="123456789" --variable APP_NAME="myApplication" --save

#3

Hi, it did not work. =(


#4

Try this
<engine name="android" spec="^7.0.0" />


#5

Also the properties ANDROID_SDK_VERSION has just been renamed, that could explain it :wink:

New name : FACEBOOK_ANDROID_SDK_VERSION

ionic cordova plugin rm cordova-plugin-facebook4 --save
ionic cordova plugin add cordova-plugin-facebook4 --variable FACEBOOK_ANDROID_SDK_VERSION="4.+” --variable --variable APP_ID="123456789" --variable APP_NAME="myApplication" --save

#6

I still get the same error.


#7

Hi, now the erros displays
FAILURE: Build failed with an exception.

    * Where:
    Build file '/home/rreyes/workspace/tennis-up-app/platforms/android/build.gradle' line: 255

    * What went wrong:
    A problem occurred evaluating root project 'android'.
    > Could not get unknown property 'FACEBOOK_ANDROID_SDK_VERSION' for object of type
    org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

/home/rreyes/workspace/tennis-up-app/platforms/android/build.gradle’ line: 255 contains the following code

dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    implementation(project(path: "CordovaLib"))
    compile "com.facebook.android:facebook-android-sdk:$FACEBOOK_ANDROID_SDK_VERSION"
    // SUB-PROJECT DEPENDENCIES END
}

and the config.xml

&lt;plugin name="cordova-plugin-facebook4" spec="^3.0.0"&gt;

&lt;variable name="APP_ID" value="2155965454685229" /&gt;

&lt;variable name="APP_NAME" value="tennis-up-app" /&gt;

&lt;variable name="FACEBOOK_ANDROID_SDK_VERSION" value="4.+" /&gt;

&lt;/plugin&gt;

#8

cordova-plugin-facebook4@3.0.0 came out 12 hours ago. Might be worth a try to go for 2.5.0.


#9

There is almost no change in 3.0.0, the difference is that as from now on the Facebook SDK for iOS and Android are going to always be sync

Also I would rather try with 3.0.0 that 2.5.0 because in 3.0.0 the Facebook Android SDK is set to 4.36.0 and not 4.+


#10

This property has been renamed to FACEBOOK_ANDROID_SDK_VERSION, see CHANGELOG of the plugin


#11

@zwacky @reedrichards Thanks for your help. I just upgrade to v 3.0.0 and get the same error that pointed in the last comment with FACEBOOK_ANDROID_SDK_VERSION, It’s like the plugin isn’t reading the value (4.+) from config.xml, so as a workaround I have harcoded that value in the file:
my-app/platforms/android/project.properties as the following:

cordova.system.library.1=com.facebook.android:facebook-android-sdk:4.+

Then I ran the android build and it works!


#12

I thought about it and I think it didn’t pick the value because you are using a cordova cli which is probably older than v7

it’s documented see “older cordova cli” with a link to an issue with different solutions: https://github.com/jeduan/cordova-plugin-facebook4/blob/master/docs/android/README.md

but a solution is of course to upgrade the cordova cli

anyhow if you solved it, you solved it, cool


#13

Thank you for you answer. I looks like it worked for me. Do you know any idea why this is such a mess all the type with this technology stack?


#14

You just saved my day sir !
But yeah why is it such a mess i’ve read like all the internet and you were he only one talking about project.properties to fix this issue …
It’s really like the plugin is not reading the value from config.xml …