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

我正在尝试将this 驱动程序导入到我在android 3.5 版本中的简单应用程序(目前只是默认文本视图)。驱动程序库已安装并想运行模拟器,我遇到了几个 Gradle 问题并且能够修复它们,最后在这里结束。当我进入时,

类路径'com.android.support:multidex:1.0.3'

在 Gradle 中。

虽然构建成功,但当我运行应用程序时,我收到了如下所述的构建错误。

com.android.tools.r8.CompilationFailedException:编译未能完成
com.android.tools.r8.utils.AbortException:错误:null,无法将请求的类放入单个 dex 文件中(#方法:114237 > 65536)

此外,我不确定该放在哪里(如this

multiDexEnabled true

和(如this),

    packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/INDEX.LIST'
}

由于我的 build.gradle 如下,

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
        maven {
            url "http://dl.bintray.com/shimmerengineering/Shimmer"
        }

    }
dependencies {
    classpath 'com.android.tools.build:gradle:3.5.1'
    apply plugin: 'eclipse'
    classpath 'com.android.support:multidex:1.0.3'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "http://dl.bintray.com/shimmerengineering/Shimmer"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

关于如何解决此问题的任何建议?

~谢谢~


固定如下:

新建一个测试应用,找到build.gradle文件并包含

allprojects { repositories { jcenter() maven { url "dl.bintray.com/shimmerengineering/Shimmer" } } }

然后在thisthis 中修复了到达的问题。然后在运行模拟器时没有构建或任何其他问题。

【问题讨论】:

  • 您正在查看错误的build.gradle 文件。您引用的内容需要添加到模块的 build.gradle 文件中(例如,app/build.gradle)。
  • 哦!好吧,我现在创建了一个新的测试应用程序并找到了 build.Gradle 文件并包含了 'allprojects { repositories { jcenter() maven { url "dl.bintray.com/shimmerengineering/Shimmer" } } }'
  • 然后再次面临与 [link] (stackoverflow.com/questions/48958884/…) 和此 [link] stackoverflow.com/questions/48249633/… 相同的问题。我能够解决这些问题。模拟器使用文本视图!希望,我现在可以继续!谢谢支持!!!

标签: android api android-studio build.gradle


【解决方案1】:

尝试在应用级 gradle 中将最大臀部大小设置为 4 GB

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    dexOptions {
        javaMaxHeapSize "4g"//this line
    }

【讨论】:

  • 感谢您的指导,但这对我不起作用。我现在更改了 Gradle 文件,然后在修复了一些问题后它就可以工作了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-09
  • 2023-03-27
  • 1970-01-01
  • 2020-02-03
  • 2018-06-23
相关资源
最近更新 更多