Ubuntu14.04设置Andriod开发环境
2014-05-19 08:48
375 查看
准备Java环境
本文只安装sdk,不安装什么IDE,因为我只需要命令行模式开发即可。首先安装openjdk 1.6,然后安装ant,这个不赘述。
下载SDK
从这里下载SDK for Linux 64bit的版本: http://developer.android.com/sdk/index.html?hl=sk#download下载后,解压到本地目录,比如/opt/目录下, 然后设置环境变量,添加三行到~/.bashrc文件
12345 | [plain] view plaincopyprint? export ANDROID_HOME=/opt/android-sdk-linux PATH=$PATH:/opt/android-sdk-linux/tools PATH=$PATH:/opt/android-sdk-linux/platform-tools |
运行Android SDK Manager
运行android命令,将会弹出SDK Manager对话框,从中选择需要的package进行安装安装模拟设备
1 2 3 | [plain] view plaincopyprint? android avd |
我为自己的moto680创建了一个模拟设备。 最后运行该模拟设备。
创建工程
显示targets
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 | [plain] view plaincopyprint? $ android list targets Available Android targets: ---------- id: 1 or "android-10" Name: Android 2.3.3 Type: Platform API level: 10 Revision: 2 Skins: 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 |
创建工程
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | [plain] view plaincopyprint? $ android create project --target android-10 --name MyFirstApp \ --path MyFirstApp --activity MainActivity --package com.example.myfirstapp > Created project directory: MyFirstApp Created directory /home/dean/work/gitlab_cloud/android/example/MyFirstApp/src/com/example/myfirstapp Added file MyFirstApp/src/com/example/myfirstapp/MainActivity.java Created directory /home/dean/work/gitlab_cloud/android/example/MyFirstApp/res Created directory /home/dean/work/gitlab_cloud/android/example/MyFirstApp/bin Created directory /home/dean/work/gitlab_cloud/android/example/MyFirstApp/libs Created directory /home/dean/work/gitlab_cloud/android/example/MyFirstApp/res/values Added file MyFirstApp/res/values/strings.xml Created directory /home/dean/work/gitlab_cloud/android/example/MyFirstApp/res/layout Added file MyFirstApp/res/layout/main.xml Added file MyFirstApp/AndroidManifest.xml Added file MyFirstApp/build.xml Added file MyFirstApp/proguard-project.txt dean@dean-Aspire-V7-481G:~/work/gitlab_cloud/android/example$ ls MyFirstApp README dean@dean-Aspire-V7-481G:~/work/gitlab_cloud/android/example$ cd MyFirstApp/ dean@dean-Aspire-V7-481G:~/work/gitlab_cloud/android/example/MyFirstApp$ ls AndroidManifest.xml ant.properties bin build.xml libs local.properties proguard-project.txt project.properties res src |
编译
运行下面的命令编译123 | [plain] view plaincopyprint? ant debug |
1 2 3 | [plain] view plaincopyprint? [aapt] /opt/android-sdk-linux/build-tools/19.0.3/aapt: error while loading shared libraries: libz.so.1: cannot open shared object |
123 | [plain] view plaincopyprint? sudo apt-get install lib32z1 |
部署程序到模拟器
1 2 3 4 5 6 | [plain] view plaincopyprint? $ adb install bin/MyFirstApp-debug.apk 97 KB/s (4858 bytes in 0.048s) pkg: /data/local/tmp/MyFirstApp-debug.apk Success |
运行程序
好了,现在可以在模拟器里面运行程序了。 运行程序MainActivity,显示下面的文字:Hello World, MainActivity
该文字其实是定义在./res/layout/main.xml 文件中:
1234567891011121314 | [html] view plaincopyprint? <?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中定义,比如:1 2 3 4 5 6 7 8 9 10 | [html] view plaincopyprint? <?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开发环境
- ubuntu14.04设置基本工作环境:搭建c 开发环境,搜狗输入法,触摸板
- Linux开发环境搭建03---Ubuntu14.04在VMware12上设置
- Ubuntu上搭建android BSP的开发编译环境 && 设置定时编译任务 && ubuntu从10.04升级到12.04后编译出错
- Windows下硬盘安装Ubuntu之三--ubuntu下android开发环境配置及常用设置
- ubuntu 14.04基础开发环境构建
- thinkpad X240 安装Ubuntu14.04 系统并搭建android开发环境
- ubuntu14.04 配置python开发环境 eric4
- ubuntu下嵌入式开发环境的设置
- ubuntu 12.04LTS下搭建Andriod开发环境记录
- Ubuntu 14.04 配置 LAMP+phpMyAdmin PHP(5.5.9)开发环境
- ubuntu下codeblocks 设置qt开发环境
- Ubuntu 14.04 配置 Android sdk 开发环境
- ubuntu12.04 || ubuntu14.04 FPGA altera 开发环境搭建 及 usb blaster配置
- Ubuntu上搭建android BSP的开发编译环境 && 设置定时编译任务
- Ubuntu 下开发 Android 环境变量设置
- Ubuntu下Gtk+开发环境的设置
- Ubuntu 14.04中搭建开发环境
- ubuntu下android开发环境配置及常用设置
- ubuntu 14.04 搭建Android开发环境