Build a full-command-line Android build system

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">The IDE is for small white <span class="wp_keywordlink">programmers, Daniel level programmer must be command line control, terminal control, you see Daniel is using Vim,emacs on everything to get it done "</span></span></p></p><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">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."</span></p></p><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">A period of time to do a person product, release products in order to count the flow of all channels to build a channel package, you know hundreds of domestic channels, by the IDE compiled packaging non-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 <span class="wp_keywordlink">improve Productivity. Write a simple tutorial here to show you how to get rid of the IDE environment to complete an Android project build, with this basic development of what automated building tools are not difficult, A while ago, a packaged HTML5 application online tool Appbuilder is built on the command line. </span></span></p></p><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">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.</span></p></p> <ul> <ul> <li><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">Ubuntu Server 14.04 (64-bit)</span></li> <li><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">JDK 1.7</span></li> <li><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">android-sdk_r24.0</span></li> <li><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">gradle-2.2.1</span></li> </ul> </ul><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">To get to the point, the next step is to describe how to install a build system that configures a command line.</span></p></p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;"><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">Step 1 Installing the JDK environment</span></span><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">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.</span></p></p><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;"></span></p></p><pre><pre>sudo add-apt-repository ppa:webupd8team/<span style="color: #000000;">javasudo apt</span>-<span style="color: #000000;">get updatesudo apt</span>-get Install Oracle-java7-installer</pre></pre><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;"><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">Step 2 Installing the Android SDK</span></span><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">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:</span></p></p><pre><pre>sudo dpkg--add-<span style="color: #000000;">architecture i386sudo apt</span>-<span style="color: #000000;">get updatesudo apt</span>-get install libc6:i386 libncurses5:i386 Libstdc++6:i386 LIB32Z1</pre></pre><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">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.</span></p></p><pre><pre>CD ~<span style="color: #000000;">wget http:</span><span style="color: #008000;">//</span><span style="color: #008000;">dl.google.com/android/android-sdk_r24.0.1-linux.tgz</span>tar xvzf android-sdk _r24.0.1-linux.tgz</pre></pre><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;"></span></p></p><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">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.</span></p></p><pre><pre>Android_home= $HOME/android-sdk-<span style="color: #000000;">linuxexport PATH</span>= "$PATH: $ANDROID _home/tools: $ANDROID _home/ Platform-tools "<span style="color: #000000;">Exprot android_home</span></pre></pre><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;"></span></p></p><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">Make environment variables effective</span></p></p><pre><pre>SOURCE ~/.profile</pre></pre><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">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)</span></p></p><pre><pre>Android List Sdk--all</pre></pre><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">The output is as Follows:</span></p></p><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;"></span></p></p><pre>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<span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span>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 Platform Android 4.4.2, API 4 revision 23-sdk Android Platform, API 3 24 -SDK Platform Android 4.2.2, API 3, Revision<span style="color: #000000;"><span style="color: #000000;"> ....</span></span></pre><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">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 "</span></p></p><pre><pre>Android Update Sdk-u-a-t 1,2,3,10,20,21,22,23</pre></pre><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;"><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">Step 3 Installation Gradle build Environment</span></span><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">Using Ant to build a project is already past, and here we use the more powerful and convenient build tool Gradle.</span></p></p><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">Download Grdle binary Package</span></p></p><pre><pre>CD ~<span style="color: #000000;">wget https:</span><span style="color: #008000;">//</span><span style="color: #008000;">services.gradle.org/distributions/gradle-2.2.1-bin.zip</span></pre></pre><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">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.</span></p></p><pre><pre>Unzip gradle-2.2.1-<span style="color: #000000;">bin.zip </span>-s gradle-2.2.1 gradle</pre></pre><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">To configure the GRADLE environment variable and make it effective, edit the ~/.profje file to add the following</span></p></p><pre><pre>Gradle_home= $HOME/<span style="color: #000000;">gradleexport PATH</span>= $PATH: $GRADLE _home/bin</pre></pre><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">Make the environment variable effective after saving</span></p></p><pre><pre>SOURCE ~/.profile</pre></pre><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">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.</span></p></p><pre><pre>Gradle</pre></pre><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">If there is no problem with the installation configuration, you will be prompted with information similar to the following</span></p></p><pre><pre><span style="color: #000000;"></span>2.2.1<span style="color: #000000;"></span><task> ...<span style="color: #000000;"> To see a list of available tasks, run Gradle tasksto see a list of command</span>-line options, run gradle--<span style="color: #000000;">helpbuild S Uccessful</span></pre></pre><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;"><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">Verify that Android apps can be compiled</span></span><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">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.</span></p></p><pre><pre>git clone https:<span style="color: #008000;">//</span><span style="color: #008000;">github.com/examplecode/gradle_demo</span>cd gradle_demo/hello-apk-with- <span style="color: #000000;"> Gradlegradle Build</span></pre></pre><p><p><span style="font-size: 15px; font-family: arial, helvetica, sans-serif;">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.</span></p></p><p><p>Build a full-command-line Android build system</p></p></span>

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.