【问题标题】:Cannot fit requested classes in a single dex file (# methods: 86010 > 65536)无法将请求的类放在单个 dex 文件中(# 方法:86010 > 65536)
【发布时间】:2020-05-16 21:49:24
【问题描述】:

我不知道错误是什么意思。我正在尝试从 youtube 上做一个使用 Firebase 的 uber 应用程序并收到此错误。

无法在单个 dex 文件中容纳请求的类(# 方法:86010 > 65536) com.android.tools.r8.CompilationFailedException:编译失败。

build.gradle(app)

    apply plugin: 'com.android.application'
    apply plugin: 'com.google.gms.google-services'
    android {
        compileSdkVersion 28
        buildToolsVersion "29.0.2"
        defaultConfig {
            applicationId "com.example.ezbusjava"
            minSdkVersion 16
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
                debuggable = true
                signingConfig signingConfigs.debug
            }
        }
    }
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'androidx.appcompat:appcompat:1.1.0'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
        implementation 'com.google.firebase:firebase-analytics:17.2.2'
        implementation 'com.google.firebase:firebase-auth:19.2.0'
        implementation 'com.google.firebase:firebase-firestore:21.3.1'
        implementation 'com.google.firebase:firebase-database:19.2.0'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'androidx.test.ext:junit:1.1.1'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    }

build.gradle(项目)

buildscript {
    repositories {
        mavenCentral()
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath 'com.google.gms:google-services:4.3.3'
    }
}

allprojects {
    repositories {
        mavenCentral()
        google()
        jcenter()

    }
}

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

【问题讨论】:

    标签: java android-studio


    【解决方案1】:

    Android 有 65,536 个方法限制。如果您的应用超过该数量,您需要启用multidexing

    只需将multiDexEnabled 标志和所需的依赖项添加到您的build.gradle

    android {
        defaultConfig {
            ...
            multiDexEnabled true
            ...
        }
        ...
    }
    
    dependencies {
        ...
        implementation 'com.android.support:multidex:1.0.3'
    }
    

    此外,您需要配置您的应用以使用多索引。

    根据文档,如果您的应用扩展 Application,则需要改为从 MultiDexApplication 扩展。

    如果您的应用没有扩展 Application,您需要将以下行添加到您的清单中:

    <application
            android:name="android.support.multidex.MultiDexApplication" >
            ...
    </application>
    

    【讨论】:

      【解决方案2】:

      尝试在应用中启用 Multidex。你可以在这里阅读更多关于它的信息https://developer.android.com/studio/build/multidex

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-17
        • 2020-01-09
        • 2019-08-30
        • 2023-03-27
        相关资源
        最近更新 更多