Search code examples
androidfirebaseandroid-studionativescriptnativescript-angular

Nativescript Cannot fit requested classes in a single dex file


I've been having trouble with this issue for quite a while and I have run out of things to try. I think I've tried every similar solution to this problem to no avail. I would like to see if I can get some more suggestions to move past my issue.

I'm building a NS8/Angular 11 project with Firebase included. I followed the steps found in https://github.com/EddyVerbruggen/nativescript-plugin-firebase to set up cloud messaging, remote config, and in app messaging, which so far is working on Android.

After building and running successfully using tns build/run android, I then open up my project in Android Studio to rebuild and sign. Upon rebuilding, the following errors occur.

Here is my current app.gradle (App_Resources/Android/src/main/app.gradle).

dependencies {
  implementation 'com.android.support:multidex:2.0.1'
}

android {
  defaultConfig {
    applicationId "com.XXXX.XXXX"
    minSdkVersion 17
    generatedDensities = []
    multiDexEnabled true
  }
  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}

Upon cleaning my project and rebuilding several times, I get this error in Android Studio

Execution failed for task ':app:mergeDexDebug'.
Error: null, Cannot fit requested classes in a single dex file (# methods: 120116 > 65536 ; # fields: 70750 > 65536)

Caused by: com.android.tools.r8.utils.b: Error: null, Cannot fit requested classes in a single dex file (# methods: 120116 > 65536 ; # fields: 70750 > 65536)

163 actionable tasks: 161 executed, 2 up-to-date
null, Cannot fit requested classes in a single dex file (# methods: 120116 > 65536 ; # fields: 70750 > 65536)

I've tried other solutions, such as to update the minSDK to 21. But I still got the same error with

// Removed "dependencies"

android {
  defaultConfig {
    applicationId "com.XXXX.XXXX"
    minSdkVersion 21
    generatedDensities = []
  }
  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}

The same error.

I'm really not sure where else to check or what else to change. It seems like enabled multiDex explicitly and updating my minSDK both don't work.

Here is my package.json and AndroidManifest if it's useful

"dependencies": {
    "@angular/animations": "~11.2.7",
    "@angular/cdk": "~11.2.7",
    "@angular/common": "~11.2.7",
    "@angular/compiler": "~11.2.7",
    "@angular/core": "~11.2.7",
    "@angular/forms": "~11.2.7",
    "@angular/platform-browser": "~11.2.7",
    "@angular/router": "~11.2.7",
    "@bradmartin/nativescript-urlhandler": "^2.0.1",
    "@mhtghn/nativescript-highcharts": "^1.0.2",
    "@nativescript-community/ble": "^3.0.25",
    "@nativescript-community/insomnia": "^2.0.2",
    "@nativescript-community/ui-drawer": "0.0.28",
    "@nativescript/angular": "~11.8.0",
    "@nativescript/core": "^8.0.8",
    "@nativescript/firebase": "^11.1.3",
    "@nativescript/theme": "~3.0.1",
    "@triniwiz/nativescript-toasty": "~4.1.3",
    "bluebird": "3.5.5",
    "crypto-es": "^1.2.7",
    "nativescript-iap": "^7.1.1",
    "nativescript-sentry": "^2.0.1",
    "npm-check-updates": "^11.8.3",
    "reflect-metadata": "^0.1.13",
    "rxjs": "~6.6.7",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~11.2.7",
    "@nativescript/android": "8.0.0",
    "@nativescript/ios": "8.0.0",
    "@nativescript/types": "~8.0.0",
    "@nativescript/webpack": "5.0.0-dev.5",
    "@ngtools/webpack": "^11.2.14",
    "webpack": "5.48.0",
    "sass": "~1.35.1",
    "ts-node": "~10.0.0",
    "typescript": "~4.0.0"
  },
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="__PACKAGE__"
    android:versionCode="XX"
    android:versionName="XXX">

    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"/>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

    <application
        android:name="com.tns.NativeScriptApplication"
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="XXXX"
        android:theme="@style/AppTheme"
        android:launchMode="singleTop">

        <meta-data android:name="io.sentry.dsn" android:value="https://14770d8bac924d4f96ceec0eac2be936@o420930.ingest.sentry.io/XXXXXX" />
        <meta-data android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/icon" />

        <activity
            android:name="com.tns.NativeScriptActivity"
            android:label="@string/title_activity_kimera"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"
            android:theme="@style/LaunchScreenTheme">

            <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" /> 
                <data android:scheme="rowforge" />
            </intent-filter>
        </activity>
        <activity android:name="com.tns.ErrorReportActivity"/>
    </application>
</manifest>

Solution

  • What worked for me was actually by passing Android Studio, building the app bundle via command line, and uploading that bundle direction.

    minSDKVersion was set to 21, without needing multiDexEnabled or implementation....