在不同 PC 上运行良好的小应用程序上出现 .dex 64K 错误

Getting .dex 64K error on a small app that works fine on a different PC

我最近在一台 PC 上开始了一个新的 Android Studio 项目(非常准系统:3 Activitys,1 Fragment,在这个阶段都非常基础),并且通过 Android Studio 将其上传到版本控制系统(我假设它只会添加必要的文件)。

当我在另一台 PC 上检出项目时,Android Studio 识别出它是一个项目,并提出将其作为一个项目打开。 gradle 构建完成,但在尝试 运行 设备或​​模拟器上的应用程序时,我遇到了老问题:

Error: The number of method references in a .dex file cannot exceed 64K.

唯一的依赖项是 'bluealliance spectrum color picker',我过去使用它没有问题。我会假设它构建了一些错误的东西,但考虑到一切都与原始项目相同,我看不出它是怎么出错的——或者它怎么可能有 >64K 的方法。

以下是 gradle 个文件:

手机build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.1"

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

repositories {
    maven {
        url "http://github.com/wada811/Android-Material-Design-Colors/raw/master/repository/"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.thebluealliance:spectrum:0.6.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:preference-v7:23.2.1'
    compile 'com.android.support:preference-v14:23.2.1'
    compile 'com.wada811:android-material-design-colors:2.0.0'
}

和项目 build.gradle :

buildscript {

    repositories {
        jcenter()
       maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

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

我已经尝试清理和重建项目,并从 git 再次检查它。在这个阶段,作为一个没有经验的开发者,我没有想法。

The only dependency as such is the 'bluealliance spectrum color picker',

不,您至少有七个依赖项,不包括可能位于 libs/ 中的任何 JAR。

其中一个依赖项是 play-services。除非您使用 Play Services SDK 中的每个 API,否则使用更精细的依赖项会更好(例如,play-services-maps 用于 Maps V2),仅引入您需要的那些 Play 服务。

顺便说一句,您应该将 23.2.1 依赖项更改为 23.4.0,这样您所有的 Android 支持库依赖项都来自同一版本。

请删除这行代码

compile 'com.google.android.gms:play-services:9.4.0'