0

I have an App written with react-native and it's worked wonderfully previously but when I install RN async-storage. I don't change anything in the native Android code

I got an error when running the app.

I'm trying to remove it and rebuild my app BUT the issue is still I don't know why!

I'd tried to run these command

rm -rf node_modules 
npm install

then

cd android && gradlew clean

and it's building successfully without any error

but after running react-native run-android

I got

What went wrong: Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'. com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

So how can I solve it?

Oliver D
  • 2,579
  • 6
  • 37
  • 80
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Dec 01 '19 at 15:50

3 Answers3

4

So here is the solution.

First, let us solve the multiDex issue.In your myapp/android/app/build.gradle file, look for the block of code inside android and defaultConfig and then add the line multiDexEnabled true as shown below:

android {
    ...

    compileOptions {
        ...
    }

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true //ADD THIS LINE 'multiDexEnabled true' Inside the defaultConfig code block
    }

}

Second, an effective way to clear npm is by first deleting node_modules folder and then running the command npm i and then npm start --reset-cache

Third, an effective way to make a gradlew clean is by running this command cd android and then gradlew clean .

After running these steps, you should be good to go. All the best.

0

The right way to uninstall a npm package is

npm uninstall <name> --save

If you simply remove node_modules it wont be removed from package.json file, when u do npm install again the package will be installed if is not removed from package.json files moe detail here In the last line in the error log its mentioned as

The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this issue at to fix this error u might need to enable multidex as mentioned here

Jose Kj
  • 2,912
  • 2
  • 28
  • 40
  • after build the app crashed with bug could not find class android.support.multidex.MultiDexApplication – Oliver D Nov 29 '19 at 12:23
  • @OliverD go through https://stackoverflow.com/questions/47031968/getting-error-building-app-apptransformdexarchivewithdexmergerfordebug – Jose Kj Nov 29 '19 at 12:42
0

It might be the minSdkVersion issue. Try minSdkVersion = 21 at dir. android/build.gradle.

Follow this answer-

https://stackoverflow.com/a/61341015/10638877

Ali Hasan
  • 3,843
  • 1
  • 5
  • 9