【问题标题】:Android - transform Classes With Dex For DebugAndroid - 使用 Dex 转换类进行调试
【发布时间】:2016-03-26 15:41:50
【问题描述】:

在我添加 Facebook 依赖项之前,我的项目运行良好。 我已经开始收到此错误。 我读过很多问题,问题似乎与MultiDex 有关。 但是没有一个解决方案对我有用

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: 
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command 
'/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 1

即使我删除了我添加的内容,它仍然显示,而且 gradle 在构建时似乎比平时花费了很多时间

这是我的 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "net.ciblo.spectrodraft"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    multiDexEnabled true

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

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

repositories {
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }

}
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.daimajia.easing:library:1.0.1@aar'
compile 'com.daimajia.androidanimations:library:1.1.3@aar'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.pnikosis:materialish-progress:1.5'
compile 'com.nineoldandroids:library:2.4.+'
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'

}

【问题讨论】:

  • 当您使用 --debug 和 --stacktrace 在命令行上构建时,您是否看到更具体的错误?
  • 对不起,我不知道如何用命令行构建
  • @HarounSMIDA 你能从 Gradle 控制台发布完整的日志吗?

标签: android android-gradle-plugin android-multidex


【解决方案1】:

将以下代码添加到build.gradle app 模块解决了我的问题

android{
    defaultConfig {

        // Enabling multidex support.
        multiDexEnabled true
    }


    dexOptions {
        javaMaxHeapSize "4g"
    }
}
dependencies {
    //...
    compile 'com.android.support:multidex:1.0.0'
}

【讨论】:

  • 所以你做的加法是javaMaxHeapSize "4g"
  • 是的,这就是我添加的
  • 非常好的解决方案,谢谢。我尝试只包含multiDexEnabled true,它通过了。我不需要包含其他代码行。测试这是否有效;否则,请继续添加 Haroun 描述的其余内容。
【解决方案2】:

这个可怕的反复出现的问题最近再次袭击了我。 gradle 构建在 app:transformClassesWithDexForDebug 处永久停止,只运行了几个小时并且从未完成。这次我通过删除所有对“fabric”的引用来修复它,这是一个新的 Crashlytics 层被推到我们身上。

//apply plugin: 'io.fabric'   //REMOVE
//classpath 'io.fabric.tools:gradle:1.26.1'  //REMOVE

【讨论】:

    【解决方案3】:

    在 build.gradle 中添加以下内容为我解决了这个问题,

    android {
    //...
    
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    //...
    }
    

    【讨论】:

      【解决方案4】:

      您可以选择性地将 Google Play 服务 API 编译到您的应用中。例如,要仅包含 Google Fit 和 Android Wear API,请在 build.gradle 文件中替换以下行:

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

      这些行:

      compile 'com.google.android.gms:play-services-fitness:8.4.0'
      compile 'com.google.android.gms:play-services-wearable:8.4.0'
      

      ==> 将您应用中的方法数量(包括框架 API、库方法和您自己的代码)保持在 65,536 个限制以下。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-14
      • 2018-04-27
      • 2017-05-05
      • 2016-04-21
      • 1970-01-01
      • 2014-09-04
      • 1970-01-01
      • 2011-08-09
      相关资源
      最近更新 更多