Android Studio 3.1 中的任务 ':app:transformClassesWithAndroidGradleClassShrinkerForDebug' 执行失败

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

我刚刚从 Android Studio 3.1 升级到 Android Studio 3.1.1(但仍在使用 Gradle 构建工具 3.0.0 ).当我 运行 我的应用程序时,它会导致此错误:

: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.

但我没有在我的项目中使用 okhttp 或任何 Http 库(如 Retrofit,..)。

当我将 Gradle 构建工具升级到最新版本 3.1.1 时,也会发生此错误。我不知道为什么,当我降级回 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'
}

更新:

我认为这是由 Android Profiler 工具的新功能引起的:网络分析器 因为 com/android/tools/profiler/agent 路径,我打开了跟踪网络负载的高级分析。

我也不想禁用 Proguard。

有什么想法吗?请帮助我。

如果您使用的是 3.1.1

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

那么你的 app/build.gradle 应该如下所示

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'
}

如果 buildToolsVersion 需要然后使用这个

buildToolsVersion '27.0.3'

project(path: ':libzcamera')

中也更改 gradle

这似乎是 Android Studio 3.1.1 的错误。它是 Android Profiler 注入了一些 ProGuard 无法很好处理的额外代码。 手动构建 APK 或执行 gradle 命令不受影响。

选项 1:(首选) 禁用 advanced profiling

选项 2:禁用调试版本的收缩

选项 3:从 Android Studio 部署应用程序时包括 okhttp 库。 [可能仅用于调试风格] (如果测量某些东西可能会有用,ProGuard 将删除任何未使用的方法,不会有太大的开销)


如果上述 solutions/quickfixes 不起作用,请确保您没有使用 okhttp。也许你是 - 它是 not properly configured。您可以使用 gradle app:dependencies 检查您的项目或任何链接库中是否引用了 okhttp。