I am working on an app using the latest version of NativeScript with Angular. I have added most of the pro-ui plugins to my project and added the Firbase plugin.
When I run “tns run android” I get the error:
“D8: Cannot fit requested classes in a single dex file. Try supplying a main-dex list.”
Also, it takes over 5 minutes to build. I have been doing some searching but I cannot find what is causing this problem. Does anyone know what is wrong?
After much trial and error I have finally come to a solution. All other answers I've read have said that the multiDexEnabled
property must be set to true
in the android project's build.gradle
file.
I wasn't sure how to do this for NativeScript though since the platforms folder is not committed to version control and can be potentially overwritten.
However, in your_project_root/app/App_resources/Android
there are two files, settings.gradle
and settings.json
.
settings.gradle
is used to generate your projects's build.gradle
file from the properties you set in settings.json
.
So, to the defaultConfig
string template in settings.gradle
I added:
if(__multiDexEnabled__) {
multiDexEnabled = __multiDexEnabled__
}
And to the JSON object defined in settings.json
I added:
"multiDexEnabled": true
After that I deleted my project's platforms folder and ran:
> tns platforms add android
> tns run android
And my app started up on my phone with no problems.
Go to the path platforms/app/build.gradle (careful NOT /platform/build.gradle) and add the line multiDexEnabled true
...
defaultConfig {
def manifest = new XmlSlurper().parse(file(android.sourceSets.main.manifest.srcFile))
def minSdkVer = manifest."uses-sdk"."@android:minSdkVersion".text() ?: 17
minSdkVersion minSdkVer
targetSdkVersion computeTargetSdkVersion()
ndk {
if (onlyX86) {
abiFilters 'x86'
} else {
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
}
multiDexEnabled true
dexOptions {
jumboMode = true
}
}
...
I have solved this by Just adding multiDexEnabled true into your app.gradle under android->defaultConfig
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With