迁移到 androidx 后 Ionic android 构建错误 [英] Ionic android build error after migrating to androidx

查看:42
本文介绍了迁移到 androidx 后 Ionic 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=trueandroid.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) {
                                          ^

任何帮助将不胜感激.谢谢

Any help would be much appreciated.Thanks

推荐答案

出现错误是因为您的 Android 项目包含引用 Android 支持库的 Java 源代码(可能是 Cordova 插件的形式),但您在你的项目.
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) 是 Android 支持库.
请注意,最新版本的 Play Services &Firebase 库.
支持库被许多现有插件使用,例如 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 并遇到错误,您可以改用 my fork of that plugin 发布为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 后 Ionic android 构建错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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