[Proguard] How do I get the Java method names of specific classes?

Hi there,
I’m reluctantly building my game with R8 Minify, and using a Custom Proguard File to make sure my packages are not ignored and are compiled into the final APK.

However, some packages are still being missed. How can I find the name of class in Java so I can add it to my Proguard file? Like, say in Unity I have a class called XYZ, what can I add to Proguard User to make sure XTZ and all its methods make it into my APK?

For example, I’m using the Native Share for Android package from the Unity Asset Store. When running in the Editor, my code is executed without errors.
However, when running on device, I can see the error in the logs (using LogCat):

2020/12/14 18:01:22.582 24330 24380 Error Unity AndroidJavaException: java.lang.NoSuchMethodError: no static method with name='Share' signature='(Lcom.unity3d.player.UnityPlayerActivity;Lcom.yasirkula.unity.NativeShareResultReceiver;[Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V' in class Ljava.lang.Object;

From this I gather that NativeShare didn’t make it through the R8 minify, and I want to add the correct line to the Proguard User file in order to make sure it makes it.
I tried adding the following but it didn’t work:

-keep class com.unity.NativeShare.** { *; }

Please help, I unfortunately have to use Minify but I don’t want to give up on these packages.
Thanks!

Based on error it seems your class got renamed. Try writing a rule like this:

-keep class com.google.androidgamesdk.ChoreographerCallback { *; }

That is, no “.**” after the class name. Does that class have nested classed? You may have to add separate rules for those too.

Hi, thanks for the reply!
Unfortunately, the error repeated even after adding the following to the Proguard file:

-keep class com.yasirkula.unity.NativeShareResultReceiver.** { *; }
-keep class com.com.unity3d.player.UnityPlayerActivity.** {*;}
-keep class com.google.androidgamesdk.ChoreographerCallback { *; }

Please advise.

You didn’t need to add Choreographer, it is already in the unity proguard file. It was an example. Have you tried removing “.**” from your line? Does your class has nested classes you want to access too?

Oh, sorry, my bad :slight_smile:

I tried changing to the format you described, but the same error repeated. That’s weird because I don’t think the class has any sub-classes:

-keep class com.yasirkula.unity.NativeShareResultReceiver { *; }

Attached you can find the class I’m trying to reference. I don’t know its logic to a full extent, as I didn’t write this plugin.

6631645–756313–NativeShare.cs (8.13 KB)

Do you also have com.yasirkula.unity.NativeShare in proguard?

That worked! Thank you so much!

As you stated, the correct line I needed to add to Proguard was:

-keep class com.yasirkula.unity.NativeShare { *; }

A shame the error didn’t indicate this being the class that was needed, but now I know the structure we expected for a standard Unity plugin would be com.(comapny).unity.(class_name)

Thank you!

2 Likes