首页 > 解决方案 > 无法在单个 dex 文件中容纳请求的类(# 方法:114237 > 65536)

问题描述

我正在尝试将此驱动程序导入我的简单应用程序(目前只是默认文本视图)在 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

和(如此),

    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中得到修复。然后在运行模拟器时没有构建或任何其他问题。

标签: androidapiandroid-studiobuild.gradle

解决方案


尝试在应用程序级别的 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
    }

推荐阅读