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

[android] config proguard-rules.pro file for release #8931

Closed
Larnoo opened this issue May 9, 2017 · 14 comments
Closed

[android] config proguard-rules.pro file for release #8931

Larnoo opened this issue May 9, 2017 · 14 comments
Assignees
Labels
Android Mapbox Maps SDK for Android build release blocker Blocks the next final release

Comments

@Larnoo
Copy link

Larnoo commented May 9, 2017

Platform: Android
Mapbox SDK version: 5.0.0

[android] when app use mapbox sdk, how to config proguard-rules.pro file for app release

@Larnoo Larnoo changed the title [android] when use mapbox sdk, how to config proguard-rules.pro file for release [android] when app use mapbox sdk, how to config proguard-rules.pro file for release May 9, 2017
@tobrun
Copy link
Member

tobrun commented May 9, 2017

@Larnoo thank you for this question, we package a proguard configuration file in the SDK. You activate it with using the following in your build.gradle:

release {
   minifyEnabled true
   proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

@tobrun tobrun closed this as completed May 9, 2017
@tobrun tobrun added Android Mapbox Maps SDK for Android build labels May 9, 2017
@mpuchala
Copy link

mpuchala commented May 9, 2017

@tobrun
Just for clarification - 5.0.2 works like a charm (proguard).
Actually I've tried last beta version 5.1.0-beta.1 and there was a problem on start (crash) - are you sure nothing has changed? If it's required I can check for logs.

@tobrun
Copy link
Member

tobrun commented May 9, 2017

Thank you for the report @mpuchala, going to use this issue to track it for 5.1.0 release.

@tobrun tobrun reopened this May 9, 2017
@tobrun tobrun added this to the android-v5.1.0 milestone May 9, 2017
@tobrun tobrun changed the title [android] when app use mapbox sdk, how to config proguard-rules.pro file for release [android] config proguard-rules.pro file for release May 9, 2017
@tobrun
Copy link
Member

tobrun commented May 9, 2017

pinpointed the native crash to ConnectivityReceiver.instance(appContext); in Mapbox.java.

@tobrun tobrun added beta blocker Blocks the next beta release release blocker Blocks the next final release labels May 9, 2017
@tobrun
Copy link
Member

tobrun commented May 9, 2017

Looking at the mapping.txt, currently nothing from our proguard configuration is picked up anymore.
This was a misconfiguration in gradle, consumer proguard was only activated for release builds.

@tobrun tobrun removed the beta blocker Blocks the next beta release label May 9, 2017
@tobrun tobrun self-assigned this May 11, 2017
@tobrun
Copy link
Member

tobrun commented May 15, 2017

This landed in #8944 to the release branch, closing

@tobrun tobrun closed this as completed May 15, 2017
@mare011
Copy link

mare011 commented May 30, 2017

My app crashes when using proguard with version 5.1.0.beta.3 or snapshot, working fine with 5.0.2.
Error:
A/libc: /usr/local/google/buildbot/src/android/ndk-r13-release/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:74: void abort_message(const char *, ...): assertion "terminating with uncaught exception of type jni::PendingJavaException" failed
A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 742

@tobrun tobrun reopened this May 30, 2017
@tobrun
Copy link
Member

tobrun commented Jun 1, 2017

@mare011

I'm not running in any proguard issues using the test app. Are you hooking into the "default" proguard config?

        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

For the reference this is the config I'm using in the test app:

-dontwarn android.support.**
-dontwarn java.lang.**
-dontwarn org.codehaus.**
-keep class com.google.**
-dontwarn com.google.**
-dontwarn java.nio.**
-keep class android.support.v7.** { *; }

Without having more information, I'm not able to look into this more. Closing as non reproducible.

@tobrun tobrun closed this as completed Jun 1, 2017
@mare011
Copy link

mare011 commented Jun 2, 2017

Sorry, i thought it wasn't app specific, cause it's working with 5.0.2, here's the config:

buildTypes {
        release {
            minifyEnabled true
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
     }
}

Rules:

# General
-keepattributes Signature
-keepattributes Exceptions
-keepattributes *Annotation*
-keepattributes EnclosingMethod

# Javascript
-keepattributes JavascriptInterface
-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

# Glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
    **[] $VALUES;
    public *;
}

# Retrofit
-dontnote retrofit2.Platform # Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor # Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8 # Platform used when running on Java 8 VMs. Will not be used at runtime.

# OkHttp 3
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

# Okio
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**

# App compat
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
    public <init>(android.content.Context);
}

# Butterknife
-keep public class * implements butterknife.Unbinder { public <init>(**, android.view.View); }
-keep class butterknife.*
-keepclasseswithmembernames class * { @butterknife.* <methods>; }
-keepclasseswithmembernames class * { @butterknife.* <fields>; }

# Joda time
-dontwarn org.joda.convert.**
-dontwarn org.joda.time.**
-keep class org.joda.time.** { *; }
-keep interface org.joda.time.** { *; }

# Unity
-dontwarn com.androidnative.**
-keep public class com.unity.plugins.** { *; }
-keep class com.unity3d.** { *; }
-keep class bitter.jnibridge.** { *; }
-keep class org.fmod.** { *; }

# Billing
-keep class com.android.vending.billing.**

@tobrun
Copy link
Member

tobrun commented Jun 2, 2017

@mare011 what happens if you add the following to that config?

-keepattributes Signature, *Annotation*, EnclosingMethod
-keep class almeros.android.multitouch.gesturedetectors.** { *; }
-keep class com.mapbox.mapboxsdk.** { *; }
-keep interface com.mapbox.mapboxsdk.** { *; }
-keep class com.mapbox.services.android.telemetry.** { *; }
-keep class com.mapbox.services.commons.** { *;}

@mare011
Copy link

mare011 commented Jun 2, 2017

@tobrun This line helped: -keep class com.google.**

@tobrun
Copy link
Member

tobrun commented Jun 2, 2017

a great @mare011! afaik this isn't something that we should include in our config. Thank you for following up!

@mare011
Copy link

mare011 commented Jun 2, 2017

No problem.

@sddamico
Copy link

@tobrun at the very least -keep class com.google.gson.** { *; } might be needed for your config.

I'm working on the upgrade to 5.1 and it seems that the sdk is accessing these gson classes as part of the new strategy for handling modifying geojson?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android build release blocker Blocks the next final release
Projects
None yet
Development

No branches or pull requests

5 participants