[Android] build Android app based on Linux command line (iii): Build process

Source: Internet
Author: User

The Android app builds and packages the files and resources in the Android project, and finally outputs the results to the. apk file. The. apk file is the container that holds the binaries, and it contains all the information needed to run the Android app, such as the compiled. Dex The file (. class corresponds to the Dalvik bytecode), a binary androidmanifest.xml file, the compiled resource (RESOURCES.ARSC), and the non-compiled resource.

If you are using Eclipse for development, the ADT plugin will continue to build your project and automatically output the. apk file to your project's Bin folder, so you don't have to do anything for the entire build process.

If you are not using Eclipse for development, you can use Ant + Build.xml,build.xml to be the ant build file, located under the project root directory. Ant automatically calls the build tool to complete the build process.

In order for the Android app to run on Android, you need to sign the Android app, and the signature is divided into debug (debug) and release two modes. In the development phase, you typically use debug mode for signing, when the build tool uses a debug key (Debug key) and a password so you don't have to enter the password every time you build it. When you want to formally publish your Android app through Google Play, you must use your private key to build your app in release mode.

Both Eclipse and ANT support automatic signing in both modes.

Describes the processes and components from building to running an Android app:

Build process

Many tools are used throughout the build process to build. APK, and many temporary files need to be processed and generated.

Describes the tools and related files that are used throughout the build process:

The overall build process is as follows:

Android Asset Packaging tool, or AAPT, is responsible for compiling all resource files, such as Androidmanifest.xml and describing the Activity's XML file, and generating a R.java file, so You can reference your resource file in Java code.

The Aidl tool converts all. AIDL interfaces into Java interfaces.

The Java compiler compiles all Java code in the project, including the R.java and. aidl files, into a. class file.

The Dex tool converts a. class file to a Dalvik byte code. All third-party libraries and. class files are also converted to Dalvik bytecode so they can eventually be packaged in the. apk file.

The Apkbuilder tool packages all the non-compiled resources (examples), compiled resources, and. Dex together into an. apk file.

When the. apk file is generated, it needs to be signed (Debug or Release mode), otherwise the. apk file cannot be installed on the Android device.

Finally, when you use release mode to sign, you also need to use the Zipalign tool to adjust the. apk file, which reduces the memory footprint of the Android app running on the device.

Note: Android app has 64K method reference[1] restrictions. If this limit is reached, the following error message will be printed during the build process:

 not in [0, 0xFFFF]: 65536.

You can use the load secondary Dex files at runtime and use Proguard to eliminate nonessential class references. (Proguard only works in release mode)

Note:

[1] 64K method reference limit refers to the Android compiler to restrict each. dex file to reference only 65,536 methods.

  

Report:

1. Building and Running

2. Learn about app signatures: Signing Your applications

  

[Android] build Android app based on Linux command line (iii): Build process

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.