React Native:迁移到AndroidX [英] React Native: Migrate to AndroidX

查看:474
本文介绍了React Native:迁移到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

Execution failed for task ':react-native-navigation:compileReactNative57_5DebugJavaWithJavac'.

我在Wix Navigation V2中使用React Native 0.58.6. 帮助将不胜感激

I am using React Native 0.58.6 with Wix Navigation V2. Help would be much appreciated

推荐答案

昨天我遇到了同样的问题,并最终弄清楚了,上述错误的原因是在将您的android项目迁移到androidx之后,您的许多反应-本机库附带本机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.properties node_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屋!

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