7

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

jschuss
  • 645
  • 1
  • 8
  • 21

2 Answers2

17

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
Ahmed Imam
  • 1,315
  • 2
  • 19
  • 42
  • Thanks for you answer Ahmed! I'm sure it will be appreciated. I found a "pre migrate to AndroidX" solution which I also added for those who have not migrated – jschuss Jun 23 '19 at 17:18
1

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

jschuss
  • 645
  • 1
  • 8
  • 21