Build an Android build system with full command lines

Source: Internet
Author: User

Build an Android build system with full command lines

IDE is for white programmers. Cool programmers must use command line control and terminal control. You can see that all cool programmers use vim and emacs can do everything"

Although this is absolutely true, it is not without reason. In order to make development more efficient, automation really lacks the command line tool, because only command line is the best man-machine interaction tool. In fact, IDE is also the underlying layer that also calls the command line tool, but it only presents a more friendly development interface for common developers. This is not to say that everyone should give up IDE and change the command line, but there is a reason for every kind of thing to exist. Whether it is a programming language or a tool, it is a principle "there is no best, only the most appropriate ".

Some time ago, I made a personal product. When I published the product, in order to collect statistics on the traffic of various channels, I had to build a channel package. You know that there are hundreds of channels in China. It is not necessary to rely on IDE compilation and packaging. These repetitive work is most suitable for submitting a program. Many programmers prefer to spend a lot of time on the business, but do not know how to use tools to improve work efficiency. Here is a simple tutorial to show you how to complete the compilation and construction of an android project without the IDE environment. With this basic development, it is not difficult to develop any automated build tool, appBuilder, an online tool for packaging html5 applications, was built based on command lines.

When it comes to command lines, there is no need for a graphical interface. Therefore, the installation and download of the Android SDK are conducted on the terminal. The following are some 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

    Next, we will introduce how to install and configure a compilation and building system under the command line.

    Step 1 install the JDK Environment

    It is best to use JDK official version instead of Open JDK for JDK with android. The following is how to install JDK 1.7 under unbuntu.

     

    sudo add-apt-repository ppa:webupd8team/javasudo apt-get updatesudo apt-get install oracle-java7-installer

     

    Step 2 install the Android SDK

    Some command line tools of the android sdk kit are based on 32-bit systems. To run 32 programs on a 64-bit platform, you must install some i386 dependent libraries. The method is as follows:

     

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

     

    After the 32-bit dependent library is installed, we use wget to download the latest android SDK package for linux.

     

    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 to add the directory below to the path search path. Make sure that some android SDK command tools can be directly used on the terminal, such as the adb command.

     

    ANDROID_HOME=$HOME/android-sdk-linuxexport PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-toolsexprot ANDROID_HOME

     

    Make environment variables take effect

     

    source ~/.profile

     

    After the environment variables take effect, you can use the android command to list sdk-related lists so that we can select the SDK version that matches our project. (The most basic SDK has just been installed. To fully meet your development environment needs, You must select the SDK and tool update and download from the list below)

     

    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  ....

     

    Different Android API versions and build tools are included. Select the serial number of the project you want to install. Here I want to install build tools 19.1, for SDK build tools 21 and android 4.2.2 and above, select the serial number ", 23"

     

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

     

    Step 3 install the gradle Build Environment

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

    Download the grdle Binary Package

     

    cd ~wget https://services.gradle.org/distributions/gradle-2.2.1-bin.zip

     

    Release it to the local Home directory and create a symbolic link named "gradle". The advantage of symbolic connection is that it facilitates version updates. With a new version, you can directly modify the symbolic link.

     

    unzip gradle-2.2.1-bin.zip  ln -s gradle-2.2.1 gradle

     

    Configure the gradle environment variable and make it take effect. Edit ~ /Add the following content to the profje file.

     

    GRADLE_HOME=$HOME/gradleexport PATH=$PATH:$GRADLE_HOME/bin

     

    Save and make the environment variable take effect

     

    source ~/.profile

     

    After the environment variables take effect, you can enter the 'gradle' command on the terminal and run it to check whether gradle is successfully installed.

     

    gradle

     

    If the installation configuration is correct, a message similar to the following is displayed.

     

    :helpWelcome to Gradle 2.2.1To run a build, run gradle 
       
         ...To see a list of available tasks, run gradle tasksTo see a list of command-line options, run gradle --helpBUILD SUCCESSFUL
       

     

    Verify that the android Application can be compiled

    After completing the above environment configuration, all the basic build environments under one of our Android systems have been configured, the next thing to do is to use gradle to compile an android app to verify that my compiling environment is OK. Download a gadle demo example I wrote for testing.

     

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

     

    After compilation, you will find the compiled apk package in the "hello-apk-with-gradle/build/outputs/apk" directory. As for how to integrate it into your own project, you just need to provide a "gradle. build" script for your project following the example.

     

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.