Build a full-command-line Android build system

Source: Internet
Author: User

The IDE is for small white programmers, Daniel level programmer must be command line control, terminal control, you see Daniel is using Vim,emacs on everything to get it done "

Although some absolute, but also reasonable, to do the development of this line to high efficiency, automation is really lack of command line tools, because only the command line is the best human-computer interaction tool. In fact, the IDE is also the bottom of the call command-line tools, but to ordinary developers to present a more friendly development interface. This is not to let everyone give up the IDE to change the command line, but every thing has his reason for existence, whether it is a programming language or tools are a principle of "no best, only the most suitable."

A time ago to do a person product, Release the product in order to count the flow of the channel to build a channel package, you know the domestic channel hundred, by the IDE compiled packaging is not vomiting. These repetitive work is best for a program, many programmers do not understand the problem, preferring to spend a lot of time on business, but do not know to use tools to improve productivity. Write a simple tutorial here to show you how to complete a build of an Android project out of the IDE environment, with this basic development of what automated build tools are not difficult, a time ago to do a packaged HTML5 application online tool

When it comes to the command line, there is no need for a graphical interface, so the installation and download of the Android SDK 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 official JDK version instead of the 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 running 32 programs for the platform must install some of the i386 dependent libraries, as follows:

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 use wget to go to the official download of 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 directory to the search path of path, making sure that some command tools for the Android SDK can be used directly at the terminal, such as 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 that matches your project. (Just installed the most basic SDK, to fully meet your development environment need to choose from the list below you need to download the SDK and tool updates)

Android List SDK--all

The output is as follows:

1- android sdk tools, revision 24.0.1   2- android sdk  platform-tools, revision 21   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-tools, revision 21.0.2   7- android sdk  build-tools, revision 21.0.1   8- android sdk build-tools,  revision 21   9- android sdk build-tools, revision 20   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, revision 19  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 17  19- documentation for android sdk, api  21, revision 1  20- sdk platform android 5.0.1, api 21 , revision 2  21- sdk platform android 4.4w.2, api 20,  Revision 2  22- sdk platform android 4.4.2, api 19, revision  4  23- sdk platform android 4.3.1, api 18, revision 3   24- SDK platform android 4.2.2, api 17, revision 3   

Here are the different Android API versions and different build tools, select the serial number of the project you want to install, here I want to install build tools 19.1, build tools 21 and Android 4.2.2 + SDK So select the serial number "1,2,3,20,2 1,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 past, and here we use the more powerful and convenient build tool gradle.

Download Grdle binary Package

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

Release to the local home directory, create a symbolic link named "Gradle", the advantage of symbolic connection is convenient version update, with a new version directly modify the symbolic link.

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 run it to detect if the Gradle is successfully installed.

Gradle

If there is no problem 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 Android apps can be compiled

Complete the above environment configuration, one of our Android infrastructure environment is fully 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 example 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 in the "hello-apk-with-gradle/build/outputs/apk" directory. As for how to integrate into your own projects, just follow the example to provide a "gradle.build" script for your project.


Build a full-command-line Android build system

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.