android ubuntu下ant环境搭建

浏览:
字体:
发布时间:2013-12-22 23:48:33
来源:
假设您已经具备下列条件,否则阅读这篇文章对您帮助不会太大。


<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 命令


打开终端,敲入命令

[html]  
  1. android -h 可以列出关于该命令的帮助及其用法,其中下面命令是这篇文章的重点
    [html] 
    1. create project: Creates a new Android project update project: Updates an Android project (must already have an AndroidManifest.xml) 接下来,我们看看这两个命令的参数及其用法。打开终端,敲入命令
      [html] view plaincopyprint?
      1. android -h create project 可以看到,输出帮助信息:
        [html 
        1. Usage: android [global options] create project [action options]
        2.  
        3. Global options: -v --verbose Verbose mode: errors, warnings and informational messages are printed.
        4. -h --help Help on a specific command. -s --silent Silent mode: only errors are printed out.
        5.  
        6. Action create project: Creates a new Android project.
        7. Options: -n --name Project name
        8. -t --target Target ID of the new project [required] -p --path The new project's directory [required]
        9. -k --package Android package name for the application [required] -a --activity Name of the default Activity that is created [required] 同理,可以看看另一个命令的用法。
          [html] 
          1. Usage: android [global options] update project [action options]
          2.  
          3. Global options: -v --verbose Verbose mode: errors, warnings and informational messages are printed.
          4. -h --help Help on a specific command. -s --silent Silent mode: only errors are printed out.
          5.  
          6. Action update project: Updates an Android project (must already have an AndroidManifest.xml).
          7. Options: -p --path The project's directory [required]
          8. -l --library Directory of an Android library to add, relative to this project's directory -n --name Project name
          9. -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
            那么,在终端只需要:
            [html] 
            1. 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文件
              [html] 
              1. android:orientation=vertical android:layout_width=fill_parent
              2. android:layout_height=fill_parent >
              3. android:layout_height=wrap_content android:text=this is my ant compile android app
              4. android:textSize=20sp android:textColor=#aa000a
              5. />

                提示:执行 androidlist target 可以查看安装的sdk版本

                 

                3.编译项目

                 

                只需要两条简单命令,呵呵!
                [html] 
                1. cd /home/mark/TestAntAndroid/ ant debug 进入目录/home/mark/TestAntAndroid/bin,可以看到 ak 文件:
                  4. 安装 apk
                  将上面的 apk 文件安装到模拟器,验证是否可行。
                  [html] 
                  1. cd /home/mark/TestAntAndroid/bin
                  2. adb install TestAntAndroid-debug.apk

                    5. 更新已有工程

                     

                    如果 android 工程已经存在,可以 update project(修改平台的版本),这样会自动修改 build.xml 等 ant 的配置文件
                    [html] 
                    1. android update project -n TestAntAndroid -t 11 -p /home/mark/TestAntAndroid/

                       

                      注意: -t 11 表示使用 android-11,当然你可以使用其他版本来更新工程。但是,有时候更新一个工程不使用 android 高版本来更新的话,项目会报错。

                       

                      控制台显示信息:

                      [html] 
                      1. Updated default.properties Updated local.properties
                      2. File build.xml is too old and needs to be updated. Updated file /home/mark/TestAntAndroid/build.xml
                      3. Updated file /home/mark/TestAntAndroid/proguard.cfg
>更多相关文章
24小时热门资讯
24小时回复排行
资讯 | QQ | 安全 | 编程 | 数据库 | 系统 | 网络 | 考试 | 站长 | 关于东联 | 安全雇佣 | 搞笑视频大全 | 微信学院 | 视频课程 |
关于我们 | 联系我们 | 广告服务 | 免责申明 | 作品发布 | 网站地图 | 官方微博 | 技术培训
Copyright © 2007 - 2024 Vm888.Com. All Rights Reserved
粤公网安备 44060402001498号 粤ICP备19097316号 请遵循相关法律法规
');})();