Program type already present: androidx.versionedparcelable.NonParcelField

Viewed 5206

i am working on a react native android project but i am stuck on this error

> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED

D8: Program type already present: androidx.versionedparcelable.NonParcelField    

FAILURE: Build failed with an exception.

i have tried to change multi dex to false in build.gradle

  defaultconfig {...
    multiDexEnabled false 
     ...}

i dont want to migrate to androidx , i just want to get rid of androidx & this error ; please help me , thanks in advance

4 Answers

Based on my research couldn't not find an easy way or should I say a correct way to draw back from androidx, to solve the above issue just add the following to your gradle.properties

android.useAndroidX=true
android.enableJetifier=true

That might cause another issue like

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

the reason of this error, if it occured, after migrating your android project to androidx, many of your react-native libraries ship native Java code and have not been updated, updating it manually is tedious, I was able to do so by using this library jetifier simply by running

npm i --save-dev jetifier
npx jetify 

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

The answer that Ahmed posted is a great solution once you've migrated to AndroidX. In my case I 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

Please follow the following steps:

  1. Open Android Studio
  2. Click on Refactor on the top menu bar
  3. Click on Migrate too AppCompat

I hope this shall help you

I ran into a similar problem: I'm updating an app for RN 0.60.0. In my case, I had a dependency in build.gradle with a '+' in its version, and that particular dependency got updated, which broke my build.

In my case, explicitly specifying the version number resolved my problem.

./gradlew app:dependencies will show a tree of your dependencies; this might point you in the right direction as well.

Related