利器ant(1):ant 入門

來源:互聯網
上載者:User

看這篇文章之前,假設您已經具備下列條件,否則閱讀這篇文章對您協助不會太大。
<1> ubuntu下,成功安裝JDK1.6並配置環境變數
<2> ubuntu下,成功下載、配置好ant環境
<3> ubuntu下,成功安裝android-sdk,並且配置好tools、platform-tools環境變數
好吧,開始ant開發android之旅!/home/mark/android/android-sdk-linux_x86是android_sdk安裝路徑。

1.android 命令
開啟終端,敲入命令

android -h 
可以列出關於該命令的協助及其用法,其中下面命令是這篇文章的重點

create project: Creates a new Android project 
update project: Updates an Android project (must already have an AndroidManifest.xml) 
接下來,我們看看這兩個命令的參數及其用法。開啟終端,敲入命令

android -h create project 
可以看到,輸出協助資訊:

Usage: 
  android [global options] create project [action options] 
 
 
Global options: 
  -v --verbose  Verbose mode: errors, warnings and informational messages are printed. 
  -h --help     Help on a specific command. 
  -s --silent   Silent mode: only errors are printed out. 
 
 
Action "create project": 
  Creates a new Android project. 
Options: 
  -n --name     Project name 
  -t --target   Target ID of the new project [required] 
  -p --path     The new project's directory [required] 
  -k --package  Android package name for the application [required] 
  -a --activity Name of the default Activity that is created [required] 
同理,可以看看另一個命令的用法。

Usage: 
  android [global options] update project [action options] 
 
 
Global options: 
  -v --verbose  Verbose mode: errors, warnings and informational messages are printed. 
  -h --help     Help on a specific command. 
  -s --silent   Silent mode: only errors are printed out. 
 
 
Action "update project": 
  Updates an Android project (must already have an AndroidManifest.xml). 
Options: 
  -p --path        The project's directory [required] 
  -l --library     Directory of an Android library to add, relative to this project's directory 
  -n --name        Project name 
  -t --target      Target ID to set for the project 
  -s --subprojects Also updates any projects in sub-folders, such as test projects. 
2. 建立項目
在/home/mark路徑下,建立android項目,詳情如下:
工程名稱        :TestAntAndroidActivity
名稱                :TestActivity
包名稱            :mark.zhangandroid  版本    :4,即 android1.5
那麼,在終端只需要:

android create project -k mark.zhang -n TestAntAndroid -a TestActivity -t 4 -p /home/mark/TestAntAndroid 
ok,在/home/mark/下面就會建立TestAntAndroid工程目錄,其結構如下,與使用Eclipse/ADT建立項目是一樣的效果。
修改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="this is my ant compile android app" 
    android:textSize="20sp" 
    android:textColor="#aa000a" 
    /> 
</LinearLayout> 
提示:執行 androidlist target 可以查看安裝的sdk版本
3.編譯項目
只需要兩條簡單命令,呵呵!

cd /home/mark/TestAntAndroid/ 
ant debug 
進入目錄/home/mark/TestAntAndroid/bin,可以看到 ak 檔案:
4. 安裝 apk
將上面的 apk 檔案安裝到模擬器,驗證是否可行。

cd /home/mark/TestAntAndroid/bin 
 
 
adb install TestAntAndroid-debug.apk 
5. 更新已有工程
如果 android 工程已經存在,可以 update project(修改平台的版本),這樣會自動修改 build.xml 等 ant 的設定檔

android update project -n TestAntAndroid -t 11 -p /home/mark/TestAntAndroid/ 
控制台顯示資訊:

Updated default.properties 
Updated local.properties 
File build.xml is too old and needs to be updated. 
Updated file /home/mark/TestAntAndroid/build.xml 
Updated file /home/mark/TestAntAndroid/proguard.cfg 

作者:AndroidBluetooth

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.