0

I work on a publicly released android library. And, for external release, I need to run proguard with the following options:

-keep public class com.example.package_one.* {
  public protected *;
}

-keep public class com.example.package_one.subpackage_one.* {
  public protected *;
}

-keep public class com.example.package_one.subpackage_two.* {
  public protected *;
}

-keep public class com.example.package_one.subpackage_three.* {
  public protected *;
}

-keep public class com.example.package_one.subpackage_four.* {
  public protected *;
}

-keep public class com.example.package_one.subpackage_four.sub_subpackage_one.* {
  public protected *;
}

-keepclassmembers class * implements android.os.Parcelable {
    static ** CREATOR;
}

But, the release version of the library is also used internally unproguarded, so I need three types of builds: debug, release, and proguarded release.

To this end I currently have the below build.gradle file for my library:

buildscript {

    repositories {
        mavenCentral()
    }

    dependencies {
       classpath 'com.android.tools.build:gradle:1.3.1'
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 23
    }

    sourceSets {
        main {}

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

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

dependencies {
}

But, when I try to create the proguarded build, all the packages I say to keep are kept, yet all my classes that extend Parcelable, other than those in the packages I say to keep, are obfuscated.

I tried putting a bug in the proguard-android.txt file on my computer, and the build did not crash, so I know that file isn't actually being read. But I don't know what to do to make all my classes that extend Parcelable not be obfuscated, other than explicitly telling proguard to not obfuscate each and every one.

This same proguard file used to work with my old Ant builds, so my guess is I am somehow messing up my gradle build script. Can anyone tell how?

Antion19
  • 227
  • 2
  • 7

1 Answers1

0

-keepclassmembers class * implements android.os.Parcelable { static ** CREATOR; }

This fragment from your ProGuard rules only keeps the class members from Parcelable types - if you want to preserve the naming of the classes/members you would need to add a rule similar to:

-keepnames class * implements android.os.Parcelable

Is there a reason you don't want these types obfuscated?

Owais Ali
  • 724
  • 1
  • 6
  • 14
  • That line is copied from the proguard manual's example for Android projects found here [link](http://proguard.sourceforge.net/). And, for making parcelable classes work, the proguard-android.txt file contains the following: -keepclassmembers class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator CREATOR; } – Antion19 Jan 27 '16 at 23:24
  • The CREATOR class member cannot be obfuscated for a Parcelable object to be able to parcel and deparcel itself reliably between processes with different levels of proguarding. – Antion19 Feb 01 '16 at 18:00