a complete package to perform the following steps: Compile, code obfuscation, packing apk, signature apk, apk optimized.
In order to use NDKcase bear in a native code used here works TestJni.
in the project root directory create local.properties file, enter the path of sdk and ndk
For example:
sdk.dir = D: \ \ Android \ \ android-sdk
ndk.dir = D: \ \ Android \ \ android-ndk
in the project root directory create build.xml, enter the code
<?xml version="1.0" encoding="UTF-8"?>
<project name="TestJni" default="my.package">
<loadproperties srcFile="local.properties" />
<loadproperties srcFile="project.properties" />
<fail message="sdk.dir is missing." unless="sdk.dir" />
<fail message="ndk.dir is missing." unless="sdk.dir" />
<target name="native">
<echo message="Building native libraries..." />
<exec executable="${ndk.dir}/ndk-build.cmd" failonerror="true" />
<echo message="DONE (Building native libraries)" />
</target>
<import file="${sdk.dir}/tools/ant/build.xml" />
<target name="my.package" depends="native,release">
</target>
</project>
my.package rely on native and release, performed a ndk compile and release operations.
open cmd, switch to the project root directory, type ant my.package, waiting for build to complete, in the bin directory swells into unsigned apk file.
code obfuscation
If project.properties is configured proguard.config = proguard.cfg , release time will automatically code obfuscation. In the $ {sdk.dir} / tools / ant / build.xml can find the appropriate target.
<target name="-release-obfuscation-check">
<echo level="info">proguard.config is ${proguard.config}</echo>
<condition property="proguard.enabled" value="true" else="false">
<and>
<isset property="build.is.mode.release" />
<isset property="proguard.config" />
</and>
</condition>
<if condition="${proguard.enabled}">
<then>
<echo level="info">Proguard.config is enabled</echo>
<!-- Secondary dx input (jar files) is empty since all the
jar files will be in the obfuscated jar -->
<path id="out.dex.jar.input.ref" />
</then>
</if>
</target>
proguard.enabled that is the basis for release mode and set proguard.config this property.
signature
in $ {sdk.dir} / tools / ant / build.xml Find a release target
<target name="release"
depends="-set-release-mode, -release-obfuscation-check, -package, -post-package, -release-prompt-for-password, -release-nosign, -release-sign, -post-build"
description="Builds the application in release mode.">
</target>
we see-release-sign this targer, continue to find the target
View first line
<target name="-release-sign" if="has.keystore" >
If you perform the signature, then has.keystore this condition to be established, continue to find has.keystore
<!-- properties for signing in release mode -->
<condition property="has.keystore">
<and>
<isset property="key.store" />
<length string="${key.store}" when="greater" length="0" />
<isset property="key.alias" />
</and>
</condition>
<condition property="has.password">
<and>
<isset property="has.keystore" />
<isset property="key.store.password" />
<isset property="key.alias.password" />
</and>
</condition>
find the above two condition, has.keystore established the conditions set key.store and key.alias these two property, and key.store length can not be 0.
has.password established conditions, has.keystore established, and set up key.store.password and key.alias.password, if not the words of these two properties, the build process will be asked to enter a password.
add these attributes in local.properties
key.store = D: \ \ Android \ \ keystore \ \ test_key.keystore
key.alias = test_key
key.store.password = 123456
key.alias.password = 123456
open cmd, switch to the project root directory, run ant my.package, in the bin directory generated TestJni-release.apk.
check whether the generated apk optimized
this point, packaged complete.
没有评论:
发表评论