Set Android development environment in Ubuntu 14.04

Source: Internet
Author: User
Tags android sdk manager

Prepare the Java environment

This article only installs the sdk and does not install any IDE, because I only need to develop it in command line mode.

First install openjdk 1.6 and then install ant.

Download SDK

Download SDK for Linux 64bit from here: http://developer.android.com/sdk/index.html? Hl = sk # download

After the download, decompress the package to the local directory, such as the/opt/directory, set the environment variables, and add three lines ~ /. Bashrc File

export ANDROID_HOME=/opt/android-sdk-linuxPATH=$PATH:/opt/android-sdk-linux/toolsPATH=$PATH:/opt/android-sdk-linux/platform-tools


Run Android SDK Manager

Run the android command. The SDK Manager dialog box is displayed, from which you can select the required package for installation.


Install a simulated Device

android avd
For more information, see the official documentation: http://developer.android.com/training/basics/firstapp/running-app.html

I created a simulated device for my moto680 instance. Finally, run the simulated device.


Create project display targets

$ android list targetsAvailable Android targets:----------id: 1 or "android-10"Name: Android 2.3.3Type: PlatformAPI level: 10Revision: 2Skins: WQVGA400, HVGA, WVGA854, QVGA, WQVGA432, WVGA800 (default)Tag/ABIs : default/armeabi----------id: 2 or "android-19"Name: Android 4.4.2     Type: Platform     API level: 19     Revision: 3     Skins: WQVGA400, HVGA, WXGA800-7in, WXGA800, WVGA854, QVGA, WQVGA432, WVGA800 (default), WSVGA, WXGA720 Tag/ABIs : default/armeabi-v7a----------id: 3 or "Google Inc.:Google APIs:10"     Name: Google APIs     Type: Add-On     Vendor: Google Inc.     Revision: 2     Description: Android + Google APIs     Based on Android 2.3.3 (API level 10)     Libraries:      * com.android.future.usb.accessory (usb.jar)          API for USB Accessories      * com.google.android.maps (maps.jar)          API for Google Maps     Skins: WVGA854, WVGA800 (default), WQVGA400, QVGA, WQVGA432, HVGA Tag/ABIs : default/armeabi----------id: 4 or "Google Inc.:Google APIs x86:19"     Name: Google APIs x86     Type: Add-On     Vendor: Google Inc.     Revision: 4     Description: Android + Google APIs x86     Based on Android 4.4.2 (API level 19)     Libraries:      * com.google.android.media.effects (effects.jar)          Collection of video effects      * com.android.future.usb.accessory (usb.jar)          API for USB Accessories      * com.google.android.maps (maps.jar)          API for Google Maps     Skins: WVGA800 (default), QVGA, WSVGA, WXGA800-7in, WQVGA400, WVGA854, WXGA720, WXGA800, WQVGA432, HVGA Tag/ABIs : default/x86


Create a project

$ android create project --target android-10 --name MyFirstApp \--path MyFirstApp --activity MainActivity --package com.example.myfirstapp> Created project directory: MyFirstAppCreated directory /home/dean/work/gitlab_cloud/android/example/MyFirstApp/src/com/example/myfirstappAdded file MyFirstApp/src/com/example/myfirstapp/MainActivity.javaCreated directory /home/dean/work/gitlab_cloud/android/example/MyFirstApp/resCreated directory /home/dean/work/gitlab_cloud/android/example/MyFirstApp/binCreated directory /home/dean/work/gitlab_cloud/android/example/MyFirstApp/libsCreated directory /home/dean/work/gitlab_cloud/android/example/MyFirstApp/res/valuesAdded file MyFirstApp/res/values/strings.xmlCreated directory /home/dean/work/gitlab_cloud/android/example/MyFirstApp/res/layoutAdded file MyFirstApp/res/layout/main.xmlAdded file MyFirstApp/AndroidManifest.xmlAdded file MyFirstApp/build.xmlAdded file MyFirstApp/proguard-project.txtdean@dean-Aspire-V7-481G:~/work/gitlab_cloud/android/example$ lsMyFirstApp  READMEdean@dean-Aspire-V7-481G:~/work/gitlab_cloud/android/example$ cd MyFirstApp/dean@dean-Aspire-V7-481G:~/work/gitlab_cloud/android/example/MyFirstApp$ lsAndroidManifest.xml  ant.properties  bin  build.xml  libs  local.properties  proguard-project.txt  project.properties  res  src

Compile

Run the following command to compile

ant debug

Deploy the program to the simulator

$ adb install bin/MyFirstApp-debug.apk97 KB/s (4858 bytes in 0.048s)pkg: /data/local/tmp/MyFirstApp-debug.apkSuccess


After running the program, you can run the program in the simulator. Run the MainActivity program to display the following text:

Hello World, MainActivity

This text is actually defined in the./res/layout/main. xml file:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    ><TextView      android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:text="Hello World, MainActivity"    /></LinearLayout>





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.