前置条件:(1)ubuntu系统,(2)在配置PATH,

具体如下:

在home目录的.bashrc文件的export PATH 前,添加下面的一行:

# add by banxi for android development PATH="$PATH:~/android/android-sdk-linux_x86/platform-tools:~/android/android-sdk-linux_x86/tools"


1.列出可用sdk (输出见附录1)


android list target


2.创建项目



~/work/cmd_dev_android$ android create project --target 6 --name MyFirstApp --path MyFirstApp --activity MainActivity --package com.banxi.appone 


对于已经存在的eclipse项目可以使用android update project 命令(具体使用见后面参考链接)来更新,便其可以在终端编译。

3.启动模拟器(有真机可以跳过)



android avd


4.在项目根目录下:(运行输出见本文附录2)


ant debug


5.安装应用到模拟器


adb install bin/MyFirstApp-debug.apk




附录(1)android list target 的输出:

banxi1988@banxi :~$ android list targetAvailable Android targets:----------id: 1 or "android-7"     Name: Android 2.1     Type: Platform     API level: 7     Revision: 3     Skins: WVGA854, WVGA800 (default), WQVGA400, WQVGA432, QVGA, HVGA     ABIs : armeabi----------id: 2 or "android-8"     Name: Android 2.2     Type: Platform     API level: 8     Revision: 3     Skins: WVGA854, WVGA800 (default), WQVGA400, WQVGA432, QVGA, HVGA     ABIs : armeabi----------id: 3 or "android-10"     Name: Android 2.3.3     Type: Platform     API level: 10     Revision: 2     Skins: WVGA854, WVGA800 (default), WQVGA400, WQVGA432, QVGA, HVGA     ABIs : armeabi----------id: 4 or "android-14"     Name: Android 4.0     Type: Platform     API level: 14     Revision: 3     Skins: WXGA720, WSVGA, WVGA854, WVGA800 (default), WQVGA400, WQVGA432, WXGA800, QVGA, HVGA     ABIs : no ABIs.----------id: 5 or "android-15"     Name: Android 4.0.3     Type: Platform     API level: 15     Revision: 3     Skins: WXGA720, WSVGA, WVGA854, WVGA800 (default), WQVGA400, WQVGA432, WXGA800, QVGA, HVGA     ABIs : armeabi-v7a----------id: 6 or "android-16"     Name: Android 4.1     Type: Platform     API level: 16     Revision: 1     Skins: WXGA720, WSVGA, WVGA854, WXGA800-7in, WVGA800 (default), WQVGA400, WQVGA432, WXGA800, QVGA, HVGA     ABIs : armeabi-v7a----------id: 7 or "Google Inc.:Google APIs:16"     Name: Google APIs     Type: Add-On     Vendor: Google Inc.     Revision: 2     Description: Android + Google APIs     Based on Android 4.1 (API level 16)     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: WQVGA400, WVGA854, WSVGA, WXGA800-7in, WXGA720, HVGA, WQVGA432, QVGA, WVGA800 (default), WXGA800     ABIs : armeabi-v7abanxi1988@banxi :~$ 


附录(2)ant debug的输出:


banxi1988@banxi :~/work/cmd_dev_android/MyFirstApp$ ant debugBuildfile: /home/banxi1988/work/cmd_dev_android/MyFirstApp/build.xml-set-mode-check:-set-debug-files:-check-env: [checkenv] Android SDK Tools Revision 20 [checkenv] Installed at /home/banxi1988/android/android-sdk-linux_x86-setup:     [echo] Project Name: MyFirstApp  [gettype] Project Type: Application     [echo] Switching between debug and non debug build: Deleting previous compilation output...-set-debug-mode:-debug-obfuscation-check:-build-setup:     [echo] Resolving Build Target for MyFirstApp...[gettarget] Project Target:   Android 4.1[gettarget] API level:        16[gettarget] WARNING: No minSdkVersion value set. Application will install on all Android versions.     [echo] ----------     [echo] Creating output directories if needed...    [mkdir] Created dir: /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/res    [mkdir] Created dir: /home/banxi1988/work/cmd_dev_android/MyFirstApp/gen    [mkdir] Created dir: /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/classes     [echo] ----------     [echo] Resolving Dependencies for MyFirstApp...[dependency] Library dependencies:[dependency] No Libraries[dependency] [dependency] ------------------[dependency] API<=15: Adding annotations.jar to the classpath.     [echo] ----------     [echo] Building Libraries with 'debug'...   [subant] No sub-builds to iterate on-pre-build:-code-gen:[mergemanifest] Merging AndroidManifest files into one.[mergemanifest] Manifest merger disabled. Using project manifest only.     [echo] Handling aidl files...     [aidl] No AIDL files to compile.     [echo] ----------     [echo] Handling RenderScript files...[renderscript] No RenderScript files to compile.     [echo] ----------     [echo] Handling Resources...     [aapt] Generating resource IDs...     [echo] ----------     [echo] Handling BuildConfig class...[buildconfig] Generating BuildConfig class.-pre-compile:-compile:    [javac] Compiling 3 source files to /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/classes-post-compile:-obfuscate:-dex:      [dex] Converting compiled files and external libraries into /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/classes.dex...-crunch:   [crunch] Crunching PNG Files in source dir: /home/banxi1988/work/cmd_dev_android/MyFirstApp/res   [crunch] To destination dir: /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/res   [crunch] Processing image to cache: /home/banxi1988/work/cmd_dev_android/MyFirstApp/res/drawable-hdpi/ic_launcher.png => /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/res/drawable-hdpi/ic_launcher.png   [crunch]   (processed image to cache entry /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/res/drawable-hdpi/ic_launcher.png: 87% size of source)   [crunch] Processing image to cache: /home/banxi1988/work/cmd_dev_android/MyFirstApp/res/drawable-ldpi/ic_launcher.png => /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/res/drawable-ldpi/ic_launcher.png   [crunch]   (processed image to cache entry /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/res/drawable-ldpi/ic_launcher.png: 0% size of source)   [crunch] Processing image to cache: /home/banxi1988/work/cmd_dev_android/MyFirstApp/res/drawable-mdpi/ic_launcher.png => /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/res/drawable-mdpi/ic_launcher.png   [crunch]   (processed image to cache entry /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/res/drawable-mdpi/ic_launcher.png: 78% size of source)   [crunch] Processing image to cache: /home/banxi1988/work/cmd_dev_android/MyFirstApp/res/drawable-xhdpi/ic_launcher.png => /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/res/drawable-xhdpi/ic_launcher.png   [crunch]   (processed image to cache entry /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/res/drawable-xhdpi/ic_launcher.png: 85% size of source)   [crunch] Crunched 4 PNG files to update cache-package-resources:     [aapt] Creating full resource package...-package:[apkbuilder] Current build type is different than previous build: forced apkbuilder run.[apkbuilder] Creating MyFirstApp-debug-unaligned.apk and signing it with a debug key...-post-package:-do-debug: [zipalign] Running zip align on final apk...     [echo] Debug Package: /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/MyFirstApp-debug.apk[propertyfile] Creating new property file: /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/build.prop[propertyfile] Updating property file: /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/build.prop[propertyfile] Updating property file: /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/build.prop[propertyfile] Updating property file: /home/banxi1988/work/cmd_dev_android/MyFirstApp/bin/build.prop-post-build:debug:BUILD SUCCESSFULTotal time: 5 seconds



从上内容参考自:

http://developer.android.com/intl/zh-CN/training/basics/firstapp/index.html



更多相关文章

  1. 上百个android小项目源码(来源于网络)
  2. eclipse导入的Android项目没有android.jar包并报错
  3. 命令运行 andorid 模拟器
  4. Android开发从入门到精通(项目案例版)——第一天(2019.11.29)
  5. Android项目从eclipse迁移到Android Studio
  6. 上百个Android开源项目分享
  7. Android 开源优秀项目
  8. Ubuntu编译Android整个系统以及编译指定模块到模拟器

随机推荐

  1. Android中获取和设置手机的壁纸
  2. android wifi 操作
  3. Android studio so库找不到问题
  4. android中listview分批加载数据
  5. Android 获取设备宽高分辨率
  6. MVP+RxJava+Dagger打造的Android(安卓)Al
  7. Android 计时器 分:秒:毫秒 http://downloa
  8. Android(安卓)UI Operation in Thread
  9. Android - HTTP util class SyncGET & Sy
  10. Android拒绝来电的实现--ITelephony类的