Ionic android build error after migrating to androidx

亡梦爱人 提交于 2019-12-13 04:33:11

问题


I am working on an ionic 3 project.i had to migrate to androidx due to a sudden build issue. I created the android platform with cordova-android@8.0.0 version and i did the needful but now i'm getting some other errors while building the android platform

I created the android platform with cordova-android version 8.0.0.

Added below lines to gradle.properties file

android.useAndroidX=true android.enableJetifier=true

Updated the plugins to the latest

this is my project.properties file

target=android-28
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.gradle.include.2=cordova-plugin-appsflyer-sdk/userapp-cordovaAF.gradle
cordova.system.library.1=com.facebook.android:facebook-android-sdk:4.40.0
cordova.gradle.include.3=cordova-plugin-firebase/userapp-build.gradle
cordova.system.library.2=com.google.android.gms:play-services-tagmanager:+
cordova.system.library.10=com.google.firebase:firebase-core:17.0.0
cordova.system.library.11=com.google.firebase:firebase-messaging:19.0.0
cordova.system.library.12=com.google.firebase:firebase-config:18.0.0
cordova.system.library.13=com.google.firebase:firebase-perf:18.0.0
cordova.gradle.include.4=cordova-plugin-googlemaps/userapp-tbxml-android.gradle
cordova.gradle.include.5=cordova-plugin-googlemaps/userapp-apikey.gradle
cordova.system.library.7=com.google.android.gms:play-services-maps:15.0.1
cordova.system.library.8=com.google.android.gms:play-services-location:15.0.1
cordova.system.library.9=com.android.support:support-core-utils:27.+
cordova.system.library.10=com.mixpanel.android:mixpanel-android:5.6.0
cordova.system.library.11=com.google.android.gms:play-services-base:+
cordova.system.library.14=com.android.support:support-v4:28.+
cordova.system.library.15=com.android.support:appcompat-v7:28.+
cordova.system.library.3=com.android.support:support-v4:28.+
cordova.system.library.4=com.android.support:appcompat-v7:28.+

When i build the project now im getting below mentioned errors

error: cannot find symbol
import android.support.v4.app.ActivityCompat;
                             ^
 cannot find symbol
import android.support.v4.os.EnvironmentCompat;

error: cannot find symbol
          public void onConnectionFailed(@NonNull ConnectionResult result) {
                                          ^

Any help would be much appreciated.Thanks


回答1:


The errors are arising because your Android project contains Java source code (presumably in the form of Cordova plugins) which references the Android Support Library but you have enabled AndroidX in your project.
AndroidX and the Android Support Library cannot live side-by-side in the same Android project - doing so will lead to build failures such as this.
From your project.properties it can been seen that the Support Library is being pulled in as a Gradle dependency (e.g. cordova.system.library.3=com.android.support:support-v4:28.+).

AndroidX (Jetpack) is the successor to the Android Support Library.
Note that AndroidX is now used by the latest versions of Play Services & Firebase libraries.
The Support library is used by many existing plugins such as cordova-plugin-firebase.

To resolve this issue, add the following two plugins your Cordova project:

  • cordova-plugin-androidx to enable AndroidX in the Android project.
  • cordova-plugin-androidx-adapter to dynamically patch the source code of any plugins using the Support Library to use the AndroidX equivalents and to patch the Gradle config to replace Android Support Library references with AndroidX equivalents.

For a working example of this in a test project, see my comment on this Github issue.

Note: if you are using cordova-plugin-firebase and encountering errors, you can instead use my fork of that plugin which is published as cordova-plugin-firebasex and is fixed to resolve issues caused by the new Firebase SDK. Here's the safest way to migrate:

rm -Rf platforms/android
cordova plugin rm cordova-plugin-firebase
rm -Rf plugins/ node_modules/
npm install
cordova plugin add cordova-plugin-firebasex
cordova platform add android


来源:https://stackoverflow.com/questions/56664901/ionic-android-build-error-after-migrating-to-androidx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!