This article Wheat College and small partners to share in detail about the android Ant command-line compilation and the APK signature details some of the implementation methods, this is a friend in the development of their own Android wrote, I hope to be helpful to everyone.
Recently in the development of Android, you need to refer to a third-party code into the project, under normal circumstances, directly under Eclipse to set the code to import the compiled output for the library, but a lot of code compiled under eclipse there will be a lot of inexplicable errors. Therefore, you can only compile the code using the command line method. Here's how:
1. Install the compiled Java, install android platform-tools, install ant, set up various environment variables. Some Linux under Ant has been integrated by default and needs to be installed by itself under Windows.
2. Use the Android tool to update the compilation configuration of your code.
3. Compile with the Ant tool to compile the debug version and release version.
4. Generate the private key for the code signing and sign the APK.
5. To align the apk file, the big file apk has a good effect.
The following is a reference to the bash code, which can be changed by itself, and when executed, sudo bash xxx.sh can be
The code is as follows
# Setup Java Home
Java_home = "/system/library/java/javavirtualmachines/1.6.0.jdk/contents/home"
# Setup Android Home
Android_home= "~/android-sdk-macosx"
# Setup Path
PATH = "$ANDROID _home/tools: $JAVA _home/bin: $PATH"
# Update Current Project
Android Update Project--path.
#android Update Project--path./LIBRARY/LIB1
#android Update Project--path./library/lib2
# Remove KeyStore
Rm-f Product.keystore
# Make Keystone
Keytool-genkey-alias Product.keystore-keyalg rsa-validity 40000
-keystore product.keystore-storepass password-keypass Password
-dname "Cn=product ou=android Team o=organization l=hongkong st=hongkong C=china"
# clean
Ant Clean
# Remove Ant.properties
Rm-f ant.properties
# Make Ant.properties
echo "Key.store=product.keystore" > Ant.properties
echo "Key.alias=product.keystore" >> ant.properties
# Build APK
Ant Release
# sign APK
# Jarsigner-verbose-keystore Product.keystore-signedjar
# bin/product_signed.apk bin/product-release-unsigned.apk Product.keystore
# Zip Align apk
# zipalign-v 4 bin/product_signed.apk bin/product_final.apk
Description
Update your Android's ant compilation configuration, if the structure of your code changes, if your code contains referenced third-party library code, you need to update the code separately.
The code is as follows
# Update Current Project
Android Update Project--path.
#android Update Project--path./LIBRARY/LIB1
#android Update Project--path./library/lib2
Generate signature with KeyStore file, description of several parameters
-genkey Generating a secret key certificate
-alias aliases
Calculation algorithm of-KEYALG secret key
-validity Validity
-keystore KeyStore File path
-storepass secret key Vault Password
-keypass secret key Certificate password
-dname Issuer Information
cn= Issuer Name (individual name or product name)
ou= organizational unit name (team name)
o= Organization name (company name)
L= City/region
st= State/Province
C= Country Code
The code is as follows
# Make Keystone
Keytool-genkey-alias Product.keystore-keyalg rsa-validity 40000
-keystore product.keystore-storepass password-keypass Password
-www.maiziedu.com-keypass Password
-dname "Cn=product ou=android Team o=organization l=hongkong st=hongkong C=CN"
Build an ant auto-compiled ant.properties file, set Key.store and Key.alias two variables, and automatically sign and align the generated apk when ant release
The code is as follows
echo "Key.store=product.keystore" > Ant.properties
echo "Key.alias=product.keystore" >> ant.properties
Manual code signing, description of several parameters
-verbose Display Output
-keystore KeyStore Aliases
-signedjar signature apk file, the first parameter is the target file, the second is unsigned apk
The code is as follows
# sign APK
Jarsigner-verbose-keystore Product.keystore-signedjar bin/product_signed.apk bin/product-release-unsigned.apk Product.keystore
To align the apk manually
The code is as follows
# Zip Align apk
Zipalign-v 4 bin/product_signed.apk bin/product_final.apk
Some tips on ant command Compilation and APK signature in Android development