Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: Migrate to AndroidX

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

like image 243
jschuss Avatar asked Jun 22 '19 16:06

jschuss


1 Answers

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
like image 136
Ahmed Imam Avatar answered Sep 20 '22 23:09

Ahmed Imam