Obfuscation during Android ant Compilation

Source: Internet
Author: User

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
  1. <Property name = "proguard-home" value = "D:/define setools/proguard4.4/lib"/>

 

Add the obfuscated target configuration to build. xml:

 

XML Code
  1. <! -- Execute proguard class flies -->
  2. <Target name = "optimize">
  3. <Jar basedir = "$ {outdir-classes}" destfile = "Temp. Jar"/>
  4. <Java jar = "$ {proguard-home}/proguard. Jar" fork = "true" failonerror = "true">
  5. <Jvmarg value = "-dmaximum. inlined. Code. Length = 32"/>
  6. <Arg value = "-injars temp. Jar"/>
  7. <Arg value = "-outjars optimized. Jar"/>
  8. <Arg value = "-libraryjars $ {Android-jar}"/>
  9. <! -- <Arg value = "-libraryjars $ {external-libs}/*. Jar"/> -->
  10. <Arg value = "-dontpreverify"/>
  11. <Arg value = "-dontoptimize"/>
  12. <Arg value = "-dontusemixedcaseclassnames"/>
  13. <Arg value = "-repackageclasses'' "/>
  14. <Arg value = "-allowaccessmodification"/>
  15. <! -- <Arg value = "-keep public class $ {exclude-activity}"/> -->
  16. <! -- <Arg value = "-keep public class $ {exclude-provider}"/> -->
  17. <Arg value = "-keep public class * extends Android. App. Activity"/>
  18. <Arg value = "-keep public class * extends Android. content. contentprovider"/>
  19. <Arg value = "-keep public class * extends Android. View. View"/>
  20. <Arg value = "-keep public class * extends Android. Preference. Preference"/> <Arg value = "-optimizationpasses 7"/>
  21. <Arg value = "-verbose"/>
  22. <Arg value = "-dontskipnonpubliclibraryclasses"/>
  23. <Arg value = "-dontskipnonpubliclibraryclassmembers"/>
  24. </Java>
  25. <Delete file = "Temp. Jar"/>
  26. <Delete dir = "$ {outdir-classes}"/>
  27. <Mkdir dir = "$ {outdir-classes}"/>
  28. <Unzip src = "optimized. Jar" DEST = "$ {outdir-classes}"/>
  29. <Delete file = "optimized. Jar"/>
  30. </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
  1. <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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.