Linuxandroid deploy_build the android environment under Linuxubuntu14.04

Source: Internet
Author: User
For those who have just started to learn about android development, the establishment of the android development environment is still complicated, not only because they need to understand the functions of various concepts and tools, but also their relationships; even more, google, a developer of these tools, cannot access websites in China. This article describes how to build an android development environment from scratch, create a helloworld mobile app, and run it on AVM and smart phones.

For those who have just started to learn about android development, the establishment of the android development environment is still complicated, not only because they need to understand the functions of various concepts and tools, but also their relevance; even more, google, a developer of these tools, cannot access websites in China. This article describes how to build an android development environment from scratch, create a hello world mobile app, and run it on AVM and smart phones.

First, Android apps are developed in java, so JDK is indispensable for compiling apps. In addition, the SDK Manager mentioned later and the running of Android Studio also need to install JDK (JDK 7 or a later version is required) to start. Although ubuntu software library contains a openjdk-7-jdk, you can easily install, but android is recommended to use the JDK provided by oracle. The Oracle version of JDK8 can be downloaded from the official page or shared with my Baidu online storage. If you use the Oracle version, uninstall openjdk. Download and decompress the package. For example, extract the package to/home/yanzs/java/jdk1.8.0 _ 40. Then you need to set the JAVA_HOME and PATH environment variables in ~ /Add at the end of the bashrc file:

Shell Export JAVA_HOME =/home/yanzs/java/jdk1.8.0 _ 40 PATH = "$ PATH:/home/yanzs/java/jdk1.8.0 _ 40/bin"
12 Export JAVA_HOME =/home/yanzs/java/jdk1.8.0 _ 40 PATH = "$ PATH:/home/yanzs/java/jdk1.8.0 _ 40/bin"

This setting is valid for the terminal opened later. To make the existing terminal valid, Run "source ~ /. Bashrc"Command(Excluding quotation marks ). After the JAVA_HOME environment variable is set, Android Studio automatically uses this version of JDK.

Ii. Install SDK tools (32-bit and 64-bit are not differentiated) SDK tools

The development of Android applications involves access to hardware and controls used in Interface Design. These functions are provided by Android APIs and have different versions. SDK tools provides a series of tools, including SDK Manager. SDK Manager can download and upgrade Android APIs of various versions, and manage some tools, such as Platform-tools, Build-tools (with multiple versions), and even SDK tools. In addition, SDK tools provides AVM (Android device simulator) management tools. As mentioned above, Android APIs, SDK tools, Platform-tools, and Build-tools also have some other extension interfaces, collectively referred to as Android SDK. Unlike sdks of other frameworks, the Android SDK is divided into various components and needs to be downloaded through SDK Manager. All the pages and addresses for downloading the Android SDK, only SDK tools, are available. This is also the cause of great troubles for beginners. After downloading SDK tools, the SDK manager and other components downloaded through SDK manager are under the SDK tools Folder and can be copied to other development machines for sharing convenience, this is the so-called "unofficial version" or "Full version" that can be found online and "updated to the version of XXX ". Download the official SDK tools here. See the end Of the Android SDK download page,SDK Tools Only. Select the version of the corresponding operating system. Here I will download the linux version and decompress the package. For example, extract the package to the/home/yanzs/android-sdk-linux directory.

Use SDK manager to install Android APIs

Run tools/android in the SDK tools directory to open SDK manager.

Shell Yanzs @ ubuntu-64 :~ /Android-sdk-linux $ tools/android
1 Yanzs @ ubuntu-64 :~ /Android-sdk-linux $ tools/android

SDK Manager connects to the server every time it runs, obtains the latest component list, and compares the currently installed components to facilitate installation and upgrade. From can see, SDK Manager get component list error, this is probably because it uses https protocol access server, and JDK does not install the corresponding certificate, refer to http://www.java-samples.com/showtutorial.php? Tutorialid = 210. However, we will not solve the problem by installing a certificate for JDK here. We can directly set the SDK Manager so that it can use the http protocol forcibly. Use the menu "Tools/Options ..." Open the Configuration window.

Select Force https ://... Sources to be fetched using http ://...", I have set both HTTP Proxy Server and HTTP Proxy Port here. This is to set SDK Manager to download the component list through Proxy and to download the component itself. If you copy the sdk from one server to another, you have to perform these settings again.

If no proxy is set, some components cannot be loaded, such.

For more information about proxy settings, see AndroidDevTools. This website has compiled a lot of Android development tools (including all the software packages mentioned in this article) and shared them with Baidu online storage. After these settings, you can load the component list and download the component.

We can see that the Android SDK Tools has been installed. This is a matter of course, because we downloaded the SDK Tools. In addition, we can see that the SDK Manager automatically selects tools and APIs for us. We recommend installing these tools. Note that by default, SDK Manager only selects the latest Android API version. The Android Application created later uses this version of API, however, as long as you do not call the interfaces provided by the new version, you can still run them on Android phones and AVM of earlier versions. In addition to the default checked components, you can choose to install other components on the following two pages. If some components are not installed, the Hello World Program may fail to be compiled:

  • Adding SDK Packages
  • Recommended Packages

After selecting the package, click "Install XX packages" to download and Install the package. The file is large and you can watch a movie before returning.

For Android development, you can download the Android SDK and components, and configure the root path of the Android SDK in Android Studio. However, some open-source projects require you to set ANDROID_HOME environment variables, or add the SDK root directory and the tools and platform-tools subdirectories to the PATH. The settings are as follows:

Export ANDROID_HOME =/home/yanzs/android-sdk-linuxPATH = "$ PATH:/home/yanzs/android-sdk-linux" PATH = "$ PATH: /home/yanzs/android-sdk-linux/tools "PATH =" $ PATH:/home/yanzs/android-sdk-linux/platform-tools"
1234 Export ANDROID_HOME =/home/yanzs/android-sdk-linuxPATH = "$ PATH:/home/yanzs/android-sdk-linux" PATH = "$ PATH: /home/yanzs/android-sdk-linux/tools "PATH =" $ PATH:/home/yanzs/android-sdk-linux/platform-tools"

 

3. Install Android Studio (32-bit and 64-bit are not differentiated)

Android Studio can be downloaded from the Android SDK download page. The instructions show that Android Studio integrates SDK Tools and other components. The problem is that some SDK components are automatically downloaded when Android Studio runs. Before the components are successfully downloaded, you cannot enable SDK Manager to perform https and proxy settings, therefore, the component cannot be downloaded successfully... That's why we downloaded it separately.SDK Tools Only. Assume that Android Studio is decompressed to/home/yanzs/android-studio. Before running the program, you need to set it so that it can skip the aforementioned steps and cause problems.Automatically download SDK ComponentsThis step. Open the bin/idea. properties file and add a line at the end:

Disable. android. first. run = true
1 Disable. android. first. run = true

Then you can run bin/studio. sh to open Android Studio. Before creating or opening an Android project, you must configure the Android SDK path and JDK path.

Now, the development environment is complete. Then you can create Hello World.

4. Hello World!

In the "Welcome to Android Studio" window opened when you first run Android Studio, click Start a new Android Studio project to create a project. The Wizard guides you to select a template and select Blank Activity. After the creation, the system enters the Android Studio IDE, and each time Android Studio is opened, the system directly enters the IDE. The created App is a Hello World Program. Click the run button on the toolbar to start execution. If necessary components are installed, after compilation is successful, you will be asked to select an AVM or connected Android phone for testing. The process will not be detailed. If compilation fails, return the previousUse SDK manager to install Android APIsTo ensure that the required components are installed.

Android Studio uses gradle to compile the project, and gradle wrapper is used by default. That is, by default, Android Studio downloads gradle and compiles the project according to the distributionUrl specified in the gradle-wrapper.properties. However, this distributionUrl is often not connected, which causes the Android project to be unable to be compiled.

To solve this problem, Android Studio uses a local gradle, which needs to be set separately for each project. After the Android project is opened, File/Settings... /Gradle. Under Project-level settings, select Use local gradle distribution and specify a local Gradle under gradle home. Generally, Android Studio comes with a gradle, such as in android/studio/gradle/gradle-2.2.1. You can also download an updated version from the gradle official website.


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.