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

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

Closed

Description

@Larnoo

Platform: Android
Mapbox SDK version: 5.0.0

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

Activity

  1. 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[/+] on May 9, 2017
  2. tobrun commented on May 9, 2017

    @tobrun
    Member

    @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'
    }
    
  3. added
    Android
    on May 9, 2017
  4. mpuchala commented on May 9, 2017

    @mpuchala

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

  5. tobrun commented on May 9, 2017

    @tobrun
    Member

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

  6. reopened this on May 9, 2017
  7. added this to the android-v5.1.0 milestone on May 9, 2017
  8. 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[/+] on May 9, 2017
  9. tobrun commented on May 9, 2017

    @tobrun
    Member

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

  10. added
    beta blocker
    release blocker
    on May 9, 2017
  11. tobrun commented on May 9, 2017

    @tobrun
    Member

    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.

  12. removed
    beta blocker
    on May 9, 2017
  13. self-assigned this
    on May 11, 2017
  14. tobrun commented on May 15, 2017

    @tobrun
    Member

    This landed in #8944 to the release branch, closing

  15. mare011 commented on May 30, 2017

    @mare011

    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

  16. reopened this on May 30, 2017
  17. tobrun commented on Jun 1, 2017

    @tobrun
    Member

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

  18. mare011 commented on Jun 2, 2017

    @mare011

    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.**
    
  19. tobrun commented on Jun 2, 2017

    @tobrun
    Member

    @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.** { *;}
    
  20. mare011 commented on Jun 2, 2017

    @mare011

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

  21. tobrun commented on Jun 2, 2017

    @tobrun
    Member

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

  22. mare011 commented on Jun 2, 2017

    @mare011

    No problem.

  23. sddamico commented on Jul 14, 2017

    @sddamico

    @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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Androidbuildrelease blocker

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions