【问题标题】:Error:Execution failed for task ':app:transformClassesWithDexForDebug' Tried all solutions which are available here错误:任务':app:transformClassesWithDexForDebug'的执行失败尝试了所有可用的解决方案
【发布时间】:2017-02-22 04:37:41
【问题描述】:

错误:任务 ':app:transformClassesWithDexForDebug' 执行失败。 com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: 没有在 C:\Users\DELL\AndroidStudioProjects\PK19\app\build\intermediates\transforms\dex\ 创建 dex 文件调试\文件夹\1000\10\instant-run_3e64ab9e373807c9050a33a8846eab1e5e4e2138

这就是我的 gradle 的样子。我使用 android studio 2.1.2

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.example.dell.pk19"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    dexOptions {
        incremental = true;
        preDexLibraries = false
        javaMaxHeapSize "4g" // 2g should be also OK
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'

    compile 'com.android.support:multidex:1.0.0'
}

如何解决这个错误?

【问题讨论】:

  • 您的应用程序类是否扩展了 MultiDexApplication?
  • 好像他没有使用外部库超过65K方法限制。
  • 你能告诉我上面的步骤怎么做吗?
  • 我是 android 和 stackoverflow 的新手。
  • 试试我的链接答案我发布了所有的可能性和他们的解决方案:stackoverflow.com/questions/37497882/…

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


【解决方案1】:

这可能是因为 Android Studio 的即时运行使用了错误的缓存。清理项目并重建它

构建->清理项目

【讨论】:

    【解决方案2】:

    您的应用程序类应该扩展 MultiDexApplication :

    public class App extends MultiDexApplication {...}
    

    那么在 AndroidManifest 中你应该引用这个类:

    <application
        ...
        android:name=".App">
        ...
    </application>
    

    【讨论】:

    • 公共类 App 扩展 MultiDexApplication { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } 在我的 mainactivity 中添加了这个 n 在我的 android 清单中写了 android:name=".app" 但它没有帮助
    • 请检查this link。解释和解决问题的相当一部分在 .gradle 中的“afterEvaluate”块中。希望,它会有所帮助。
    • 复制了“afterEvaluate”块。还是一样的错误
    【解决方案3】:

    就我而言,除此之外,没有可用的解决方案, 我禁用了即时运行。无需在 gradle 中进行任何更改

    文件 → 设置 → 构建、执行、部署 → 即时运行并取消选中启用即时运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-16
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 2017-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多