Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NativeScript Execution failed for task: Error while merging dex archives

While building NS + Vue application, following error occurred -

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives

Error is because the number of method references in a .dex file cannot exceed 64K. Error also directs to the solution at https://developer.android.com/tools/building/multidex.html

This solution suggests to enable multidex for apps with over 64K methods i.e. to add multiDexEnabled true in build.gradle which resolves the error.

In NativeScript build.gradle is located in platforms/, so whenever I clean the platform with tns platform clean or remove platforms/, I have to again add multiDexEnabled true in build.gradle.

Is there any permanent solution to this?

like image 975
Amit Gurbani Avatar asked Mar 05 '23 08:03

Amit Gurbani


1 Answers

Instead of build.gradle in platforms/, use app.gradle in App_Resources/Android.

Add multiDexEnabled true inside android.defaultConfig in app.gradle file, this will persist and will not change with tns platform clean or removing platforms/

like image 152
Amit Gurbani Avatar answered Mar 08 '23 05:03

Amit Gurbani