【发布时间】:2018-10-14 09:43:43
【问题描述】:
如何解决我在 Android Studio 中遇到的这个错误:
错误:单个 dex 文件中无法容纳请求的类(# 方法:67593 > 65536)
现在无法构建我的项目
【问题讨论】:
如何解决我在 Android Studio 中遇到的这个错误:
错误:单个 dex 文件中无法容纳请求的类(# 方法:67593 > 65536)
现在无法构建我的项目
【问题讨论】:
执行此4步骤
1:将此库添加到应用程序 build.gradle 的依赖项中:
implementation 'com.android.support:multidex:1.0.3'
2:在app build.gradle的defaultConfig中添加:
defaultConfig {
//other configs
multiDexEnabled true //add this line
}
3:像这样创建新的 Java 类:
public class ApplicationClass extends MultiDexApplication {
@Override
public void onCreate() {
super.onCreate();
}
}
4:将此添加到您的清单中(在应用程序标记中):
<application
android:name=".ApplicationClass"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
【讨论】:
在您做出任何决定之前,如 Google 文档中所述:
在配置您的应用以启用 64K 或更多方法之前 参考,您应该采取措施减少总数量 您的应用代码调用的引用,包括您定义的方法 应用代码或包含的库。
所以尝试在你的应用程序 gradle 中删除无用的导入并做一个干净的项目或做 multidex
【讨论】:
在我的 Visual Studio 2019 Xamarin 项目中也发生了同样的情况,解决这个问题的方法就像链接中提到的那样: Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: 72477 > 65536
multiDexEnabled true
通过勾选***.Droid项目选项页面中的Enable multiDex复选框即可解决问题。
【讨论】: