Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Ionic build - missing ANDROID_SDK_VERSION #650

Closed
dhavalsoni2001 opened this issue Apr 24, 2018 · 30 comments
Closed

Ionic build - missing ANDROID_SDK_VERSION #650

dhavalsoni2001 opened this issue Apr 24, 2018 · 30 comments

Comments

@dhavalsoni2001
Copy link

ionic build android throwing an error and not able to generate APK.

screen shot 2018-04-24 at 3 46 45 pm

System information:

Cordova CLI: 6.5.0
Gulp version: CLI version 3.9.1
Gulp local: Local version 3.9.1
Ionic Framework Version: 1.3.2
Ionic CLI Version: 1.7.16
Ionic App Lib Version: 0.7.3
ios-deploy version: 1.9.2
ios-sim version: Not installed
OS: Mac OS X El Capitan
Node Version: v6.11.4
Xcode version: Xcode 9.2 Build version 9C40b

@peterpeterparker
Copy link
Collaborator

peterpeterparker commented Apr 24, 2018

Plz provide more information

Plugin version ?
config.xml ?

ANDROID_SDK_VERSION isn't defined but should have a default value (see Android Guide)

P.S.: @skaman since you created the PR #646, plz follow this issue

@dhavalsoni2001
Copy link
Author

@peterpeterparker
config.xml :

  <plugin name="cordova-plugin-facebook4" spec="git+https://github.com/jeduan/cordova-plugin-facebook4.git">
    <variable name="APP_ID" value="FB_APP_ID"/>
    <variable name="APP_NAME" value="FB_APP_NAME"/>
  </plugin>

@peterpeterparker
Copy link
Collaborator

could you check if the following piece of code does exist in your plugins/cordova-plugin-facebook4/plugin.xml ?

<preference name="ANDROID_SDK_VERSION" default="4.+"/>

@dhavalsoni2001
Copy link
Author

Yes its there.

@skaman
Copy link

skaman commented Apr 24, 2018

@dhavalsoni2001 did you updated the plugin or just installed it?

@dhavalsoni2001
Copy link
Author

I have tried with update its not working so I have uninstall it and then install it, still its not working.

@peterpeterparker
Copy link
Collaborator

I guess if you add following variable it should works but shouldn't the default value be picked @skaman ?

<variable name="ANDROID_SDK_VERSION" value="4.+"/>

@peterpeterparker peterpeterparker changed the title ionic build failed for android Ionic build - missing ANDROID_SDK_VERSION Apr 24, 2018
@skaman
Copy link

skaman commented Apr 24, 2018

@dhavalsoni2001 you can try to add the variable inside the config.xml as @peterpeterparker said, but i've some doubts because ionic have also the same values in packages.json and maybe also in other places.

I think your cordova version is not handling correctly the default variable. My ideas are:

  • update your cordova cli that maybe is too old. I'm using cordova 7.1.0 (after cordova update you maybe need to remove and readd the plugin)
  • try to specify the sdk version when you install it. Ex: ionic cordova plugin add cordova-plugin-facebook4 --save --variable APP_ID="123456789" --variable APP_NAME="myApplication" --variable ANDROID_SDK_VERSION="4.+"

@peterpeterparker
Copy link
Collaborator

peterpeterparker commented Apr 24, 2018

@skaman could you give a try with a dummy repo to double check that the ANDROID_SDK_VERSION correctly get a default value even if not defined in config.xml, just to be sure?

@skaman
Copy link

skaman commented Apr 24, 2018

@peterpeterparker i was speaking about cordova cli version, the cordova android version could stay the same.

I did a test creating a ionic project from scratch and adding the plugin. The default variable is not saved inside the config.xml but is used correctly from the platform (you can find it inside the file platforms/android/android.json). The project compile succesfully.

I attach the shell log about my test
facebook-plugin-ionic-test.txt

@peterpeterparker
Copy link
Collaborator

peterpeterparker commented Apr 24, 2018

@skaman thx for pointing that out and THX A LOT for double checking!

this confirm that there isn't any problem not having the variable ANDROID_SDK_VERSION in config.xml even with cordova-android < 7

we could keep the issue open for a bit till op fix his/her problem in his/her project but it looks like it isn't related to the code of the plugin itself

@tmzblue
Copy link

tmzblue commented Apr 25, 2018

Hello guys,

I'm also getting the same error in my Ionic project.

Initially, I thought it could be some sort of misconfiguration. To sort things out, I created a new Ionic starter project, installed the plugin and tried to build the .apk. Unfortunately, the build failed.

I'm attaching the log with the commands I used to repro the problem:
starter-project-console-log.txt

Any help appreciated.

System Info:
Cordova CLI: 6.5.0
Ionic CLI Version: 3.20.0
OS: Windows 10 Pro

@peterpeterparker
Copy link
Collaborator

First of all thx @tmzblue I really appreciate your detailed feedback!

So it looks like the problem is what @skaman described above, you also use an older version of the cordova cli

Therefore I see the following solutions:

  1. @skaman do you think you could improve the code in order to be compatible with older cordova version?

  2. if no, should we "just" add a notice in the "android guide" of the plugin in order to make it clear that in case of cordova cli <7 the property ANDROID_SDK_VERSION as to be specified in the config.xml

or

  1. do we rollback the PR

let me know guys what you think/rather like. I'm fine with adding a notice in the guide but I'm open

@peterpeterparker
Copy link
Collaborator

I have added a notice about the compatibility with older Cordova CLI in the Android Guide https://github.com/jeduan/cordova-plugin-facebook4/blob/master/docs/android/README.md

Summarized:

  • Android CLI <7, ANDROID_SDK_VERSION has to be specified in config.xml or at install time in order to set the default value "4.+" because otherwise it won't found. You could also update your old Cordova CLI if you could and that will solve the issue too

  • Android CLI >= 7, no problem

Therefore I close the issue.

In case you would be not agree with this, no problemo, let me know. I just think that the CLI 6.5 is relatively old and therefore that this is acceptable.

@skaman
Copy link

skaman commented Apr 26, 2018

@peterpeterparker yes, in my opinion update the doc is the better solution (but i needed that fix, so my opinion is based on my needs 😁).

I don't think there is any workaround to avoid the issue by code.

@dhavalsoni2001 and @tmzblue have you tried to update the cli or specify manually that variable? Is it working?

@tmzblue
Copy link

tmzblue commented Apr 26, 2018

Hello @peterpeterparker and @skaman,

I agree with the solution. After updating cordova cli to v8 I ran some tests and the problem was gone.

Thx! 😛

@peterpeterparker
Copy link
Collaborator

@skaman @tmzblue cool thx for testing and for your feedbacks!

@giangambero
Copy link

Hello, i'm getting the same error with cordova cli 8.0 and a project created by cordova template of Microsoft Visual Studio 2017. Thanks in advance for any suggestion.

1>MSBUILD : cordova-build error : FAILURE: Build failed with an exception.
1>MSBUILD : cordova-build error : * Where:

1>MSBUILD : cordova-build error : Build file 'C:\Users\gianc\source\repos\xxx\xxx\platforms\android\build.gradle' line: 255
1>MSBUILD : cordova-build error : * What went wrong:
1>MSBUILD : cordova-build error : A problem occurred evaluating root project 'android'.
1>MSBUILD : cordova-build error : > Could not get unknown property 'ANDROID_SDK_VERSION' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
1>MSBUILD : cordova-build error : * Try:
1>MSBUILD : cordova-build error : Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Command finished with error code 1: cmd /s /c "C:\Users\gianc\source\repos\xxx\xxx\platforms\android\gradlew.bat cdvBuildDebug -b C:\Users\gianc\source\repos\xxx\xxx\platforms\android\build.gradle -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx2048m -Pandroid.useDeprecatedNdk=true"

------ Nuova copia nel progetto: android
1>MSBUILD : cordova-build error : (node:18040) UnhandledPromiseRejectionWarning: Error: cmd: Command failed with exit code 1 Error output:
1>MSBUILD : cordova-build error : FAILURE: Build failed with an exception.
1>MSBUILD : cordova-build error : * Where:
1>MSBUILD : cordova-build error : Build file 'C:\Users\gianc\source\repos\xxx\xxx\platforms\android\build.gradle' line: 255
1>MSBUILD : cordova-build error : * What went wrong:
1>MSBUILD : cordova-build error : A problem occurred evaluating root project 'android'.
1>MSBUILD : cordova-build error : > Could not get unknown property 'ANDROID_SDK_VERSION' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
1>MSBUILD : cordova-build error : * Try:
1>MSBUILD : cordova-build error : Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
1>MSBUILD : cordova-build error : Picked up _JAVA_OPTIONS: -Xmx512M
1>MSBUILD : cordova-build error : at ChildProcess.whenDone (C:\Users\gianc\source\repos\xxx\xxx\platforms\android\cordova\node_modules\cordova-common\src\superspawn.js:169:23)
1>MSBUILD : cordova-build error : at ChildProcess.emit (events.js:160:13)
1>MSBUILD : cordova-build error : at maybeClose (internal/child_process.js:943:16)
1>MSBUILD : cordova-build error : at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
1>MSBUILD : cordova-build error : (node:18040) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
1>MSBUILD : cordova-build error : (node:18040) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
1>Compilazione progetto "xxxx.jsproj" completata.

@lukasstaecker
Copy link

lukasstaecker commented Apr 30, 2018

Hey guys, is there any workaround for this problem using cordova-android 6.3.0? I can't upgrade to cordova-android 7.0.0 because it's not supported by cordova-plugin-compat which is a dependency of various other plugins. Thanks for helping!

EDIT: Nevermind, cordova-plugin-compat can be removed by force when using cordova-android >6.3.0 with "cordova plugin rm cordova-plugin-compat --force", if anyone else wonders. The project finally builds again!

@peterpeterparker
Copy link
Collaborator

@giangambero try to remove add the platform

as @skaman described and tested above, you should not face this with cli 8

in any case if problem persists, just add the plugin with the variable and problem will be solved

@lukasstaecker
Copy link

lukasstaecker commented May 3, 2018

For me, the problem persists even with cordova cli 8 and when adding the plugin with the variable. The only thing that fixed it for me was updating the platform to cordova-android 7.0.0. However, I'm still facing issues with this update, so I would appreciate any alternative to make it work on cordova-android 6.2.1.

@peterpeterparker
Copy link
Collaborator

peterpeterparker commented May 3, 2018

@Lukizzle to be honest I don't know, look like everybody following this issue was able to solve the issue by upgrading or updating or specifying the variable. So I would spontaneously say that I see the following options (but probably someone more clever would come with better or other idea):

  1. you could edit manually your local platform gradle / project.properties and add the library, something like

        cordova.system.library.....=com.facebook.android:facebook-android-sdk:4.+
    
  2. you could not update the plugin and revert to version facebook4 plugin v1.10.1

  3. you could try to fix the problem you are facing and submit a PR to solve it

@artuska
Copy link

artuska commented May 7, 2018

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

This happens when you install cordova-plugin-facebook4 plugin 2.1.0 version.

It changes your project.properties file from

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

to

cordova.system.library.2=com.facebook.android:facebook-android-sdk:$ANDROID_SDK_VERSION

ANDROID_SDK_VERSION variable exists in plugins/cordova-plugin-facebook4/config.xml

<preference name="ANDROID_SDK_VERSION" default="4.+"/>

and in main config.xml:

<plugin name="cordova-plugin-facebook4" spec="~2.1.0">
    <variable name="APP_ID" value="150722098901852" />
    <variable name="APP_NAME" value="Balu" />
    <variable name="ANDROID_SDK_VERSION" value="4.+" />
</plugin>

but it does not work at all — error is still thrown.

@peterpeterparker
Copy link
Collaborator

@artuska your cordova Cli version? if < 7, see my last answer above

@Moghul
Copy link

Moghul commented May 9, 2018

For anyone else with this problem, here's what works for me
Cordova-cli 8.0.0
Cordova-android 6.3.0
cordova-plugin-facebook 2.1.0

cordova plugin add cordova-plugin-facebook4 --save --variable APP_ID="123456789" --variable APP_NAME="myApplication" --variable ANDROID_SDK_VERSION="4.+"
cordova platform remove android
cordova platform add android@6.3.0
cordova prepare android

@Boldonglen
Copy link

Ive been though this post as well as several others I found on the internet and I still cant seem to build my ionic application for android:

Cordova-cli: 7.1.0
Cordova-android:6.3.0
cordova-plugin-facebook 2.1.0
Ionic: 3.20.0

I have tried adding and removing the package using:

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

I have tried adding and removing android using:

cordova platform remove android
cordova platform add android@6.3.0

I have tried lost of combinations of the the above and after running "ionic cordova run android --device" still get the error:

* 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.

This is what is in my config.xml for the project:

<plugin name="cordova-plugin-facebook4" spec="^2.1.0">
        <variable name="APP_ID" value="123456789" />
        <variable name="APP_NAME" value="myApp" />
        <variable name="ANDROID_SDK_VERSION" value="4.+" />
    </plugin>

@peterpeterparker
Copy link
Collaborator

@Boldonglen see my answer above, try to modify your project.properties manually or downgrade the plugin to v1.10.1 or maybe if you could send a PR to fix this for old cordova-android version

@Boldonglen
Copy link

Hi @peterpeterparker I'm not sure how to fix the issue so can't send a pull request. As far as I am aware I am using the latest versions of all packages so not sure why it shouldn't be working? My cordova-android version is the same as other people's in this thread that have successfully got the plugin working so not sure why mine isn't working?

@peterpeterparker
Copy link
Collaborator

@Boldonglen like I said you could then try to downgrade the plugin version to v1.10.1 otherwise you could also update cordova-android to a newer version which are for sure compatible

@daymonique
Copy link

daymonique commented Jan 16, 2019

I had the same issue in my project (cordova 7.0), putting <variable name="FACEBOOK_ANDROID_SDK_VERSION" value="4.+" />
didn't work for me. I had to change the value of
cordova.system.library.4=com.facebook.android:facebook-android-sdk:FACEBOOK_ANDROID_SDK_VERSION
to
cordova.system.library.4=com.facebook.android:facebook-android-sdk:4.14.+
in the platform/android/project.properties file.

This file is automatically generated by Android Tools, so i created a cordova hook to do it after add platform in cordova.

More info: https://cordova.apache.org/docs/en/latest/guide/appdev/hooks/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants