views:

117

answers:

3

I am trying to use ProGuard with Android. I have found several ProGuard scrips to use, with the following one being an example (I have found several others that are the same or very similar). However, when I try and run ProGuard using this script, I get the error:

"Expecting java type before ';' in line 23 of file ..."

I am completely new to ProGuard. Can someone explain what is going wrong here

Thanks.

-injars      bin(!.svn/**)
-outjars     obfuscated
-libraryjars C:\android-sdk_r04-windows\android-sdk-windows\platforms\android-1.6\android.jar
-libraryjars C:\GoogleAnalyticsAndroid_0.7\libGoogleAnalytics.jar

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-printmapping proguard.map
-keepattributes SourceFile,LineNumberTable

-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.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native ;
}

-keepclasseswithmembernames class * {
    public (android.content.Context, android.util.AttributeSet); 
}

-keepclasseswithmembernames class * {
    public (android.content.Context, android.util.AttributeSet, int); 
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
A: 

From looking at the error message your compiler gave, it looks like the compiler is practically telling you what the problem is.

"Expecting java type before ';' in line 23 of file ..."

I lost count, but it looks like this line is line 23:

native ;

I don't know about you, but that doesn't look like valid Java at all.

Jason Whitehorn
It isn't java, it is a script that is input to ProGuard, which is a java program which takes java code and optimizes, and obfuscates it. I was hoping that someone with experience with ProGuard might know the answer.
John Gaby
+1  A: 

The problem is here:

native ;

Try changing it to:

native <methods>;
finnw
Thanks for the response. I have actually already tried that and it fixes the error on that line, but then I get an error on the 'public (android.content.Context, android.util.AttributeSet);' line. The thing I don't understand is that, based on the posts that I have found, other people have clearly used this script successfully. Were they using an older version of ProGuard or something? Thanks.
John Gaby
Ok, I believe that I have identified the problem. These scripts were posted on some blogs, and it appears that the blogs 'ate' all the elements that were in angle brackets (e.g. the '<methods>' tag). Tracking down those elements and restoring them got it to work. Thanks
John Gaby
A: 

As I commented above, it appears that the problem stems from the fact that the blog from which I obtained the scripts seemed to be 'eating' anything with angle brackets. I decided it would be nice to post the corrected code, in case anyone else is looking for it. The corrected code is as follows:

-injars      bin(!.svn/**)
-outjars     obfuscated
-libraryjars C:\android-sdk\platforms\android-4\android.jar

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-printmapping proguard.map
-keepattributes SourceFile,LineNumberTable

-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.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet); 
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet, int); 
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
John Gaby