完美解决:app:transformClassesWithDexForDebug

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_24118527/article/details/82904068

最近被这个问题卡了整整两天,期间搜索了各种回答,感觉StackOverflow中许多开发者和我遇到的问题很像,但是依照他们的解决方法去做总是解决不了问题qwq

今天一个偶然的机会,终于解决了这个问题,原来是我之前看了有些不太规范的回答,导致我的gradle.build文件里面有一些很关键的地方写错了,今天恰好看到了一个StackOverflow的帖子对这个细节进行描述,最终解决了问题。

解决过程如下:

之前我的gradle.build文件是这样的

请仔细看这个地方

这个地方其实是有问题的,问题在哪里呢,就是这个

运行起来的结果就是...红红火火

真的是忧伤

但是去掉之后,it works like a charm...

我现在的build.gradle是这样的

附上源码,可供大家参考(这个是没有error版的)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.0 '
    defaultConfig {
        applicationId "com.example.administrator.wrongtry"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false

    /*dexOptions {
        //javaMaxHeapSize "2048M"
    }*/
}


repositories {
    maven {
        url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //compile files('libs/android-support-v4.jar')
    
    // MPAndroidChart
    compile 'com.github.PhilJay:MPAndroidChart:v3.0.3'
    // RecycleView


    //noinspection GradleCompatible
    compile'com.android.support:appcompat-v7:25.3.1'
    compile'com.android.support.constraint:constraint-layout:1.0.2'
    compile'com.android.support:recyclerview-v7:27.0.0'
    compile'com.github.PhilJay:MPAndroidChart:v3.0.3'
    compile'com.facebook.stetho:stetho:1.4.1'
    compile 'com.uphyca:stetho_realm:2.0.0'
    compile 'com.github.PhilJay:MPAndroidChart-Realm:v3.0.3@aar'
    compile 'com.android.support:cardview-v7:27.0.0'
    compile 'com.android.support:design:27.0.0'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.android.support:support-v4:27.0.0'
    testCompile 'junit:junit:4.12'

    compile 'com.jakewharton:butterknife:8.4.0'
    compile project(':lib')
    compile project(':qmui')
    compile 'com.android.support:support-v4:27.0.0'

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

apply plugin: 'realm-android'

下面详细说一下原因


这是给我启发很大的一个回答

https://stackoverflow.com/questions/38758700/i-am-getting-many-of-these-erroruncaught-translation-error-if-it-helps-i-am-b

也就是说,dexOptions{ ... }这个东西是可以放在两个不同的地方的

一个是android{ ... }的这个大括号里面

另一个外面没有东西,直接放

这两种放的方式是不一样的,里面可以放的东西也不一样

我之前就是一个错误示范

切记,如果要在gradle里面加东西(相当于配置工作),当你看到网上有一条语句要你加进去,你最好自己打出来,看看有没有这个候选项的。我之前那个就是,你把那句错的写进去,gradle也是可以sync的,没有问题,那句话也没有标红,但是编译就是有错,你还找不出错在哪里,真是气啊qwq

猜你喜欢

转载自blog.csdn.net/qq_24118527/article/details/82904068
今日推荐