首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >生成签名apk时生成失败

生成签名apk时生成失败
EN

Stack Overflow用户
提问于 2021-01-26 04:48:53
回答 1查看 466关注 0票数 0

如果我为调试版本启用了r8/proguard,那么我构建应用程序时不会出现任何错误。但是如果我试图生成一个签名的apk,那么构建就会失败,尽管我已经从okhttp和retrofit的github repo中添加了proguard/r8的规则。

使用--info运行Gradle错误日志

代码语言:javascript
运行
复制
R8 is a new Android code shrinker. If you experience any issues, please file a bug at
https://issuetracker.google.com, using 'Shrinker (R8)' as component name. You can
disable R8 by updating gradle.properties with 'android.enableR8=false'.
Current version is: 2.1.75 (build 8142868c18707f172934d5343ba33dc36cff56ad from go/r8bot (luci-r8-custom-ci-xenial-1-nxk4)).

C:\Users\acer\Documents\AndroidStudioProjects\ClassManager-Kotlin\app\build\intermediates\proguard-files\proguard-android-optimize.txt-4.1.2:15:1-15: R8: Ignoring option: -optimizations
C:\Users\acer\Documents\AndroidStudioProjects\ClassManager-Kotlin\app\build\intermediates\proguard-files\proguard-android-optimize.txt-4.1.2:16:1-22: R8: Ignoring option: -optimizationpasses

C:\Users\acer\.gradle\caches\transforms-2\files-2.1\f594407e73853045cddd2f89553be864\jetified-okhttp-4.7.2.jar: R8: Type `org.conscrypt.Conscrypt` was not found, it is required for default or static interface methods desugaring of `Lokhttp3/internal/platform/ConscryptPlatform$Companion;atLeastVersion(III)Z`

> Task :app:minifyReleaseWithR8
C:\Users\acer\.gradle\caches\transforms-2\files-2.1\f594407e73853045cddd2f89553be864\jetified-okhttp-4.7.2.jar: R8: Type `org.conscrypt.ConscryptHostnameVerifier` was not found, it is required for default or static interface methods desugaring of `okhttp3.internal.platform.ConscryptPlatform$platformTrustManager$2`
AGPBI: {"kind":"error","text":"com.android.tools.r8.errors.b: Undefined value encountered during compilation. This is typically caused by invalid dex input that uses a register that is not defined on all control-flow paths leading to the use.","sources":[{}],"tool":"R8"}
Task :app:minifyReleaseWithR8 in app Finished

> Task :app:minifyReleaseWithR8 FAILED
:app:minifyReleaseWithR8 (Thread[Daemon worker Thread 6,5,main]) completed. Took 23.724 secs.
AAPT2 aapt2-4.1.2-6503028-windows Daemon #0: shutdown

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> com.android.tools.r8.CompilationFailedException: Compilation failed to complete

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 33s
29 actionable tasks: 5 executed, 24 up-to-date

我的proguard-rules.pro文件:

代码语言:javascript
运行
复制
-dontobfuscate
-keep public class bd.edu.daffodilvarsity.classmanager.common.models.* { *; }

# Rules for OkHttp library

# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**

# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase

# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*

# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn org.conscrypt.**
-dontwarn okhttp3.internal.platform.**



# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod

# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations

# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}

# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**

# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit

# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.KotlinExtensions

# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>

build.gradle文件:

代码语言:javascript
运行
复制
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.4.21'
    repositories {
        google()
        jcenter()
        maven {
            url "http://storage.googleapis.com/r8-releases/raw/master"
        }
    }
    dependencies {
        classpath 'com.android.tools:r8:2.1.75'
        classpath 'com.android.tools.build:gradle:4.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.4'
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.28-alpha'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://www.jitpack.io" }

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

gradle-wrapper.properties

代码语言:javascript
运行
复制
#Mon Jan 25 03:03:02 BDT 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-03 15:24:18

这是与https://issuetracker.google.com/176381203密切相关的R8中的一个错误。它应该在2.2.53版的R8编译器中修复。修复程序正在进入studio,应该不会晚于Studio4.2 RC1。用户可以通过将以下内容添加到顶级build.gradle文件来使用版本2.2.53:

代码语言:javascript
运行
复制
buildscript {

    repositories {
        maven {
            url 'https://storage.googleapis.com/r8-releases/raw'
        }
    }

    dependencies {
        classpath 'com.android.tools:r8:2.2.53'          // Must be before the Gradle Plugin for Android.
        classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP version.
     }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65892228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档