失效恢复导致 D8: 在 Android Studio 中无法将请求的类放入单个 dex 文件(# method: 71610 > 65536)中

我试图在最新版本的 Android Studio 中使用带有 Flutter 应用程序的 firestore。我一直严格遵守这些指示。上周我甚至用一个不同的应用程序让他们开始工作。现在,在完成更新 pubspec.yaml 之前(包括)的所有步骤之后,尝试运行新应用程序时,会出现以下错误。请记住,在这个例子中,我得到了一个新的颤振计数器应用程序的错误,没有其他代码更改,但你在这里看到什么。

D8: Cannot fit requested classes in a single dex file (# methods: 71610 > 65536)


FAILURE: Build failed with an exception.


* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\2.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\3.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\4.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\5.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\6.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\7.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\8.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\9.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\10.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\11.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\12.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\13.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\14.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\15.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\16.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\17.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\18.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\19.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\20.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\21.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\22.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\23.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\24.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\25.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\26.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\27.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\28.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\29.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\30.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\31.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_p
rojects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\32.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\33.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\34.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\35.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\36.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\37.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\38.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\39.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\40.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\41.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\42.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\43.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\44.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\45.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\46.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\47.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\48.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\49.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\50.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\51.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\52.jar, C:\Users\DonBo\AndroidStudioProjects\don_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\53.jar
The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.


* Get more help at https://help.gradle.org


BUILD FAILED in 21s
Finished with error: Gradle task assembleDebug failed with exit code 1

这是我的 pubspec 文件

name: bakery
description: A new Flutter application.


# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1


environment:
sdk: ">=2.1.0 <3.0.0"


dependencies:


cloud_firestore:


flutter:
sdk: flutter


# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2


dev_dependencies:
flutter_test:
sdk: flutter




# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec


# The following section is specific to Flutter.
flutter:


# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true


# To add assets to your application, add an assets section, like this:
# assets:
#  - images/a_dot_burr.jpeg
#  - images/a_dot_ham.jpeg


# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.


# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages


# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
#   - family: Schyler
#     fonts:
#       - asset: fonts/Schyler-Regular.ttf
#       - asset: fonts/Schyler-Italic.ttf
#         style: italic
#   - family: Trajan Pro
#     fonts:
#       - asset: fonts/TrajanPro.ttf
#       - asset: fonts/TrajanPro_Bold.ttf
#         weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.io/custom-fonts/#from-packages

这是我的应用程序级别的分级文件

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}


def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}


def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}


def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}


apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"


android {
compileSdkVersion 28


lintOptions {
disable 'InvalidPackage'
}


defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.boody.sag.bakery"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}


buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}


flutter {
source '../..'
}


dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}


apply plugin: 'com.google.gms.google-services'

这是我的机器人级别的档案

buildscript {
repositories {
google()
jcenter()
}


dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:3.2.0'
}
}


allprojects {
repositories {
google()
jcenter()
}
}


rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}


task clean(type: Delete) {
delete rootProject.buildDir
}
69319 次浏览

把这个加到 android/app/build.gradle:

defaultConfig {
...
multiDexEnabled true
}

启用 multidex。

打开 project/app/build.gradle并添加以下代码行。

defaultConfig {
...


multiDexEnabled true
}

还有

dependencies {
...


implementation 'com.android.support:multidex:1.0.3'
}

如果你已经迁移到了 AndroidX,你会想要这个(来自 图雷 · 霍尔德的提示) :

dependencies {
...


implementation 'androidx.multidex:multidex:2.0.1'
}

阅读更多关于 给你的内容

默认情况下,Flutter 支持 Android SDK v16(Jelly Bean,发布于2012年) ,但是 multidex 并不支持 Jelly Bean 开箱即用。有两种方法可以解决这个问题:

A)更改最低目标 SDK

  1. 打开 android/app/build.gradle,然后找到写着 minSdkVersion 16的行。
  2. 把那条线改成 minSdkVersion 21
  3. 保存文件。

B)启用 multidex。

如果你想支持旧的 Android 版本,你可以使用 multidex 支持库。

  1. 打开和修改 project/app/build.gradle文件以启用 multidex 并添加 multidex 库作为依赖项,如下所示:
android {
defaultConfig {
...
multiDexEnabled true
}
...
}


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

这里是官方指南

我也有同样的错误,所以我所做的就是将应用程序级的 Gradle 文件的 minSdkVersion 从16增加到21。现在好了。

只需增加这个 minSdkVersion,targetSdkVersion:

老年人:

defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

最新消息:

defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

还有这个已编译的 SdkVersion:

老年人:

android {
compileSdkVersion 28

最新消息:

android {
compileSdkVersion 29

在文件夹里

Android/app/build.gradle

将 minSdkVersion 更改为21

android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
}
...
}

参考: Https://developer.android.com/studio/build/multidex

另一种解决方案是将 debug min sdk 21改为 debug 模式,将16改为 release。构建时间不会增加,一切都将正常工作。

// open android/app/build.gradle


buildTypes {
...
// add this line
debug { defaultConfig.minSdkVersion 21 }
}

builld.gradle defaultConfig中设置 multiDexEnabled true

enter image description here

还要加上 implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.android.support:multidex:1.0.3'呼叫 dependencies

enter image description here

我有这个问题,在我的情况下,是与 Firebase,火灾恢复等,我不再使用依赖关系。我只是删除它和运行 OK。

一个建议是打开一个新的项目,以采取其梯度的副本,作出一个孤立的年级在您的项目的 / /和替换为一个新的,并作出调整,如果必要的。