我正在开发一个启用Multidex的应用程序,以避免65k的限制。我想在Jar类型中添加一个外部库(即iPay Jar SDK)。我已经同步了Gradle并成功,但是我无法运行该项目。

错误消息如下所示

Error:Execution failed for task ':app:shrinkDebugMultiDexComponents'.



这是我的Gradle代码
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.2'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

repositories {
    mavenCentral()
    mavenLocal()
}

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName '[My Package]'
    }
}

dependencies {
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"

    compile fileTree(dir: 'libs', include: ['*.jar'])
    //Libs folder contains: org.apache.http.legacy.jar
    //and ipay88_androidv7.jar

    compile 'com.loopj.android:android-async-http:1.4.5'
    compile 'com.github.rey5137:material:1.2.1'
    compile 'com.jpardogo.materialtabstrip:library:1.0.9'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'

    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.facebook.android:facebook-android-sdk:4.7.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "[My Application Id]"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java', 'build/source/apt/debug']
            resources.srcDirs = ['src/main/res']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
        }

        beta {
            resources.srcDirs = ['app/src/beta/res']
            res.srcDirs = ['app/src/beta/res']
        }
    }
    signingConfigs {
        release {
            ...
        }
    }
}

在添加此类外部库(即iPay Jar SDK)之前,该应用已成功运行。但是问题是在我添加了iPay Jar SDK(第二个Jar库)之后出现的。

有关更多信息,我已经在https://developer.android.com/tools/building/multidex.html上遵循了本指南
但这对我的项目没有用。

您对解决此错误有何建议?

最佳答案

试试这个:

public class MyApplication extends MultiDexApplication
{
    @Override
    protected void attachBaseContext(Context base)
    {
        super.attachBaseContext( base );
    }

    @Override
    public void onCreate()
    {
        MultiDex.install(getTargetContext());
        super.onCreate();
    }

}

10-07 19:17
查看更多