Http://www.javaeye.com/topic/787389
For ant compilation and script see: http://sinfrancis.javaeye.com/blog/721582
Proguard4.4 is used here, and the following code is added to the original Ant script:
Define the home of proruard4.4:
XML Code
- <Property name = "proguard-home" value = "D:/define setools/proguard4.4/lib"/>
Add the obfuscated target configuration to build. xml:
XML Code
- <! -- Execute proguard class flies -->
- <Target name = "optimize">
- <Jar basedir = "$ {outdir-classes}" destfile = "Temp. Jar"/>
- <Java jar = "$ {proguard-home}/proguard. Jar" fork = "true" failonerror = "true">
- <Jvmarg value = "-dmaximum. inlined. Code. Length = 32"/>
- <Arg value = "-injars temp. Jar"/>
- <Arg value = "-outjars optimized. Jar"/>
- <Arg value = "-libraryjars $ {Android-jar}"/>
- <! -- <Arg value = "-libraryjars $ {external-libs}/*. Jar"/> -->
- <Arg value = "-dontpreverify"/>
- <Arg value = "-dontoptimize"/>
- <Arg value = "-dontusemixedcaseclassnames"/>
- <Arg value = "-repackageclasses'' "/>
- <Arg value = "-allowaccessmodification"/>
- <! -- <Arg value = "-keep public class $ {exclude-activity}"/> -->
- <! -- <Arg value = "-keep public class $ {exclude-provider}"/> -->
- <Arg value = "-keep public class * extends Android. App. Activity"/>
- <Arg value = "-keep public class * extends Android. content. contentprovider"/>
- <Arg value = "-keep public class * extends Android. View. View"/>
- <Arg value = "-keep public class * extends Android. Preference. Preference"/> <Arg value = "-optimizationpasses 7"/>
- <Arg value = "-verbose"/>
- <Arg value = "-dontskipnonpubliclibraryclasses"/>
- <Arg value = "-dontskipnonpubliclibraryclassmembers"/>
- </Java>
- <Delete file = "Temp. Jar"/>
- <Delete dir = "$ {outdir-classes}"/>
- <Mkdir dir = "$ {outdir-classes}"/>
- <Unzip src = "optimized. Jar" DEST = "$ {outdir-classes}"/>
- <Delete file = "optimized. Jar"/>
- </Target>
Note: The-keep parameter indicates which classes are not obfuscated. For details, refer to the progurard documentation. All files configured in the XML file cannot be confused. Otherwise, the class cannot be found during running.
Add the command to call the obfuscated target in the compiled target:
XML Code
- <Antcall target = "optimize"/>
This is acceptable.
If you use the xmlpull class library, do not add it to the source code for obfuscation. The Android class library already contains xmlpull. Otherwise, obfuscation will fail and will occur.
Warning: Library class android. content. res. xmlresourceparser extends or implements program class org. xmlpull
. V1.xmlpullparser
And Other Related errors.