Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Keep Mapbox.java when obfuscating code #15762

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.AssetManager;
import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
Expand All @@ -25,6 +26,7 @@
*/
@UiThread
@SuppressLint("StaticFieldLeak")
@Keep
Copy link
Contributor

@LukasPaczos LukasPaczos Oct 4, 2019

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.

Copy link
Member Author

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

Copy link
Contributor

@LukasPaczos LukasPaczos Oct 4, 2019

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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 🍏

Copy link
Member Author

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..

public final class Mapbox {

private static final String TAG = "Mbgl-Mapbox";
Expand Down