Error when building for Android


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 ran “tns run android” I would get an error saying I needed google-services.json. So I generated that from the Firebase console and that error was resolved.

Now 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.