无法合并multidex执行失败

问题描述 投票:0回答:1

我有错误无法在我的项目中合并dex。我从StackOverFlow应用了不同的答案,如:

 defaultConfig {
    multiDexEnabled true
}
dependencies {
    compile 'com.android.support:multidex:1.0.1'}
<application
    android:name="android.support.multidex.MultiDexApplication"

并在清单中应用。清理项目Rebuild / MakeProject并应用用户在答案中提供的所有其他选项,但收到该错误。当我启用multidex然后我得到将字节转换为dex的错误列表。我不知道我错过了什么。这是我的App Gradle

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.example.hp_pc.cerv"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    dexOptions {
        preDexLibraries = false
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
//    compile files('libs/httpclient-4.2.3.jar')
//    compile files('libs/httpmime-4.3.jar')
//    compile files('libs/httpcore.jar')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.mcxiaoke.volley:library:1.0.+'
    compile 'com.github.pinball83:masked-edittext:1.0.3'
   // compile 'com.google.android.gms:play-services-maps:9.8.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.wdullaer:materialdatetimepicker:2.5.0'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'joda-time:joda-time:2.9.4'
    testCompile 'junit:junit:4.12'
}

这是我的Project Gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
java android android-gradle build.gradle
1个回答
0
投票

如果您使用的是Google服务,则您的Project gradle应如下所示:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

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

对于处理Multidexing和使用Google服务,您的App gradle应如下所示 -

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.example.hp_pc.cerv"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    dexOptions {
        preDexLibraries = false
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
//    compile files('libs/httpclient-4.2.3.jar')
//    compile files('libs/httpmime-4.3.jar')
//    compile files('libs/httpcore.jar')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.mcxiaoke.volley:library:1.0.+'
    compile 'com.github.pinball83:masked-edittext:1.0.3'
   // compile 'com.google.android.gms:play-services-maps:9.8.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.wdullaer:materialdatetimepicker:2.5.0'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'joda-time:joda-time:2.9.4'
    testCompile 'junit:junit:4.12'
}

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

并在AndroidManifest文件中添加这两行代码 -

<application
    android:hardwareAccelerated="true"
    android:largeHeap="true"

希望它能解决你的问题。

© www.soinside.com 2019 - 2024. All rights reserved.