添加依赖项会产生 multidex 问题

adding dependencies generates multidex issue

我正在使用这个示例依赖项

compile ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.8.5@aar'){
        transitive=true
    }

Link:- https://github.com/h6ah4i/android-advancedrecyclerview

错误:任务“:app:transformClassesWithDexForDebug”执行失败。

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 2

在您的 gradle 默认配置中添加 multidex true。

defaultConfig {
    ...
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    ... 
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:multidex:1.0.1' //update accordingly
   }

自2014年12月3日起,发布构建工具1.0.0-rc1。现在,您需要做的就是在您的应用程序 class:

中覆盖它
public class YouApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}
and modify your build.gradle like so:

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22

             // Enabling multidex support.
             multiDexEnabled true
         }
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
}

有关详细信息,这是 good guide