[英]D8: Cannot fit requested classes in a single dex file
I am trying to add the below dependencies:我正在尝试添加以下依赖项:
firebase_auth: ^0.14.0+5
google_sign_in: ^4.0.7
cloud_firestore: ^0.12.9+5
fluttertoast: ^3.1.3
image_picker: ^0.6.1+8
shared_preferences: ^0.5.3+4
firebase_storage: ^3.0.6
cached_network_image: 2.0.0-rc.1
firebase_messaging: 6.0.13
flutter_local_notifications: 1.4.0
photo_view: ^0.5.0
I found this error:我发现了这个错误:
D8: Cannot fit requested classes in a single dex file (# methods: 85948 > 65536)
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
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
at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:131)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:118)
at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:102)
at com.android.build.gradle.internal.tasks.DexMergingTaskRunnable.run(DexMergingTask.kt:444)
at com.android.build.gradle.internal.tasks.Workers$ActionFacade.run(Workers.kt:335)
at org.gradle.workers.internal.AdapterWorkAction.execute(AdapterWorkAction.java:50)
at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:47)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1$1.create(NoIsolationWorkerFactory.java:65)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1$1.create(NoIsolationWorkerFactory.java:61)
at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:98)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.execute(NoIsolationWorkerFactory.java:61)
at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:56)
at org.gradle.workers.internal.DefaultWorkerExecutor$3.call(DefaultWorkerExecutor.java:215)
at org.gradle.workers.internal.DefaultWorkerExecutor$3.call(DefaultWorkerExecutor.java:210)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
at com.android.tools.r8.utils.t.a(:55)
at com.android.tools.r8.D8.run(:11)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:116)
... 34 more
Caused by: com.android.tools.r8.utils.AbortException: Error: null, Cannot fit requested classes in a single dex file (# methods: 85948 > 65536)
at com.android.tools.r8.utils.Reporter.a(:21)
at com.android.tools.r8.utils.Reporter.a(:7)
at com.android.tools.r8.dex.VirtualFile.a(:33)
at com.android.tools.r8.dex.VirtualFile$h.a(:5)
at com.android.tools.r8.dex.ApplicationWriter.a(:13)
at com.android.tools.r8.dex.ApplicationWriter.write(:35)
at com.android.tools.r8.D8.d(:44)
at com.android.tools.r8.D8.b(:1)
at com.android.tools.r8.utils.t.a(:23)
... 36 more
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
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 51s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 53.6s
[!] The shrinker may have failed to optimize the Java bytecode.
To disable the shrinker, pass the `--no-shrink` flag to this command.
To learn more, see: https://developer.android.com/studio/build/shrink-code
Exception: Gradle task assembleDebug failed with exit code 1
and this is my full pubspec.yaml
这是我的完整
pubspec.yaml
name: aradi_online_vtwo
description: A new Flutter project.
https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
provider: ^3.0.0
intl: ^0.15.8
flutter_speed_dial: ^1.2.1
font_awesome_flutter: ^8.5.0
smooth_star_rating: ^1.0.3
firebase_auth: ^0.14.0+5
google_sign_in: ^4.0.7
cloud_firestore: ^0.12.9+5
fluttertoast: ^3.1.3
image_picker: ^0.6.1+8
shared_preferences: ^0.5.3+4
firebase_storage: ^3.0.6
cached_network_image: 2.0.0-rc.1
firebase_messaging: 6.0.13
flutter_local_notifications: 1.4.0
photo_view: ^0.5.0
# 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:
- assets/images/
- assets/design_course/
- assets/fitness_app/
- assets/hotel/
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/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: WorkSans
fonts:
- asset: assets/fonts/WorkSans-Regular.ttf
- asset: assets/fonts/WorkSans-Medium.ttf
weight: 500
- asset: assets/fonts/WorkSans-SemiBold.ttf
weight: 600
- asset: assets/fonts/WorkSans-Bold.ttf
weight: 700
- family: Roboto
fonts:
- asset: assets/fonts/Roboto-Bold.ttf
- asset: assets/fonts/Roboto-Regular.ttf
- asset: assets/fonts/Roboto-Medium.ttf
weight: 400
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
So how can I solve this problem?那么我该如何解决这个问题呢?
Add multiDex to your app-level build.gradle file.将 multiDex 添加到您的应用级 build.gradle 文件中。 Under defaultConfig add this line
在 defaultConfig 下添加这一行
multiDexEnabled true
Then in dependencies add multidex and check versions然后在依赖项中添加multidex并检查版本
implementation 'androidx.multidex:multidex: 2.0.1'
So basically this error happens when your app and the libraries it references exceed 65,536 methods,the build error just means your app has reached the limit of the Android build architecture, so to fix this go to android/app/build.gradle
directory and add the multiDexEnabled true
and implementation 'com.android.support:multidex:2.0.1'
in thus manner所以基本上这个错误发生在你的应用程序和它引用的库超过 65,536 个方法时,构建错误只是意味着你的应用程序已经达到 Android 构建架构的限制,所以要修复这个 go 到
android/app/build.gradle
目录并添加multiDexEnabled true
并以这种方式implementation 'com.android.support:multidex:2.0.1'
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
........
multiDexEnabled true
}
dependencies {
...........
implementation 'com.android.support:multidex:2.0.1'
}
and of course restart your android-studio or the platform you're using.当然,重新启动您的 android-studio 或您正在使用的平台。
Upgrade min sdk to 21将最小 sdk 升级到 21
I had the same issue and Multi dex is not engouh to solve it I'm solve it with updgrading min sdk to 21我遇到了同样的问题,Multi dex 无法解决它我正在通过将 min sdk 升级到 21 来解决它
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 30
multiDexEnabled
}
dependencies {
...
implementation 'androidx.multidex:multidex:2.0.1'
}
If none of this works just add one more thing increment your minsdkversion in app gradle (build gradle ) if it is 20 then do 21 or increase by 1 -2.如果这些都不起作用,只需在应用程序 gradle (构建 gradle )中再增加一件事,如果它是 20,则执行 21 或增加 1 -2。 It works for me
这个对我有用
in my case the app not build after adding the above lines so I have在我的情况下,添加上述行后应用程序没有构建,所以我有
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
minifyEnabled true
shrinkResources true
}
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' line is missing so I add it proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 行丢失所以我添加它
I tried with 'multiDexEnabled' and implementation 'androidx.multidex:multidex: 2.0.1' that worked我尝试使用'multiDexEnabled'和实现'androidx.multidex:multidex:2.0.1'
If you use android plugin with version 7.4.0
, you need to add minifyEnabled true
to debug{}
block.如果您使用版本为
7.4.0
的 android 插件,则需要将minifyEnabled true
添加到debug{}
块。
id 'com.android.application' version '7.4.0'
buildTypes {
release { ... }
debug {
// 'com.android.application' version '7.4.0' 需要(奇葩)
minifyEnabled true
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.