添加recyclerview-v7:23.0.0后编译错误

时间:2015-09-02 02:26:12

标签: android android-studio gradle

我正在使用Android Studio,而我正在尝试将回收站视图添加到我的项目中。添加代码后包括

compile 'com.android.support:recyclerview-v7:23.0.0'

到我的build.gradle文件。当我尝试编译它失败时出现此错误: 错误:任务':app:dexDebug'。

的执行失败
  

com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令' C:\ Program Files \ Java \ jdk1.8.0_45 \ bin \的java.exe''完成非零退出值2

其他商品:如果我删除回收商evething工作正常。我使用版本#22.2.0的所有gradle库版本我有相同的错误,所以我决定将我的projecto更新到版本#23.0.0,但问题仍然存在。还尝试清理项目。没有发现任何问题,因为这个错误与recyclerView有关。

我的傻瓜:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.testproject"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'

    compile 'com.journeyapps:zxing-android-embedded:3.0.2@aar'
    compile 'com.google.zxing:core:3.2.0'
    compile 'io.reactivex:rxjava:1.0.4'
    compile 'io.reactivex:rxandroid:0.25.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.google.android.gms:play-services:7.8.0'
    compile 'com.android.support:design:23.0.0'
    compile 'com.android.support:support-v4:23.0.0'
    compile 'com.android.support:cardview-v7:23.0.0'
    compile 'com.android.support:recyclerview-v7:23.0.0'

}

完整构建消息:

    Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72300Library UP-TO-DATE
:app:prepareComAndroidSupportCardviewV72300Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2300Library UP-TO-DATE
:app:prepareComAndroidSupportMediarouterV72220Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72300Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42300Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServices780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAds780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppindexing780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppinvite780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppstate780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBase780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesCast780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesDrive780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesFitness780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesGames780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesGcm780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesIdentity780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesLocation780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMaps780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesNearby780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesPanorama780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesPlus780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesSafetynet780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesVision780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesWallet780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesWearable780Library UP-TO-DATE
:app:prepareComJourneyappsZxingAndroidEmbedded302Library UP-TO-DATE
:app:prepareComSquareupLeakcanaryLeakcanaryAndroid131Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
    at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
    at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
    at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
    at com.android.dx.command.dexer.Main.run(Main.java:277)
    at com.android.dx.command.dexer.Main.main(Main.java:245)
    at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 12.43 secs
Information:1 error
Information:0 warnings
Information:See complete output in console

1 个答案:

答案 0 :(得分:0)

你只有太多的方法,超过64k,dex无法处理。

https://developer.android.com/tools/building/multidex.html

您应该遵循上面的multidex指南,或者您必须减少项目使用的方法数量。