I have App written with react-native and it's work very fine previously but when I install RN async-storage . I don't change anything in native android code
I got an error when running the app.
I'm trying to remove it and rebuild my app BUT the issue still I don't know why!
I'm 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 run 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?
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.
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
It might be the minSdkVersion issue. Try minSdkVersion = 21 at dir. android/build.gradle.
Follow this answer-
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.