命令行下创建 Android 工程,用 Ant 进行编译部署

来源:互联网 发布:从零开始学日语软件 编辑:程序博客网 时间:2024/06/05 12:02

       如果你没有使用IDE(例:Eclipse ADT、Android Studio),而是stand-alone SDK tools那么你需要使用命令行来构建android project,并且用ant或者gradle来build你的project。


环节一:开发环境搭建

             下载stand-alone SDK tools。下载地址,安装好后,cmd进入tools\,运行android.bat来启动sdk manager下载sdk 以及Android sdk tools和build tools。

              再下载ant构建工具,下载地址,接下后,浆ant所在目录配置到系统路径里,便于在cmd中使用。

环节二:开发应用程序

Create a Project with Command Line Tools


If you're not using the Eclipse IDE with the ADT plugin, you can instead create your project using the SDK tools from a command line:

  1. Change directories into the Android SDK’s tools/ path.
  2. Execute:
    android list targets

    This prints a list of the available Android platforms that you’ve downloaded for your SDK. Find the platform against which you want to compile your app. Make a note of the target id. We recommend that you select the highest version possible. You can still build your app to support older versions, but setting the build target to the latest version allows you to optimize your app for the latest devices.

    If you don't see any targets listed, you need to install some using the Android SDK Manager tool. 

  3. Execute:
    android create project --target <target-id> --name MyFirstApp \--path <path-to-workspace>/MyFirstApp --activity MainActivity \--package com.example.myfirstapp

    Replace <target-id> with an id from the list of targets (from the previous step) and replace <path-to-workspace> with the location in which you want to save your Android projects.

Your Android project is now a basic "Hello World" app that contains some default files. To run the app, continue to the next lesson.

Tip: Add the platform-tools/ as well as the tools/ directory to your PATH environment variable.


Running Your App

             

run your app from a command line:

  1. Change directories to the root of your Android project and execute:
    ant debug
  2. Make sure the Android SDK platform-tools/ directory is included in your PATH environment variable, then execute:
    adb install bin/MyFirstApp-debug.apk
  3. On your device, locate MyFirstActivity and open it.


0 0
原创粉丝点击