当前位置: 代码迷 >> Android >> android搅混(Obfuscate)
  详细解决方案

android搅混(Obfuscate)

热度:16   发布时间:2016-05-01 12:28:15.0
android混淆(Obfuscate)

Obfuscate an Android application 这篇文章的作者介绍了如何在Android平台下混淆程序,并且给出antbuild.xml文件,经过自己的测试,发现里面少了一些target项,在Eclips会出错,后来结合zxing开源项目的build.xml文件,终于混淆成功,项目包减少了不少。

?

这里主要提一些注意事项,不提供源代码

1、创建build.xml文件

?直接在项目的目录下新建一个名为build.xml的文件

?

?

2、创建Ant打包方式

项目 –> properties –> builders –> new –> ant builder

?

?

接着Buildfile选择项目build.xml文件,Base Dir选择项目目录就行了,记得勾上你的builders

?

?

?

3build.xml文件修改

zxing这个文件没有加入混淆包选项,所以得做一些修改,如下示例

?

Xml代码 复制代码?收藏代码
  1. <property?name="proguard-home"?value="D:\\Program?Files\\proguard4.2\\lib\\"/>??
  2. ??
  3. ????<target?name="optimize"?depends="compile">??
  4. ????????<jar?basedir="${outdir-classes}"?destfile="temp.jar"/>??
  5. ????????<java?jar="${proguard-home}/proguard.jar"?fork="true"?failonerror="true">??
  6. ????????????<jvmarg?value="-Dmaximum.inlined.code.length=32"/>??
  7. ????????????<arg?value="-injars?temp.jar"/>??
  8. ????????????<arg?value="-outjars?optimized.jar"/>??
  9. ????????????<arg?value="-libraryjars?${android-jar}"/>??
  10. ????????????<!--?<arg?value="-libraryjars?${library-jar}/some_lib_used.jar"/>?-->??
  11. ????????????<arg?value="-dontpreverify"/>??
  12. ????????????<arg?value="-dontoptimize"/>??
  13. ????????????<arg?value="-dontusemixedcaseclassnames"/>??
  14. ????????????<arg?value="-repackageclasses?''"/>??
  15. ????????????<arg?value="-allowaccessmodification"/>??
  16. ????????????<arg?value="-keep?public?class?com.iwidsets.WidsetsActivity"/>??
  17. ????????????<!--?<arg?value="-keep?public?class?com.just2me.obfapp.receiver.*"/>?-->??
  18. ????????????<arg?value="-optimizationpasses?7"/>??
  19. ????????????<arg?value="-verbose"/>??
  20. ????????????<arg?value="-dontskipnonpubliclibraryclasses"/>??
  21. ????????????<arg?value="-dontskipnonpubliclibraryclassmembers"/>??
  22. ????????</java>??
  23. ????????<delete?file="temp.jar"/>??
  24. ????????<delete?dir="${outdir-classes}"/>??
  25. ????????<mkdir?dir="${outdir-classes}"/>??
  26. ????????<unzip?src="optimized.jar"?dest="${outdir-classes}"/>??
  27. ????????<delete?file="optimized.jar"/>??
  28. ????</target>??
<property name="proguard-home" value="D:\\Program Files\\proguard4.2\\lib\\"/>	<target name="optimize" depends="compile">		<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 ${library-jar}/some_lib_used.jar"/> -->			<arg value="-dontpreverify"/>			<arg value="-dontoptimize"/>			<arg value="-dontusemixedcaseclassnames"/>			<arg value="-repackageclasses ''"/>			<arg value="-allowaccessmodification"/>			<arg value="-keep public class com.iwidsets.WidsetsActivity"/>			<!-- <arg value="-keep public class com.just2me.obfapp.receiver.*"/> -->			<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>

?

注意:keep public class com.iwidsets.WidsetsActivity需改成你的主Activity

?

?并修改target dex

?

Xml代码
  1. <!--?Convert?this?project's?.class?files?into?.dex?files.?-->??
  2. <target?name="dex"?depends="compile,optimize">??
  3. ????<echo>Converting?compiled?files?and?external?libraries?into?${out-folder}/${dex-file}...</echo>??
  4. ????<apply?executable="${dx}"?failonerror="true"?parallel="true">??
  5. ????????<arg?value="--dex"?/>??
  6. ????????<arg?value="--output=${intermediate-dex-location}"?/>??
  7. ????????<arg?path="${outdir-classes-location}"?/>??
  8. ????????<fileset?dir="${external-libs-folder}"?includes="*.jar"/>??
  9. ????</apply>??
  10. </target>??
  相关解决方案