Android Studio gradle 发布 Build 耗时无限

Android Studio gradle release Build taking infinite time

我最近将我的代码库更新为 Androidx,现在尝试使用命令构建生产变体

> ./gradlew assembleProduction

它在进程 transformClassesAndResourcesWithProguardForProductionRelease 中继续构建

这是输出

Note: com.google.android.gms.measurement.internal.zzgp: can't find dynamically referenced class com.google.android.gms.tagmanager.TagManagerService
Note: com.google.android.gms.measurement.internal.zzs: can't find dynamically referenced class android.os.SystemProperties
Note: com.google.android.youtube.player.internal.aa: can't find dynamically referenced class com.google.android.youtube.api.locallylinked.LocallyLinkedFactory
Note: com.squareup.okhttp.internal.Platform: can't find dynamically referenced class com.android.org.conscrypt.SSLParametersImpl
Note: com.squareup.okhttp.internal.Platform: can't find dynamically referenced class org.apache.harmony.xnet.provider.jsse.SSLParametersImpl
Note: com.squareup.okhttp.internal.Platform: can't find dynamically referenced class sun.security.ssl.SSLContextImpl
Note: io.fabric.sdk.android.FabricKitsFinder: can't find dynamically referenced class com.google.android.gms.ads.AdView
Note: kotlin.internal.PlatformImplementationsKt: can't find dynamically referenced class kotlin.internal.JRE8PlatformImplementations
Note: kotlin.internal.PlatformImplementationsKt: can't find dynamically referenced class kotlin.internal.JRE7PlatformImplementations
Note: okhttp3.internal.platform.AndroidPlatform$CloseGuard$Companion: can't find dynamically referenced class dalvik.system.CloseGuard
Note: okhttp3.internal.platform.AndroidPlatform$Companion: can't find dynamically referenced class com.android.org.conscrypt.SSLParametersImpl
Note: okhttp3.internal.platform.AndroidPlatform$Companion: can't find dynamically referenced class com.android.org.conscrypt.OpenSSLSocketImpl
Note: okhttp3.internal.platform.ConscryptPlatform$Companion: can't find dynamically referenced class org.conscrypt.Conscrypt$Version
Note: okhttp3.internal.platform.Platform: can't find dynamically referenced class sun.security.ssl.SSLContextImpl
Note: the configuration refers to the unknown field 'com.google.android.gms.common.api.internal.BasePendingResult$ReleasableResultGuardian mResultGuardian' in class 'com.google.android.gms.common.api.internal.BasePendingResult'
Note: the configuration refers to the unknown method 'com.android.vending.billing.IInAppBillingService asInterface(android.os.IBinder)' in class 'com.android.vending.billing.IInAppBillingService'
Note: the configuration refers to the unknown method 'com.google.android.gms.measurement.AppMeasurement getInstance(android.content.Context,java.lang.String,java.lang.String)' in class 'com.google.android.gms.measurement.AppMeasurement'
Note: the configuration explicitly specifies 'sun.misc.Unsafe' to keep library class 'sun.misc.Unsafe'
Note: the configuration explicitly specifies 'org.xmlpull.v1.**' to keep library class 'org.xmlpull.v1.XmlPullParser'
Note: the configuration explicitly specifies 'org.xmlpull.v1.**' to keep library class 'org.xmlpull.v1.XmlPullParserException'
Note: the configuration explicitly specifies 'org.xmlpull.v1.**' to keep library class 'org.xmlpull.v1.XmlPullParserFactory'
Note: the configuration explicitly specifies 'org.xmlpull.v1.**' to keep library class 'org.xmlpull.v1.XmlSerializer'
Note: the configuration explicitly specifies 'android.widget.Space' to keep library class 'android.widget.Space'
Note: there were 7 references to unknown classes.
      You should check your configuration for typos.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
Note: there were 3 references to unknown class members.
      You should check your configuration for typos.
Note: there were 6 library classes explicitly being kept.
      You don't need to keep library classes; they are already left unchanged.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#libraryclass)
Note: there were 49 unresolved dynamic references to classes or interfaces.
      You should check if you need to specify additional program jars.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Note: there were 1 class casts of dynamically created class instances.
      You might consider explicitly keeping the mentioned classes and/or
      their implementations (using '-keep').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclasscast)
Ignoring unused library classes...
  Original number of library classes: 24139
  Final number of library classes:    2071
Printing kept classes, fields, and methods...
Inlining subroutines...
Shrinking...
Printing usage to [/Users/harsh/git/Mobile_Android_MVA/app/build/outputs/mapping/production/release/usage.txt]...
Removing unused program classes and class elements...
  Original number of program classes: 21242
  Final number of program classes:    21242
Optimizing (pass 1/5)...
<=<============-> 99% EXECUTING [14m 57s]
> :app:transformClassesAndResourcesWithProguardForProductionRelease

我的 gradle.properties 看起来像这样

> org.gradle.jvmargs=-Xmx3096m -XX:MaxPermSize=512m
> -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
> 
> org.gradle.parallel=true org.gradle.daemon=true
> # Disables R8 for Android Library modules only. android.enableR8.libraries = false
> # Disables R8 for all modules. android.enableR8 = false android.useAndroidX=true android.enableJetifier=true
> 
> org.gradle.configureondemand=true

我正在使用混淆器并发布 buildType 具有以下内容

minifyEnabled true
useProguard true
shrinkResources true
zipAlignEnabled true
debuggable false

我尝试使用和不使用 androidx proguard,但结果相同

-keep class androidx.appcompat.widget.** { *; }
-dontwarn com.google.android.material.**
-keep class com.google.android.material.** { *; }

-dontwarn androidx.**
-keep class androidx.** { *; }
-keep interface androidx.** { *; }

你能帮我解决这个问题吗,这样我就可以生成一个签名的 apk

您使用的 Android Studio 是哪个版本? 3.4?

当您使用 R8 而不是 Proguard 进行编译时会发生什么?有时错误消息更明确。