生成签名apk时生成失败



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

使用——info

命令运行Gradle时的错误日志
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:UsersacerDocumentsAndroidStudioProjectsClassManager-Kotlinappbuildintermediatesproguard-filesproguard-android-optimize.txt-4.1.2:15:1-15: R8: Ignoring option: -optimizations
C:UsersacerDocumentsAndroidStudioProjectsClassManager-Kotlinappbuildintermediatesproguard-filesproguard-android-optimize.txt-4.1.2:16:1-22: R8: Ignoring option: -optimizationpasses
C:Usersacer.gradlecachestransforms-2files-2.1f594407e73853045cddd2f89553be864jetified-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:Usersacer.gradlecachestransforms-2files-2.1f594407e73853045cddd2f89553be864jetified-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。支持文件:

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

构建。gradle文件:

// 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

#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

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

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

最新更新