Description:
Ionic 4+ app fails to build after adding the firebasex package
Steps to Reproduce:
Step 1: Create a latest blank ionic project
Step 2: Added the firebasex package onto the Ionic 4+ project
ionic cordova plugin add cordova-plugin-firebasex
npm install @ionic-native/firebase-x
Step 3: Generate google-services.json from firebase project and add to the project folder
Step 4: Add android platform and build for android
Error received: Getting the following error when build for android
This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to
true in the gradle.properties file and retry.
Step 5: Modify platforms/android/gradle.properties as follows and rebuild
android.useAndroidX=true,
android.enableJetifier=true
Same error as step 4 received and the flags get reset automatically to 'false' as follows
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m
android.useAndroidX=false
android.enableJetifier=false
cdvMinSdkVersion=22
Step 6: Add < preference name="AndroidXEnabled" value="true" /> in config.xml
ionic cordova prepare android
build for android
Error received: Task :app:compileDebugJavaWithJavac FAILED
/Users/XXX/Development/app1/platforms/android/app/src/main/java/com/ionicframework/cordova/webview/IonicWebViewEngine.java:11: error: package android.support.annotation does not exist
import android.support.annotation.RequiresApi;
Output:
/-----------------------------------------------------------------------------------------/
* Output for Step4 error
Prepared android project successfully
Executing script found in plugin cordova-plugin-firebasex for hook "after_prepare": plugins/cordova-plugin-firebasex/scripts/after_prepare.js
cordova-plugin-firebasex: Preparing Firebase on Android
No scripts found for hook "before_compile".
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=/Users/XXX/Library/Android/sdk (DEPRECATED)
Using Android SDK: /Users/XXX/Library/Android/sdk
Subproject Path: CordovaLib
Subproject Path: app
Gradle Distribution URL: https\://services.gradle.org/distributions/gradle-6.5-all.zip
Task :app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:mergeDebugResources'.
This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.
The following AndroidX dependencies are detected: androidx.appcompat:appcompat:1.1.0, androidx.slidingpanelayout:slidingpanelayout:1.0.0, androidx.versionedparcelable:versionedparcelable:1.1.0, androidx.fragment:fragment:1.1.0, androidx.core:core:1.2.0, androidx.customview:customview:1.0.0, androidx.swiperefreshlayout:swiperefreshlayout:1.0.0, androidx.constraintlayout:constraintlayout-solver:1.1.3, androidx.interpolator:interpolator:1.0.0, androidx.loader:loader:1.0.0, androidx.activity:activity:1.0.0, androidx.drawerlayout:drawerlayout:1.0.0, androidx.collection:collection:1.1.0, androidx.viewpager:viewpager:1.0.0, androidx.cardview:cardview:1.0.0, androidx.localbroadcastmanager:localbroadcastmanager:1.0.0, androidx.arch.core:core-common:2.1.0, androidx.savedstate:savedstate:1.0.0, androidx.annotation:annotation:1.1.0, androidx.lifecycle:lifecycle-common:2.1.0, androidx.appcompat:appcompat-resources:1.1.0, androidx.lifecycle:lifecycle-livedata:2.0.0, androidx.legacy:legacy-support-core-ui:1.0.0, androidx.lifecycle:lifecycle-viewmodel:2.1.0, androidx.constraintlayout:constraintlayout:1.1.3, androidx.lifecycle:lifecycle-livedata-core:2.0.0, androidx.browser:browser:1.0.0, androidx.arch.core:core-runtime:2.0.0, androidx.legacy:legacy-support-v4:1.0.0, androidx.media:media:1.0.0, androidx.legacy:legacy-support-core-utils:1.0.0, androidx.documentfile:documentfile:1.0.0, androidx.cursoradapter:cursoradapter:1.0.0, androidx.vectordrawable:vectordrawable-animated:1.1.0, androidx.lifecycle:lifecycle-runtime:2.1.0, androidx.vectordrawable:vectordrawable:1.1.0, androidx.coordinatorlayout:coordinatorlayout:1.0.0, androidx.asynclayoutinflater:asynclayoutinflater:1.0.0, androidx.print:print:1.0.0
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 959ms
9 actionable tasks: 2 executed, 7 up-to-date
Command failed with exit code 1: /Users/[email protected]/Development/radian_rates_v5/platforms/android/gradlew cdvBuildDebug -b /Users/[email protected]/Development/radian_rates_v5/platforms/android/build.gradle
Error: Command failed with exit code 1: /Users/[email protected]/Development/radian_rates_v5/platforms/android/gradlew cdvBuildDebug -b /Users/[email protected]/Development/radian_rates_v5/platforms/android/build.gradle
at makeError (/Users/[email protected]/Development/radian_rates_v5/platforms/android/cordova/node_modules/execa/lib/error.js:59:11)
at handlePromise (/Users/[email protected]/Development/radian_rates_v5/platforms/android/cordova/node_modules/execa/index.js:114:26)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
[ERROR] An error occurred while running subprocess cordova.
cordova build android --verbose exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
ionic:utils-process onBeforeExit handler: 'process.exit' received +0ms
ionic:utils-process onBeforeExit handler: running 2 functions +0ms
ionic:utils-process processExit: exiting (exit code: 1) +37ms
/-----------------------------------------------------------------------------------------/
**Note: The following error occurs when < preference name="AndroidXEnabled" value="true" > is added in the config.xml
cordova-plugin-firebasex: Preparing Firebase on Android
No scripts found for hook "before_compile".
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=/Users/XXX/Library/Android/sdk (DEPRECATED)
Using Android SDK: /Users/XXX/Library/Android/sdk
Subproject Path: CordovaLib
Subproject Path: app
Gradle Distribution URL: https\://services.gradle.org/distributions/gradle-6.5-all.zip
Task :app:compileDebugJavaWithJavac FAILED
/Users/XXX/Development/app1/platforms/android/app/src/main/java/com/ionicframework/cordova/webview/IonicWebViewEngine.java:11: error: package android.support.annotation does not exist
import android.support.annotation.RequiresApi;
^
/Users/XXX/Development/app1/platforms/android/app/src/main/java/com/ionicframework/cordova/webview/IonicWebViewEngine.java:137: error: cannot find symbol
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
^
symbol: class RequiresApi
location: class IonicWebViewEngine.ServerClient
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
23 actionable tasks: 2 executed, 21 up-to-date
Command failed with exit code 1: /Users/XXX/Development/app1/platforms/android/gradlew cdvBuildDebug -b /Users/XXX/Development/app1/platforms/android/build.gradle
Error: Command failed with exit code 1: /Users/XXX/Development/app1/platforms/android/gradlew cdvBuildDebug -b /Users/XXX/Development/app1/platforms/android/build.gradle
at makeError (/Users/XXX/Development/app1/platforms/android/cordova/node_modules/execa/lib/error.js:59:11)
at handlePromise (/Users/XXX/Development/app1/platforms/android/cordova/node_modules/execa/index.js:114:26)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
[ERROR] An error occurred while running subprocess cordova.
cordova build android --verbose exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
ionic:utils-process onBeforeExit handler: 'process.exit' received +0ms
ionic:utils-process onBeforeExit handler: running 2 functions +0ms
ionic:utils-process processExit: exiting (exit code: 1) +41ms
/-----------------------------------------------------------------------------------------/
My ionic info:
Ionic:
Ionic CLI : 6.11.0 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.3.3
@angular-devkit/build-angular : 0.1000.8
@angular-devkit/schematics : 10.0.8
@angular/cli : 10.0.8
@ionic/angular-toolkit : 2.3.3
Cordova:
Cordova CLI : 10.0.0
Cordova Platforms : android 9.0.0, ios 6.1.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 8 other plugins)
Utility:
cordova-res (update available: 0.15.1) : 0.14.0
native-run (update available: 1.1.0) : 1.0.0
System:
Android SDK Tools : 26.1.1 (/Users/XXX/Library/Android/sdk)
ios-deploy : 1.10.0
ios-sim : 8.0.2
NodeJS : v12.18.0 (/usr/local/bin/node)
npm : 6.14.8
OS : macOS Catalina
Xcode : Xcode 12.0 Build version 12A7209
Any updates on the above issue?
I just found out that Cordova Platforms : android 9.0.0 is causing the issue.
I have downgraded the version to 8.1.0 and the build issue disappeared. But the ionic cordova run android --emulator is no longer working
Hope this will help to resolve the issue with latest version of android 9.0.0
any news on that?
Any updates? The latest cordova-android 9.0.0 causing this issue.
Hi Guys, I hope i am not very late to reply but i think, this issue can be avoided by adding ionic cordova plugin add cordova-plugin-androidx and ionic cordova plugin add cordova-plugin-androidx-adapter all you have to do is run this command and the error will be disappeared. The error comes because this project is not using androidX but these plugins solve error.
Hi Guys, I hope i am not very late to reply but think issue can be avoided by adding
ionic cordova plugin add cordova-plugin-androidxandionic cordova plugin add cordova-plugin-androidx-adapterall you have to do is run this command and the error will be disappeared. The error comes because this project is not using androidX but these plugins solve error.
It really worked for me thanks a lot !!
Hi Guys, I hope i am not very late to reply but think issue can be avoided by adding
ionic cordova plugin add cordova-plugin-androidxandionic cordova plugin add cordova-plugin-androidx-adapterall you have to do is run this command and the error will be disappeared. The error comes because this project is not using androidX but these plugins solve error.
Works for me, thanks so much!
Although this does make your app build, it doesn't really solve the problem, as the plugin author @dpa99c notes:
https://github.com/dpa99c/cordova-plugin-androidx#deprecation-notice
This plugin is deprecated as it's no longer required since cordova-android@9 adds built-in support for AndroidX.
This plugin is only needed if your project uses legacy cordova-android@8.
If you update to cordova-android@9 and your project contains this plugin then you should remove it.
So I'm kinda hoping this issue "is" going to get looked at
Edit:
The way I got this to build with cordova-android 9:
#start without the androidx plugins installed
ionic cordova plugin remove cordova-plugin-androidx
ionic cordova plugin remove cordova-plugin-androidx-adapter
#also remove the platform
ionic cordova platform add android
#re-add everything
--ionic cordova plugin add cordova-plugin-androidx--- (not needed see further edit below)
ionic cordova plugin add cordova-plugin-androidx-adapter
ionic cordova platform add android
#make sure your config.xml will work, I had to add to the android platform section (YMMV):
<preference name="AndroidXEnabled" value="true"/> (see further edit below)
<preference name="android-minSdkVersion" value="22" />
<preference name="android-targetSdkVersion" value="29"/>
#build
ionic cordova build android
---only downside, is my /platform/android/gradle.properties now seems to fill up with spurious additions of android.useAndroidX and android.enableJetifier--- <- nope, this doesn't happen if you "don't" use this cordova-plugin-androidx plugin
Further Edit:
I just realised that all the cordova-plugin-androidx plugin does is add in the androidx=true stuff in config.xml. if you then use the recommended
<preference name="AndroidXEnabled" value="true"/>
as suggested by the OP (and referenced here: https://cordova.apache.org/announcements/2020/06/29/cordova-android-9.0.0.html) then you don't actually need that plugin, but you "do" still need the cordova-plugin-androidx-adapter plugin
Hi Guys, I hope i am not very late to reply but i think, this issue can be avoided by adding
ionic cordova plugin add cordova-plugin-androidxandionic cordova plugin add cordova-plugin-androidx-adapterall you have to do is run this command and the error will be disappeared. The error comes because this project is not using androidX but these plugins solve error.
This fix worked for me. Thank you very much...
Hi Guys, I hope i am not very late to reply but i think, this issue can be avoided by adding
ionic cordova plugin add cordova-plugin-androidxandionic cordova plugin add cordova-plugin-androidx-adapterall you have to do is run this command and the error will be disappeared. The error comes because this project is not using androidX but these plugins solve error.
thnx... its working
Hi Guys, I hope i am not very late to reply but think issue can be avoided by adding
ionic cordova plugin add cordova-plugin-androidxandionic cordova plugin add cordova-plugin-androidx-adapterall you have to do is run this command and the error will be disappeared. The error comes because this project is not using androidX but these plugins solve error.It really worked for me thanks a lot !!
Thank you, your solution works
Hi Guys, I hope i am not very late to reply but i think, this issue can be avoided by adding
ionic cordova plugin add cordova-plugin-androidxandionic cordova plugin add cordova-plugin-androidx-adapterall you have to do is run this command and the error will be disappeared. The error comes because this project is not using androidX but these plugins solve error.
It really worked for me Thank you
Hi Guys, I hope i am not very late to reply but think issue can be avoided by adding
ionic cordova plugin add cordova-plugin-androidxandionic cordova plugin add cordova-plugin-androidx-adapterall you have to do is run this command and the error will be disappeared. The error comes because this project is not using androidX but these plugins solve error.It really worked for me thanks a lot !!
It really worked for me Thank you
It really worked for me Thank you
ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter
these command really worked for me. Its really helpful.
Thank you
In case people miss it... you don't actually need cordova-plugin-androidx
https://github.com/ionic-team/ionic-cli/issues/4562#issuecomment-714676906
Most helpful comment
Hi Guys, I hope i am not very late to reply but i think, this issue can be avoided by adding
ionic cordova plugin add cordova-plugin-androidxandionic cordova plugin add cordova-plugin-androidx-adapterall you have to do is run this command and the error will be disappeared. The error comes because this project is not using androidX but these plugins solve error.