0

Android ProGuard with androidx lib,Activity protected method has changed to be public.

I have a basic activity extends 'androidx.appcompat.app.AppCompatActivity'. And I have override the protected onCreate() method as protected type. But I use the ProGuard rule like these below, protected onCreate() has change to be public onCreate().Why? Can it be fixed?

-optimizationpasses 5
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-printmapping proguardMapping.txt
-optimizations !code/simplification/cast,!field/*,!class/merging/*
-keepattributes *Annotation*,InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.support.multidex.MultiDexApplication
-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 * extends android.view.View
-keep public class com.android.vending.licensing.ILicensingService
-keep class android.support.** {*;}
-keep class androidx.** {*;}
-keep public class * extends androidx.appcompat.app.AppCompatActivity

-keep public class * extends android.view.View{
    *** get*();
    void set*(***);
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * {
    void *(**On*Event);
    void *(**On*Listener);
}
-keepclassmembers class * extends android.app.Activity {
     public void *(android.view.View);
}
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}
-keep class **.R$* {
    *;
}
-keepclassmembers class * {
    void *(*Event);
}
-keepclasseswithmembers public class * {
    protected <methods>;
    public <methods>;
} 
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
}
-keepclasseswithmembernames class * {
    native <methods>;
}
arjinmc
  • 3
  • 5
  • I have tried -keep class my base activity class it's not worked – arjinmc Aug 08 '19 at 05:50
  • do not use proguard make app bundles instead..proguard messes up code big time. – Pemba Tamang Aug 08 '19 at 06:17
  • @Pemba Tamang So use other proguard? Can you tell what proguard do you use? – arjinmc Aug 08 '19 at 07:41
  • well, I make app bundles and let the playstore sign them. They do all the optimizing themselves. I do not use proguard or minify read more here https://developer.android.com/guide/app-bundle – Pemba Tamang Aug 08 '19 at 07:49
  • Thx all the same. But this app won't be published to playstore. I search much infos but it has not be solved that I think these methods should be changed to public when I use them. – arjinmc Aug 09 '19 at 03:24
  • diable proguard and see `buildTypes { release { minifyEnabled false useProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }` – Pemba Tamang Aug 09 '19 at 17:46

1 Answers1

0

This question seems to address the same problem as yours: R8 changes "protected" methods of abstract class to "public"

The answers there boil down to eliminating -allowaccessmodification from your proguard files.

The easiest way to do that is to copy the generated default proguard file (that you don't control) into your module's proguard.pro file (that you do). You can then edit the latter and use it in your module's build.gradle without any default file.

HendrikFrans
  • 193
  • 9