React Native:迁移到 AndroidX [英] React Native: Migrate to AndroidX
问题描述
我今天运行了我的 Android RN 项目,但出现以下错误
I ran my Android RN project today and was presented with the following error
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.v4.app.INotificationSideChannel$Stub
我认为为了解决这个问题,需要迁移到AndroidX.
I believe that in order to resolve this, it is required to migrate to AndroidX.
我备份了我的项目并尝试使用 Android Studio 进行操作,但无济于事.我还尝试在我的 gradle.properties
文件
I backed up my project and attempted to do it with Android Studio to no avail. I also tried setting it manually in my gradle.properties
file
android.enableJetifier=true
android.useAndroidX=true
此后,我尝试从我的 app/build.gradle 中删除支持的库,并将目标 targetSdkVersion
设置为 28.
After this I tried removing supported libraries from my app/build.gradle, as well as setting targeted targetSdkVersion
to 28.
这些尝试给我带来了更多的错误,尤其是这个
These attempts resulted in more errors for me, specifically this one
任务 ':react-native-navigation:compileReactNative57_5DebugJavaWithJavac' 执行失败.
我正在使用 React Native 0.58.6 和 Wix Navigation V2.非常感谢您的帮助
I am using React Native 0.58.6 with Wix Navigation V2. Help would be much appreciated
推荐答案
昨天遇到了同样的问题,终于解决了,上面的错误原因是你的android项目迁移到androidx后,你的很多react-本机库提供本机 Java 代码并且尚未更新,我可以通过使用此库 jetifier 来解决它通过运行
I ran into the same problem yesterday and finally figured it out, the reason of the above error is after migrating your android project to androidx, many of your react-native libraries ship native Java code and have not updated, I was able to solve it by using this library jetifier simply by running
npm i --save-dev jetifier
npx jetify
但就我而言,仍有一些库导致了一些问题,例如我们react-native-fast-image 作为一种解决方法,我在/中创建了一个 gradle.propertiesnode_modules/react-native-fast-image/android 并为此模块停用 AndroidX 和 Jetifier:
but in my case there were still some libraries causing some issues such us react-native-fast-image as a workaround, I created a gradle.properties inside /node_modules/react-native-fast-image/android and deactivated AndroidX and Jetifier for this module:
android.useAndroidX=false
android.enableJetifier=false
这篇关于React Native:迁移到 AndroidX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!