Execution failed for task ':app:transformClassesWithAndroidGradleClassShrinkerForDebug' in Android Studio 3.1

大城市里の小女人 提交于 2019-12-08 02:37:40

问题


I've just upgraded from Android Studio 3.1 to Android Studio 3.1.1 (but still using Gradle build tool 3.0.0). When I run my app it causes this error:

:app:transformClassesWithAndroidGradleClassShrinkerForDebug
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okhttp3/Interceptor
com/android/tools/profiler/agent/okhttp/OkHttp2Interceptor references unknown class: com/squareup/okhttp/Interceptor
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okhttp3/Request
com/android/tools/profiler/agent/okhttp/OkHttp2Interceptor references unknown class: okio/Okio
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okhttp3/ResponseBody
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okio/Okio
com/android/tools/profiler/agent/okhttp/OkHttp2Interceptor references unknown class: com/squareup/okhttp/Request
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okhttp3/Response
com/android/tools/profiler/agent/okhttp/OkHttp2Interceptor references unknown class: com/squareup/okhttp/Headers
com/android/tools/profiler/agent/okhttp/OkHttp2Interceptor references unknown class: com/squareup/okhttp/ResponseBody
com/android/tools/profiler/agent/okhttp/OkHttp2Interceptor references unknown class: com/squareup/okhttp/Interceptor$Chain
com/android/tools/profiler/agent/okhttp/OkHttp2Interceptor references unknown class: com/squareup/okhttp/Response$Builder
com/android/tools/profiler/agent/okhttp/OkHttp2Interceptor references unknown class: com/squareup/okhttp/Response
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okhttp3/Headers
com/android/tools/profiler/agent/okhttp/OkHttp2Interceptor references unknown class: com/squareup/okhttp/RequestBody
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okhttp3/OkHttpClient$Builder
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okhttp3/HttpUrl
com/android/tools/profiler/agent/okhttp/OkHttp2Interceptor references unknown class: com/squareup/okhttp/OkHttpClient
com/android/tools/profiler/agent/okhttp/OkHttp2Interceptor references unknown class: okio/BufferedSource
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okhttp3/Interceptor$Chain
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okhttp3/Response$Builder
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okhttp3/RequestBody
com/android/tools/profiler/agent/okhttp/OkHttp2Interceptor references unknown class: okio/BufferedSink
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okio/BufferedSource
com/android/tools/profiler/agent/okhttp/OkHttp3Interceptor references unknown class: okio/BufferedSink
:app:transformClassesWithAndroidGradleClassShrinkerForDebug FAILED
:app:buildInfoGeneratorDebug

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithAndroidGradleClassShrinkerForDebug'.
> Warnings found during shrinking, please use -dontwarn or -ignorewarnings to suppress them.

But I'm NOT using okhttp or any Http library (like Retrofit,..) in my project.

This error also happens when I'm upgrading Gradle build tool to the newest version 3.1.1. I don't know why, everything is fine when I downgrade back to Android Studio 3.1.0.

app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.z.a.zcamera"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(path: ':libzcamera')
    implementation 'com.android.support:support-v4:26.1.0'
}

Update:

I think it is caused by Android Profiler tool's new feature: the network profiler because of the com/android/tools/profiler/agent path and I'm turning ON the advanced profiling to track network payload.

I also don't want to disable Proguard too.

Any ideas? Please help me.


回答1:


It seems like a bug of Android Studio 3.1.1. It's Android Profiler injects some additional code that is not well-handled by ProGuard. Building APKs or executing gradle commands manually is not affected.

Option 1: (prefered) Disable advanced profiling.

Option 2: Disable shrinking for Debug builds

Option 3: Include okhttp library while deploying app from Android Studio. [probably only for debug flavor] (may be useful if measuring something, ProGuard will remove any unused methods, will be no big overhead)


If solutions/quickfixes above don't work, please make sure you are not using okhttp. Maybe you are - and it's not properly configured. You may use gradle app:dependencies to check if okhttp is referenced in your project or any linked libraries.




回答2:


if you are using 3.1.1

  classpath 'com.android.tools.build:gradle:3.1.1'

then your app/build.gradle should be like given below

apply plugin: 'com.android.application' 
android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.z.a.zcamera"
    minSdkVersion 14
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(path: ':libzcamera')
implementation 'com.android.support:support-v4:27.1.0'
}

if buildToolsVersion require then use this

buildToolsVersion '27.0.3'

also change gradle in project(path: ':libzcamera')



来源:https://stackoverflow.com/questions/49770112/execution-failed-for-task-apptransformclasseswithandroidgradleclassshrinkerfo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!