android - 在 minifyEnabled true 后,使用 google for android 登录在发布的 apk 中不起作用

标签 android proguard

我研究了一整天。由于发布 SHA1,大多数人都面临问题,但我已经使用所有方法(命令行和 Android studio)进行了检查。我得到了相同的发布哈希 key ,如果我在发布版本中将 minifyEnabled 设置为 false,它就可以工作。

如果我将 minifyEnabled 设置为 true 来混淆文件,则 google 登录将无法正常工作。

这是我的 proguard 文件

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

# -keep public class * extends android.app.Activity
# -keep public class * extends android.app.Application
# -keep public class * extends android.app.Service
# -keep public class * extends android.content.BroadcastReceiver
# -keep public class * extends android.content.ContentProvider
# -keep public class * extends android.app.backup.BackupAgentHelper
# -keep public class * extends android.preference.Preference
# -keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *

-keepclassmembernames class *
{
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

-keep class com.google.android.gms.common.GooglePlayServicesUtil {*;}

-dontwarn com.google.android.gms.**
-keepattributes SourceFile,LineNumberTable

-adaptresourcefilenames

-adaptresourcefilecontents

-keepdirectories

#-keepclassmembers class * {
#  public void *(android.view.View);
#}

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}
-keep public class com.google.android.gms.ads.** {
   public *;
}

-keep public class com.google.ads.** {
   public *;
}

-dontwarn java.lang.invoke.*
-dontwarn **$$Lambda$*

# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions

-dontwarn org.xmlpull.v1.**
-dontwarn okhttp3.**
-keep class okhttp3.** { *; }
-dontwarn okio.**
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault
-dontwarn javax.annotation.**

-keepclassmembers class * {
  @com.google.api.client.util.Key <fields>;
}

-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault
-keep class com.google.** {*;}

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

非常感谢任何帮助,在这个问题上花了一整天的时间!

最佳答案

经过2天的努力,我解决了。问题在于改造和模型类。

我们不应该允许重命名如此保留的模型类

-dontwarn okio.**
-dontwarn java.lang.invoke.*
-dontwarn retrofit2.Platform$Java8
-keep class retrofit.** { *; }
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * {
    @retrofit.http.* <methods>;
}
-keepclasseswithmembers interface * {
    @retrofit.http.* <methods>;
}
-keepclasseswithmembers interface * {
    @retrofit2.* <methods>;
}

-keep class com.google.gson.** { *; }
-keep class com.google.inject.** { *; }
-keep class javax.inject.** { *; }
 -keep class com.yourproject.YourClass**
 -keepclassmembers class com.yourproject.YourClass** {
    *;
 }

关于android - 在 minifyEnabled true 后,使用 google for android 登录在发布的 apk 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46669412/

相关文章:

java - 如何将 ViewPager 添加到 Android 应用程序中的抽屉导航项?

javascript - 这个 for 循环有什么作用?

java - Proguard 由于特定的第三方库而产生运行时错误

android - 如何将Android R8混淆应用于 native 代码?

android - Proguard 和 Scoreloop

android - Retrofit 返回 404 响应码

java - 帮助在 Java 中将颜色十六进制存储为整数

android - 如何使用 Eclipse + Proguard "run"导出的 Android 应用程序?

java - JavaME 和/或 Proguard 会重新排序分配吗?

java - 原始文件未显示在android studio中