Ubuntu 14.04 設定Android開發環境

來源:互聯網
上載者:User

標籤:apt-get   layout   data-   byte   linux   1.0   建立   cannot   setting   

準備Java環境

本文僅僅安裝sdk,不安裝什麼IDE,由於我僅僅須要命令列模式開發就可以。

首先安裝openjdk 1.6。然後安裝ant。這個不贅述。

下載SDK

從這裡下載SDK for Linux 64bit的版本號碼: http://developer.android.com/sdk/index.html?hl=sk#download

wget http://dl.google.com/android/android-sdk_r23.0.2-linux.tgz

下載後,解壓到本地檔案夾,比方/opt/檔案夾下, 然後環境變數設定,加入三行到~/.bashrc檔案

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


執行Android SDK Manager

執行android命令。將會彈出SDK Manager對話方塊,從中選擇須要的package進行安裝


安裝類比裝置

android avd
詳細參考官方文檔:http://developer.android.com/training/basics/firstapp/running-app.html

我建立了一個類比裝置。  最後執行該類比裝置。








建立工程顯示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


建立工程

$ 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.txt[email protected]:~/work/gitlab_cloud/android/example$ lsMyFirstApp  README[email protected]:~/work/gitlab_cloud/android/example$ cd MyFirstApp/[email protected]:~/work/gitlab_cloud/android/example/MyFirstApp$ lsAndroidManifest.xml  ant.properties  bin  build.xml  libs  local.properties  proguard-project.txt  project.properties  res  src

編譯

執行以下的命令編譯

ant debug


假設報以下錯誤:

     [aapt] /opt/android-sdk-linux/build-tools/19.0.3/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory

安裝庫:

sudo apt-get install lib32z1


部署程式到模擬器

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


執行程式好了,如今能夠在模擬器裡面執行程式了。 執行程式MainActivity。顯示以下的文字:

Hello World, MainActivity

該文字事實上是定義在./res/layout/main.xml 檔案裡:

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



定義應用程式名稱

假設想要改動Android中的應用程式名稱,不是在pom.xml中編輯,而是在src/values/strings.xml中定義,比方:

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="app_name">mvn_example1</string>    <string name="edit_message">Enter a message</string>    <string name="button_send">Send</string>    <string name="action_settings">Settings</string>    <string name="title_activity_main">MainActivity</string></resources>





Ubuntu 14.04 設定Android開發環境

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.