Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program type already present: androidx.versionedparcelable.NonParcelField

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

like image 332
Prince Hamza Avatar asked Jun 18 '19 12:06

Prince Hamza


2 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
like image 159
Ahmed Imam Avatar answered Nov 08 '22 01:11

Ahmed Imam


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

like image 41
Basil Satti Avatar answered Nov 08 '22 02:11

Basil Satti