Search code examples
androidwear-osandroid-wear-data-apiandroid-proguard

Android Wear Proguard


I tried using proguard with my Android Wear application, but I'm not sure what should be going into the rules. In my wear app's gradle file I have:

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

and my proguard-rules.pro looks like:

-keepattributes SourceFile,LineNumberTable

When I run my app, the UI works, but anything that accesses the DataApi is missing. Anyone have any ideas/experience?


Solution

  • I got it to work by combining parts of Firefox's proguard config with some of my own:

    -keep class com.google.android.gms.common.api.** {*;}
    -keep class com.google.android.gms.wearable.** {*;}
    
    # Firefox
    -keep class * extends java.util.ListResourceBundle {
        protected Object[][] getContents();
    }
    -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
        public static final *** NULL;
    }
    -keepnames @com.google.android.gms.common.annotation.KeepName class *
    -keepclassmembernames class * {
        @com.google.android.gms.common.annotation.KeepName *;
    }
    -keepnames class * implements android.os.Parcelable {
        public static final ** CREATOR;
    }
    -keepattributes SourceFile,LineNumberTable
    # Preserve all fundamental application classes.
    -keep public class * extends android.app.Activity
    -keep public class * extends android.app.Application
    -keep public class * extends android.app.Service
    -keep public class * extends android.app.backup.BackupAgentHelper
    -keep public class * extends android.content.BroadcastReceiver
    -keep public class * extends android.content.ContentProvider
    -keep public class * extends android.preference.Preference
    
    -keep public class * extends android.support.v4.app.Fragment
    
    # Preserve all native method names and the names of their classes.
    -keepclasseswithmembernames class * {
        native <methods>;
    }
    
    -keepclasseswithmembers class * {
        public <init>(android.content.Context, android.util.AttributeSet, int);
    }
    
    -keepclassmembers class * extends android.app.Activity {
       public void *(android.view.View);
    }
    
    # Preserve enums. (For awful reasons, the runtime accesses them using introspection...)
    -keepclassmembers enum * {
         *;
    }