【问题标题】:Getting .dex 64K error on a small app that works fine on a different PC在其他 PC 上正常运行的小应用程序上出现 .dex 64K 错误
【发布时间】:2016-08-27 15:52:03
【问题描述】:

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

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

错误:.dex 文件中的方法引用数不能超过 64K。

唯一的依赖是“bluealliance 光谱颜色选择器”,我过去使用它没有问题。我会假设它构建了一些错误,但考虑到一切都与原始项目相同,我看不出它是如何出错的 - 或者它怎么可能有超过 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 再次检查它。在这个阶段,作为一个缺乏经验的开发人员,我没有想法。

【问题讨论】:

  • 您必须将您的项目转换为 MultiDex。 stackoverflow.com/questions/26609734/…
  • 干净构建或禁用“即时运行”是否有效?这些是应该解决大多数问题的事情。 :)
  • @Sufian Instant run 必须是我最喜欢和最不喜欢的 android studio 功能 - 我会非常有用,但它似乎破坏了一切(虽然不是在这种情况下)

标签: android android-studio dalvik


【解决方案1】:

唯一的依赖是“bluealliance 光谱颜色选择器”,

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

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

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

【讨论】:

  • 天哪。接得好。我想这应该是它。让我们看看OP怎么说。
  • 更改为特定的 gms 服务似乎可以解决问题 - 但为什么它会在其他地方工作而不会引发错误?
  • @nuggetbram:我无法解释这种行为。特别是如果您在两个地方都从头开始(例如,您在原始位置清理了项目),您应该获得等效的构建,因为在您的项目中以版本的形式指定了所有正在使用的工具(例如, build.gradle 文件, gradle-wrapper.properties)。
【解决方案2】:

请去掉这行代码

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

【讨论】:

    猜你喜欢
    • 2019-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-07
    • 2018-04-18
    • 2012-07-25
    • 2012-11-12
    • 2012-05-03
    相关资源
    最近更新 更多