问题
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
I believe that in order to resolve this, it is required to migrate to AndroidX.
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
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'.
I am using React Native 0.58.6 with Wix Navigation V2. Help would be much appreciated
回答1:
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
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
回答2:
The answer that Ahmed posted is a great solution once you've migrated to AndroidX. In my case I didn't want to quite yet and found out that only one library in my application was using AndroidX from this thread
In short my solution was to simply yarn upgrade react-native-device-info@latest
The app build as expected after rebuilding it
来源:https://stackoverflow.com/questions/56717351/react-native-migrate-to-androidx