Build a full-command-line Android build system

Source: Internet
Author: User

The IDE is to the small white program ape , Daniel level of the program ape must be command line control, terminal control, you see Daniel is using Vim,emacs on everything to fix "

This is a bit of an absolute, though. But it's not unreasonable. To do the development of this line to high efficiency, self-initiative is really lack of command line tools, because only the command line is the best human-computer interaction tool.

The fact that the IDE is also the bottom line is to invoke the command lines tool just to present a more friendly development interface to the general developer.

This is not to preach to let everyone give up the IDE to change the command line, just that every thing has his reason for existence, whether it is a programming language or tools are a principle "no best, only the most suitable."

A period of time to do a person product, the release of the product in order to count the flow of all channels inevitably to build a channel package. You know hundreds of domestic channels. Compiling by the IDE is not a blood-vomiting package. These repeated work is best for a program to do, very many program apes want to not clear this problem, preferring to devote a lot of energy time to business, but do not know to use tools to improve efficiency . Write a simple tutorial here to show you how to get out of the IDE environment an Android project compiled build, with this basic development what self-motivated build tools are not difficult, a time ago to do a packaged HTML5 application online tool AppBuilder is built on the command line.

When it comes to command lines, there is no need for graphical interfaces. So the installation of the Android SDK download is naturally done on the terminal.

The following are some of the SDKs and basic environments used in this article.

    • Ubuntu Server 14.04 (64-bit)
    • JDK 1.7
    • android-sdk_r24.0
    • gradle-2.2.1

To get to the point, the next step is to describe how to install a build system that configures a command line.

Step 1 Installing the JDK environment

JDK with Android is best to use the JDK official version number instead of open JDK, below is the method of installing JDK 1.7 under Unbuntu.

sudo add-apt-repository ppa:webupd8team/javasudo apt-get updatesudo apt-get Install Oracle-java7-installer

Step 2 Installing the Android SDK

Some of the command-line tools for the Android SDK Toolkit are based on 32-bit systems, and in 64 for platform execution 32 programs must have some dependent libraries installed I386, such as the following:

sudo dpkg--add-architecture i386sudo apt-get updatesudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib3 2z1

After installing the 32-bit dependent library, we used wget to download the latest Linux under the Android SDK package.

CD ~wget Http://dl.google.com/android/android-sdk_r24.0.1-linux.tgztar Xvzf android-sdk_r24.0.1-linux.tgz

Edit. Profile or. bash_profile Add the following folder to the search path of path, making sure that some of the command tools for the Android SDK can be used directly at the terminal. For example, the ADB command.

Android_home= $HOME/android-sdk-linuxexport path= "$PATH: $ANDROID _home/tools: $ANDROID _home/platform-tools" Exprot Android_home

Make environment variables effective

SOURCE ~/.profile

After the environment variable is in effect, you can use the Android command to list the SDK-related lists so that we choose the SDK version number that matches your project.

(Just the most basic SDK was installed.) To fully meet your development environment, you have to choose from the list below to download the SDK and tool updates you need.

Android List SDK--all

The output looks like the following:

1-android SDK Tools, revision 24.0.1 2-android SDK Platform-tools, Revision 3-android SDK Build-tools, revision 21.1.2 4-android SDK Build-tools, revision 21.1.1 5-android SDK Build-tools, revision 21.1 6-android SDK build-to OLS, revision 21.0.2 7-android SDK Build-tools, revision 21.0.1 8-android SDK Build-tools, revision 9-android SDK Build-tools, Revision 10-android SDK Build-tools, Revision 19.1 11-android SDK Build-tools, revision 19.0.3 12 -Android SDK Build-tools, revision 19.0.2 13-android SDK Build-tools, revision 19.0.1 14-android SDK Build-tools, rev Ision 15-android SDK Build-tools, revision 18.1.1 16-android SDK Build-tools, revision 18.1 17-android SDK build- Tools, revision 18.0.1 18-android SDK Build-tools, revision 19-documentation for Android SDK, API, Revision 1 2 0-sdk Platform Android 5.0.1, API, Revision 2 21-SDK Platform Android 4.4w.2, API, Revision 2 22-SDK Platform A Ndroid 4.4.2, API, reVision 4 23-sdk Platform android 4.3.1, API, Revision 3 24-SDK Platform Android 4.2.2, API Revision 3 .... 

This includes different Android API version numbers and different build tools. Select the serial number of the project you want to install, here I would like to install build tools 19.1, build tools 21 and Android 4.2.2 + SDK So select the serial number "1,2,3,20,21,22,23"

Android update sdk-u-a-t  1,2,3,10,20,21,22,23

Step 3 Installation Gradle build Environment

Using Ant to build a project is already a past style. Here we use the more powerful and convenient construction tool gradle.

Download Grdle binary Package

CD ~wget Https://services.gradle.org/distributions/gradle-2.2.1-bin.zip

Release to the local home folder, create a symbolic link named "Gradle", the advantage of symbolic connection is convenient version number update. With the new version number, you can change the symbolic link directly.

Unzip Gradle-2.2.1-bin.zip  ln-s gradle-2.2.1 gradle

To configure the GRADLE environment variable and make it effective, edit the ~/.profje file to add the following

Gradle_home= $HOME/gradleexport path= $PATH: $GRADLE _home/bin

Make the environment variable effective after saving

SOURCE ~/.profile

After the environment variable is in effect, you can enter the ' gradle ' command at the terminal and perform a gradle to detect whether the installation was successful.

Gradle

Assuming that there are no problems with the installation configuration, you will be prompted with information similar to the following

: Helpwelcome to Gradle 2.2.1To run a build, run Gradle <task> ... To see a list of available tasks, run Gradle Tasksto see a list of command-line options, run Gradle--helpbuild successful

Verify that you can compile Android apps

Complete the above environment configuration, one of our Android infrastructure environment is all configured, the next thing is to try to compile an Android app using Gradle to verify that my compilation environment is OK, download a gadle demo sample I wrote to test.

git clone https://github.com/examplecode/gradle_democd gradle_demo/hello-apk-with-gradlegradle build

If all goes well, after compiling. You will find the compiled APK package under the "hello-apk-with-gradle/build/outputs/apk" folder.

As for how to integrate into your own projects, just copy the same example to give your project a "gradle.build" script.

Build a full-command-line Android build system

Related Article

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.