【问题标题】:Cannot fit requested classes in a single dex file. Try supplying a main-dex list无法在单个 dex 文件中容纳请求的类。尝试提供一个 main-dex 列表
【发布时间】:2018-09-06 07:50:33
【问题描述】:

根据标题,将 AndroidStudio 从 3.0.1 升级到 3.1 后遇到限制,

以前没有问题。

错误详情:

方法:66320 > 65536

Message{kind=ERROR, text=Cannot fit请求的类在单个dex文件中。尝试提供一个 main-dex 列表。

方法:66320 > 65536,sources=[未知源文件],工具名=Optional.of(D8)}

apply plugin: 'com.android.application'
android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        multiDexEnabled false
        applicationId "com.example.xxx"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            //minifyEnabled true
            useProguard true
            //shrinkResources true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            //minifyEnabled true
            useProguard true
            //shrinkResources true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
    }
    // Necessary to force the use of a specific version (on all the builds)
    configurations.all {
        resolutionStrategy.force 'com.github.bumptech.glide:glide:3.7.0'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    //Android
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:27.0.2'
    implementation 'com.android.support:cardview-v7:27.0.2'
    implementation 'com.android.support:recyclerview-v7:24.0.0'
    implementation 'com.android.support:percent:27.0.2'
    implementation 'com.google.android.gms:play-services-location:11.8.0'
    implementation 'com.google.android.gms:play-services-maps:11.8.0'
    //compile 'com.google.android.gms:play-services-auth:11.8.0'
    // Firebase
    implementation 'com.google.firebase:firebase-core:11.8.0'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation 'com.google.firebase:firebase-firestore:11.8.0'
    implementation 'com.google.firebase:firebase-database:11.8.0'
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.google.firebase:firebase-messaging:11.8.0'
    implementation 'com.google.firebase:firebase-appindexing:11.8.0'
    implementation 'com.google.firebase:firebase-crash:11.8.0'
    implementation 'com.google.firebase:firebase-analytics:11.8.0'
    implementation 'com.google.firebase:firebase-config:11.8.0'
    implementation 'com.firebaseui:firebase-ui-auth:3.1.3'
    implementation 'com.firebaseui:firebase-ui-database:0.4.1'
    implementation 'com.firebaseui:firebase-ui-firestore:3.1.3'
    implementation 'com.firebaseui:firebase-ui-storage:3.1.3'


    implementation 'pub.devrel:easypermissions:1.1.2'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.2'
    implementation group: 'com.github.bumptech.glide', name: 'glide', version: '3.7.0' 


    implementation 'com.firebase:geofire-android:2.2.0'
    implementation 'hani.momanii.supernova_emoji_library:supernova-emoji-library:0.0.2'
    implementation 'me.himanshusoni.chatmessageview:chat-message-view:1.0.3'
    implementation 'com.microsoft.projectoxford:face:1.3.0'
    implementation 'com.google.ar:core:1.0.0'


    implementation 'de.javagl:obj:0.2.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'



    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support:support-annotations:27.0.2'

}

apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 为什么要投反对票?至少说一下原因还是很快也会在这里充满仇恨?我们来这里是为了讨论和交流想法、知识和经验,如果有人没有冒犯或开一些不好的笑话,我认为没有必要对他投反对票,也没有让他有机会成为社区的一员,在这里和从那里学到的东西其他来源。

标签: android-studio dex


【解决方案1】:

尝试添加

defaultConfig {

    multiDexEnabled true 
    ...
}

在毕业典礼上。它解决了我的问题。

文档:https://developer.android.com/studio/build/multidex

【讨论】:

    【解决方案2】:

    在 Gradle 构建中添加实现 com.android.support:multidex:1.0.3,然后在 defaultConfig 中添加 multiDexEnabled true

    【讨论】:

      【解决方案3】:

      app 级别添加build.gradle 文件:

      defaultConfig {
          multiDexEnabled true 
      ...
      }
      

      【讨论】:

        【解决方案4】:

        build.gradle文件中添加依赖:

        implementation 'com.android.support:multidex:1.0.3'
        

        build.gradledefaultConfig 部分,添加:

        multiDexEnabled true
        

        【讨论】:

        • 嘿,欢迎来到 SO :) 我已经编辑了你的答案,所以它更容易阅读。不要犹豫,使用markdown 来格式化内容。
        • 添加 documentation 会改善这个答案。不是每个人都知道 multiDexEnable 是什么意思
        【解决方案5】:

        delete -rf 你使用了 gradle 版本的文件路径(.gradle/warpper/dists/gradle-**.-all)。 它解决了我的问题

        【讨论】:

          【解决方案6】:

          问题已解决。

          错误出现在某些 png aapt 试图压缩并发现不正确。

          添加

           aaptOptions{
                  cruncherEnabled = false
              }
          

          在 gradle 中解决了这个问题。

          希望这可以帮助将来的人。

          【讨论】:

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