android自动打包-简单实现 使用ant打包android程序+多渠道+签名
<arg value="${resource-dir}" /> <arg value="-M" /> <arg value="${manifest-xml}" /> <arg value="-I" /> <arg value="${android-jar}" /> <arg value="${verbose}" /> </exec> </target> <!-- 编译aidl文件 --> <target name="aidl" depends="gen-R"> <echo>编译aidl文件....</echo> <apply executable="${aidl}" failonerror="true"> <!-- 指定预处理文件 --> <arg value="-p${framework-aidl}" /> <!-- aidl声明的目录 --> <arg value="-I${srcdir}" /> <!-- 目标文件目录 --> <arg value="-o${outdir-gen}" /> <!-- 指定哪些文件需要编译 --> <fileset dir="${srcdir}"> <include name="**/*.aidl" /> </fileset> </apply> </target> <!-- 将工程中的java源文件编译成class文件 --> <target name="compile" depends="aidl"> <echo>java源文件编译成class文件....</echo> <javac encoding="${encoding}" source="${source}" target="${target}" debug="true" extdirs="" destdir="${outdir-classes}" verbose="false" classpath="${outdir-classes-ospath}" bootclasspath="${android-jar}" includeAntRuntime="false"> <src path="${srcdir}" /> <src path="${outdir-gen}" /> <classpath> <fileset dir="${external-lib-ospath}" includes="*.jar" /> </classpath> </javac> <!-- <antcall target="optimize"/> --> </target>
<target name="optimize" unless="no-optimize"> <mkdir dir="optimized"/> <java jar="${proguard-jar}" fork="true" failonerror="true"> <jvmarg value="-Dmaximum.inlined.code.length=48"/> <arg value="-injars ${outdir-classes}"/> <arg value="-outjars optimized"/> <arg value="-libraryjars ${android-jar}"/> <arg value="-libraryjars ${external-lib-ospath}/kuguobanner-com.pkgc.b-1.0.5.jar"/> <arg value="-libraryjars ${external-lib-ospath}/kuguobanner-com.pkgc.b-1.0.5.jar"/> <arg value="-libraryjars ${external-lib-ospath}/kuzai-com.pkgc.k-2.0.4.jar"/> <arg value="-libraryjars ${external-lib-ospath}/umeng_sdk.jar"/> <arg value="-keep class com.yeung.game.sevendemons523.*"/> <!-- <arg value="-keep class org.cocos2dx.lib.* { public * }"/> --> <arg value="-target ${target}"/> <arg value="-optimizationpasses 6"/> <arg value="-optimizations !field/*,!class/merging/*"/> <!-- works around dex VerifyError --> <arg value="-dontshrink"/> <arg value="-dontobfuscate"/> <arg value="-dontskipnonpubliclibraryclasses"/> <arg value="-verbose"/> <arg value="-dump proguard-dump.txt"/> <classpath> <fileset dir="${external-lib-ospath}" includes="*.jar" /> </classpath> </java> <!-- <delete dir="${outdir-classes}"/> --> <move file="optimized" tofile="${outdir-classes}"/> </target> <!-- 将.class文件转化成.dex文件 --> <target name="dex" depends="compile"> <echo>将.class文件转化成.dex文件....</echo> <apply executable="${dx}" failonerror="true"
parallel="true"> <arg value="--dex" /> <arg value="--output=${dex-ospath}" /> <arg path="${outdir-classes-ospath}" /> <fileset dir="${external-lib-ospath}" includes="*.jar"/> </apply> </target> <!-- 将资源文件放进输出目录 --> <target name="package-res-and-assets"> <echo>将资源文件放进输出目录...</echo> <exec executable="${aapt}" failonerror="true"> <arg value="package" /> <arg value="-f" /> <arg value="-M" /> <arg value="${manifest-xml}" /> <arg value="-S" /> <arg value="${resource-dir}" /> <arg value="-A" /> <arg value="${asset-dir}" /> <arg value="-I" /> <arg value="${android-jar}" /> <arg value="-F" /> <arg value="${resources-package}" /> <arg value="-J" /> <arg value="${outdir-gen}" /> <arg value="${verbose}" /> </exec> </target> <!-- 打包成未签证的apk --> <target name="package" depends="dex, package-res-and-assets"> <echo>打包成未签证的apk....</echo> <exec executable="${apkbuilder}" failonerror="true"> <arg value="${out-unsigned-package-ospath}" /> <arg value="-u" /> <arg value="-z" /> <arg value="${resources-package-ospath}" /> <arg value="-f" /> <arg value="${dex-ospath}" /> <arg value="-nf" /> <arg value="${external-lib-ospath}" />
<arg value="-rf" /> <arg value="${srcdir-ospath}" /> <arg value="-rj"/> <arg value="${external-lib-ospath}" /> <arg value="${verbose}"/> </exec> </target> <!-- 对apk进行签证 --> <target name="jarsigner" depends="package"> <echo>对apk进行签证...</echo> <exec executable="${jarsigner}" failonerror="true"> <arg value="-keystore" /> <arg value="${keystore-file}" /> <arg value="-storepass" /> <arg value="${keystore-storepass}" /> <arg value="-keypass" /> <arg value="${keystore-keypass}" /> <arg value="-signedjar" /> <arg value="${out-signed-unzipalign-package-ospath}" /> <arg value="${out-unsigned-package-ospath}" /> <!-- 证书的别名 --> <arg value="${keystore-alias}" /> </exec> </target> <!-- 发布 --> <target name="release" depends="jarsigner"> <!-- 删除未签证apk --> <delete file="${out-unsigned-package-ospath}" /> <echo>签证成功. path:${out-signed-unzipalign-package-ospath}</echo> </target> <!-- 打包的应用程序进行优化 --> <target name="zipalign" depends="release"> <echo>打包的应用程序进行优化...</echo> <delete file="${out-signed-package-ospath}" /> <exec executable="${zipalign}" failonerror="true"> <arg value="${verbose}" /> <arg value="4" /> <arg value="${out-signed-unzipalign-package-ospath}" />
<arg value="${out-signed-package-ospath}" /> </exec> <delete file="${out-signed-unzipalign-package-ospath}" /> <echo>APK优化完成. path:${out-signed-package-ospath}</echo> </target> </project>
1234567890ABCDEFGHIJKLMNabcdefghijklmn!@#$%^&&*()_+.一三五七九贰肆陆扒拾,。青玉案元夕东风夜放花千树更吹落星如雨宝马雕车香满路凤箫声动玉壶光转一夜鱼龙舞蛾儿雪柳黄金缕笑语盈盈暗香去众里寻他千百度暮然回首那人却在灯火阑珊处