代码之家  ›  专栏  ›  技术社区  ›  Antwan

添加multiDexEnabled后的NoClassDef

  •  0
  • Antwan  · 技术社区  · 9 年前

    嘿,在添加了大量文件后,我有一个大型android项目

     UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define
    

    所以我搜索了我的问题,我找到了一个解决方案,就是将这个属性添加到Gradle文件中,但是在我成功添加了项目构建之后

    但是当我运行这个项目时,我的一些片段和活动出现了NoClassDef错误

    这是我的成绩

        apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 22
        buildToolsVersion "22.0.1"
        defaultConfig {
            applicationId "cloudappers.com.rta_ca"
            minSdkVersion 17
            targetSdkVersion 22
            versionCode 1
            versionName "1.0"
    
            multiDexEnabled = true
    
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        dexOptions {
            preDexLibraries = false
        }
    }
    allprojects {
        repositories {
            mavenCentral()
            jcenter()
            maven { url 'https://github.com/leonardocardoso/mvn-repo/raw/master/maven-deploy' }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile project(':bounceScroller')
        compile project(':SwipeMenu')
        compile project(':indicator')
        compile files('libs/android-async-http.jar')
        compile('com.weiwangcn.betterspinner:library:1.1.0') {
            exclude group: 'com.android.support', module: 'appcompat-v7'
        }
        compile files('libs/org.apache.commons.io.jar')
        compile 'com.android.support:appcompat-v7:22.0.0'
        compile 'com.nineoldandroids:library:2.4.0'
        compile 'com.daimajia.easing:library:1.0.1@aar'
        compile 'com.daimajia.androidanimations:library:1.1.3@aar'
        compile 'com.edmodo:cropper:1.0.1'
        compile 'com.github.bumptech.glide:glide:3.6.1'
        compile 'com.leocardz:aelv:1.1@aar'
        compile 'com.google.android.gms:play-services:7.8.0'
        compile 'com.google.android.gms:play-services-ads:7.8.0'
        compile 'com.google.android.gms:play-services-identity:7.8.0'
        compile 'com.google.android.gms:play-services-gcm:7.8.0'
        compile 'com.android.support:multidex:1.0.0'
    
    
    }
    

    它在android 5上运行,但在4.4及之前版本上不运行

    有什么帮助吗?

    1 回复  |  直到 9 年前
        1
  •  1
  •   AndiGeeky    9 年前

    从你的成绩这里:

    1. compile fileTree(dir: 'libs', include: ['*.jar'])
    2. compile files('libs/android-async-http.jar')   
    3. compile files('libs/org.apache.commons.io.jar')
    

    现在,如果您使用第1行,则无需添加第2&3.

    原因是 'compile fileTree(dir: 'libs', include: ['*.jar'])' 包括libs文件夹中的所有jar文件。。

    因此,删除第2行&3.

    谢谢