无法在单个dex文件中容纳所请求的类。尝试提供main-dex列表

时间:2018-03-27 19:13:01

标签: android-studio dex

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

之前没有问题。

错误详情:

方法:66320> 65536

消息{kind = ERROR,text =无法在单个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'

6 个答案:

答案 0 :(得分:4)

尝试添加

defaultConfig {

    multiDexEnabled true 
    ...
}

在gradle中。它解决了我的问题。

答案 1 :(得分:1)

app 级别添加build.gradle文件:

defaultConfig {
    multiDexEnabled true 
...
}

答案 2 :(得分:0)

问题已解决。

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

已添加

 aaptOptions{
        cruncherEnabled = false
    }
gradle解决了这个问题。

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

答案 3 :(得分:0)

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

答案 4 :(得分:0)

build.gradle文件中添加依赖项:

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

build.gradle的{​​{1}}部分中,添加:

defaultConfig

答案 5 :(得分:0)

将实现import { UserService } from './user.service'; import { TestBed } from '@angular/core/testing'; import { environment } from 'src/environments/environment.prod'; import { AngularFireModule } from '@angular/fire'; describe('UserService unit tests', () => { let userService: UserService; beforeEach(() => { TestBed.configureTestingModule({ imports: [AngularFireModule.initializeApp(environment)], providers: [ { provide: UserService } ] }); userService = TestBed.get(UserService); }); it('should be created', () => { userService.hello(); }); }); 添加到Gradle构建中,然后在com.android.support:multidex:1.0.3中添加multiDexEnabled true