About Android Build

Source: Internet
Author: User

There is a series of articles on Android in Jane's book, which is good, some students can read and study in the process of development: Www.jianshu.com/collection/3fde3b545a35

About Android build, see this post. Students can refer to:

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 i386    sudo apt-get update    sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1

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.tgz    tar 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-linux    export 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 3-android SDK Build-tools, Revisi On 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 9-andro  ID 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, Revision 15-android SDK Build-tools, revision 18.1.1 16-android SDK Build-tools, revision 18.1 17-android SDK Bui   Ld-tools, revision 18.0.1 18-android SDK Build-tools, revision 19-documentation for Android SDK, API, Revision 1 20-sdk Platform Android 5.0.1, API, Revision 2 21-SDK Platform Android 4.4w.2, API, Revision 2 22-SDK platfor M Android 4.4.2, API 19, Revision 4 23-sdk Platform android 4.3.1, API 3 revision 24-SDK Android Platform, API 4.2.2 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.

Reference: Build a full-command-line Android build system (see: Www.jianshu.com/p/1694ea9a3f90)

About Android Build

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.