Android command line compile, package build apk file

Source: Internet
Author: User

First, build the environment

1. Installing the JDK and Android SDK

2. Configure Environment variables
D:\android-sdk-windows\tools
C:\Program Files\java\jdk1.6.0_20\bin

3. Example Information
Project directory: D:\ProjectDemo
SDK Directory: D:\android-sdk-windows\platforms\android-8\


Second, the command line to compile the Android project

1. Generate R file

2. Java code generation class file

3. class file generates DEX file

4. Packaging Resources

5. Build apk

6. Create a key

7. Signature APK


1. AAPT command, generate R file

> aapt package-f-m-j/gen-s res-m androidmanifest.xml-i D:\android.jar


-F If the compiled generated file already exists, force overwrite.
-M causes the directory of the generated package to be stored in the directory specified by the-J parameter
-J Specifies the output directory path of the generated R.java
-s specifies the path to the Res folder

-i specifies the path to the Android.jar file for a version platform

-a specifies the path of the Assert folder




2. Javac command, generate class file

> Javac-target 1.5-bootclasspath D:\android-sdk-windows\platforms\android-8\android.jar-d bin src\demo\project\* . Java Gen\demo\project\r.java


-target < version > Generate a class file for a specific VM version
-bootclasspath < path > Overwrite the location of the boot class file
-D < directory > Specify the location where the generated class files are stored
-sourcepath < paths > Specify where to find the input source files



3. DX command, convert class file to. dex File

> DX--dex--output=d:\projectdemo\bin\classes.dex D:\ProjectDemo\bin


--output=< the Classes.dex path to be generated > < path to the class file to be processed >



4. AAPT command, Packaging resources

> Aapt package-f-M androidmanifest.xml-s res-i D:\android-sdk-windows\platforms\android-8\android.jar-F Bin\resou Rces.ap_


-F If the compiled generated file already exists, Force overwrite
-m specifies the path of the Androidmanifest.xml
-s Specifies the Res folder path

-i specifies the path to the Android.jar of a version platform

-f Specifies the full path to the output file




5. Apkbuilder command, Generate APK

Apkbuilder D:\ProjectDemo\bin\projectdemo.apk-v-u-z D:\ProjectDemo\bin\resources.ap_-F D:\ProjectDemo\bin\ CLASSES.DEX-RF D:\PROJECTDEMO\SRC


-V Verbose Show process information
-U Create a non-signed package
-Z Specify APK resource path
-F Specify the Dex file path

-rf specifying the source path



6. Create a key

>keytool-genkey-alias release-keyalg rsa-validity 20000-keystore release.keystore


-genkey a default file ". KeyStore" is created in the user's home directory, and a MyKey alias is generated, MyKey contains the user's public key, private key, and certificate
-alias Generating aliases
-keyalg the algorithm that specifies the key
-validity specifies how many days to create a certificate validity period
-keystore Specifies the name of the KeyStore (the resulting types of information will not be in the. keystore file)



7. Signature

Jarsigner-verbose-keystore C:\Users\UserName\Desktop\build\release.keystore-storepass Antmima-keypass Antmima- Signedjar D:\ProjectDemo\bin\projectdemo-signed.apk D:\ProjectDemo\bin\projectdemo.apk Release


-verbose output details when signing/validating
-keystore KeyStore Location
-storepass password for key-store integrity
-keypass Password for private key (if different)
-signedjar the name of the signed JAR file (the first apk is the file after the signature, the second apk is the one that needs to be signed)


Android command line compile, package build apk file

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.