迁移到androidx后出现离子android生成错误 [英] Ionic android build error after migrating to androidx

查看:256
本文介绍了迁移到androidx后出现离子android生成错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理ionic 3项目.由于突然的构建问题,我不得不迁移到androidx.我用cordova-android@8.0.0版本创建了android平台,做了很多工作,但现在在构建android平台时遇到了其他错误

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

我用cordova-android版本8.0.0创建了android平台.

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

将以下行添加到gradle.properties文件中

Added below lines to gradle.properties file

android.useAndroidX = true android.enableJetifier = true

android.useAndroidX=true android.enableJetifier=true

将插件更新为最新版本

这是我的project.properties文件

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) {
                                          ^

任何帮助将不胜感激.

推荐答案

由于您的Android项目包含引用了Android支持库的Java源代码(可能是Cordova插件的形式)而出现了错误,但您已在其中启用了AndroidX您的项目.
AndroidX和Android支持库不能同时存在于同一个Android项目中-这样做会导致诸如此类的构建失败.
从您的project.properties中可以看出,支持库是作为Gradle依赖项(例如cordova.system.library.3=com.android.support:support-v4:28.+)引入的.

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)是 Play Services& Firebase库.
许多现有的插件都使用了Support库,例如 cordova-plugin-firebase .

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.

要解决此问题,请在Cordova项目中添加以下两个插件:

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.

有关在测试项目中的工作示例,请参见我对这个Github问题的评论.

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

注意:如果您使用的是 cordova-plugin-firebase 并遇到错误,您可以改用我的该插件的分叉 cordova-plugin-firebasex,已修复,可解决由新的Firebase SDK引起的问题.这是最安全的迁移方式:

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

这篇关于迁移到androidx后出现离子android生成错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆