解决项目无报错运行时assembleDebug报错(64K错误)
原创:@As.Kai
博客地址:https://blog.csdn.net/qq_42362997
如果以下内容对您有帮助,点赞点赞点赞~
报错信息:
* 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
我们主要看这一句
The number of method references in a .dex file cannot exceed 64K.
这个报错信息大概讲的是:
一个.dev文件中方法引用的数量不能超过64k
我们的项目中应该是引用了较多的依赖包超过了官方规定的 64K大小
使得方法引用过多导致报错
在网上查找相关问题时发现:
The problem is with multidex builder. Actually, this often happens when you have imported a lot of packages in your yaml file which cannot fit into a single .dex built hence you have to enable multidex.
他的意思大概是说由于在pubspec.yaml文件中导入了过多无法放入单个.dex文件依赖包,所以你必须启用multidex进行分包
解决方案:
Go to android/app/build.gradle and add the following lines of codes:
意思是转到android / app / build.gradle并添加以下代码行:
dependencies {
implementation 'com.android.support:multidex:1.0.3' //enter the latest version
}
android {
defaultConfig {
multiDexEnabled true
}
}
最后重新运行程序,问题完美解决!
别忘了点赞~
关注我,一起成长!
@As.Kai