-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Keep Mapbox.java when obfuscating code #15762
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verified locally, release and debug build test app works on pixel 2
@@ -25,6 +26,7 @@ | |||
*/ | |||
@UiThread | |||
@SuppressLint("StaticFieldLeak") | |||
@Keep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping just the getAssetManager
method that is referenced from JNI is enough in this context and would allow obfuscating all other java methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also look up the class from JNI, so it needs to be kept as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that if you keep at least one method/field from the class, the class name is not going to be obfuscated. This allows all other methods that are not accessed from native to be obfuscated then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, interesting. It fails because if we're looking up a static method, JNI tries to verify the instance first with:
Caused by: java.lang.NoSuchMethodError: no static method "Lcom/mapbox/mapboxsdk/Mapbox;.hasInstance()Z"
The class is not obfuscated, but this internal, static hasInstance()
method seems to be? Anyway 🍏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably could fine tune this with using a specific proguard rule..
This is needed to allow looking up this file from JNI code.
Refs https://github.com/mapbox/mapbox-gl-native/pull/15712/files