【问题标题】:Error: Cannot fit requested classes in a single dex file (# methods: 67593 > 65536)错误:无法在单个 dex 文件中容纳请求的类(# 方法:67593 > 65536)
【发布时间】:2018-10-14 09:43:43
【问题描述】:

如何解决我在 Android Studio 中遇到的这个错误:

错误:单个 dex 文件中无法容纳请求的类(# 方法:67593 > 65536)

现在无法构建我的项目

【问题讨论】:

标签: android android-studio


【解决方案1】:

执行此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">

【讨论】:

    【解决方案2】:

    在您做出任何决定之前,如 Google 文档中所述:

    在配置您的应用以启用 64K 或更多方法之前 参考,您应该采取措施减少总数量 您的应用代码调用的引用,包括您定义的方法 应用代码或包含的库。

    所以尝试在你的应用程序 gradle 中删除无用的导入并做一个干净的项目或做 multidex

    来源:https://developer.android.com/studio/build/multidex

    【讨论】:

      【解决方案3】:

      在我的 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复选框即可解决问题。

      【讨论】:

        猜你喜欢
        • 2020-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-23
        • 2023-03-27
        • 1970-01-01
        相关资源
        最近更新 更多