您的位置:首页 > 移动开发 > Android开发

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

2014-09-06 13:30 381 查看
       如果你没有使用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:
Change directories into the Android SDK’s 
tools/
 path.
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. 

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:

Change directories to the root of your Android project and execute:
ant debug


Make sure the Android SDK 
platform-tools/
 directory is included in your 
PATH
 environment variable, then execute:
adb install bin/MyFirstApp-debug.apk


On your device, locate MyFirstActivity and open it.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: