Nativescript 无法在单个 dex 文件中满足请求 类

Nativescript Cannot fit requested classes in a single dex file

我已经为这个问题困扰了很长一段时间,我 运行 没有什么可以尝试的了。我想我已经尝试过所有类似的解决方案来解决这个问题,但都无济于事。我想看看是否可以得到更多建议来解决我的问题。

我正在构建一个包含 Firebase 的 NS8/Angular 11 项目。我按照 https://github.com/EddyVerbruggen/nativescript-plugin-firebase 中的步骤设置了云消息、远程配置和应用内消息,目前正在 Android。

使用 tns build/run android 构建并 运行ning 成功后,我在 Android Studio 中打开我的项目进行重建和签名。重建后,出现以下错误。

这是我目前的 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"
  }
}

清理我的项目并重建几次后,我在 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)

我尝试了其他解决方案,例如将 minSDK 更新为 21。但我仍然遇到与

相同的错误
// Removed "dependencies"

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

同样的错误。

我真的不确定还有什么地方可以检查或者还有什么可以改变的。似乎显式启用 multiDex 和更新我的 minSDK 都不起作用。

这是我的 package.json 和 AndroidManifest 是否有用

"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>

对我有用的实际上是通过 Android Studio,通过命令行构建应用程序包,然后上传该包方向。

minSDKVersion 设置为 21,不需要 multiDexEnabledimplementation...