博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Managing Projects from the Command Line(android官网文档)
阅读量:4215 次
发布时间:2019-05-26

本文共 9042 字,大约阅读时间需要 30 分钟。

The android tool provides you with commands to create all three types of projects. An Android project contains all of the files and resources that are needed to build a project into an .apk file for installation.

  • An Android project contains all of the files and resources that are needed to build a project into an .apk file for installation. You need to create an Android project for any application that you want to eventually install on a device.
  • You can also designate an Android project as a library project, which allows it to be shared with other projects that depend on it. Once an Android project is designated as a library project, it cannot be installed onto a device.
  • Test projects extend JUnit test functionality to include Android specific functionality. For more information on creating a test project, see .

Creating an Android Project


To create an Android project, you must use the android tool. When you create a new project with android, it will generate a project directory with some default application files, stub files, configuration files and a build file.

To create a new Android project, open a command-line, navigate to the tools/ directory of your SDK and run:

android create project \--target 
\--name
\--path path/to/your/project \--activity
\--package
  • target is the "build target" for your application. It corresponds to an Android platform library (including any add-ons, such as Google APIs) that you would like to build your project against. To see a list of available targets and their corresponding IDs, execute: android list targets.
  • name is the name for your project. This is optional. If provided, this name will be used for your .apk filename when you build your application.
  • path is the location of your project directory. If the directory does not exist, it will be created for you.
  • activity is the name for your default  class. This class file will be created for you inside<path_to_your_project>/src/<your_package_namespace_path>/ . This will also be used for your .apk filename unless you provide a name.
  • package is the package namespace for your project, following the same rules as for packages in the Java programming language.

Here's an example:

android create project \--target 1 \--name MyAndroidApp \--path ./MyAndroidAppProject \--activity MyAndroidAppActivity \--package com.example.myandroid

Once you've created your project, you're ready to begin development. You can move your project folder wherever you want for development, but keep in mind that you must use the  (adb) — located in the SDK platform-tools/directory — to send your application to the emulator (discussed later). So you need access between your project solution and the platform-tools/ folder.

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

Caution: You should refrain from moving the location of the SDK directory, because this will break the SDK location property located in local.properties. If you need to update the SDK location, use the android update project command. See  for more information.

Updating a Project


If you're up grading a project from an older version of the Android SDK or want to create a new project from existing code, use the android update project command to update the project to the new development environment. You can also use this command to revise the build target of an existing project (with the --target option) and the project name (with the --name option). The android tool will generate any files and folders (listed in the previous section) that are either missing or need to be updated, as needed for the Android project.

To update an existing Android project, open a command-line and navigate to the tools/ directory of your SDK. Now run:

android update project --name 
--target
--path
  • target is the "build target" for your application. It corresponds to an Android platform library (including any add-ons, such as Google APIs) that you would like to build your project against. To see a list of available targets and their corresponding IDs, execute: android list targets.
  • path is the location of your project directory.
  • name is the name for the project. This is optional—if you're not changing the project name, you don't need this.

Here's an example:

android update project --name MyApp --target 2 --path ./MyAppProject

Setting up a Library Project


A library project is a standard Android project, so you can create a new one in the same way as you would a new application project. Specifically, you can use the android tool to generate a new library project with all of the necessary files and folders.

To create a new library project, navigate to the <sdk>/tools/ directory and use this command:

android create lib-project --name 
\--target
\--path path/to/your/project \--package

The create lib-project command creates a standard project structure that includes preset property that indicates to the build system that the project is a library. It does this by adding this line to the project's project.properties file:

android.library=true

Once the command completes, the library project is created and you can begin moving source code and resources into it, as described in the sections below.

If you want to convert an existing application project to a library project, so that other applications can use it, you can do so by adding a the android.library=true property to the application's project.properties file.

Creating the manifest file

A library project's manifest file must declare all of the shared components that it includes, just as would a standard Android application. For more information, see the documentation for .

For example, the  example library project declares the Activity GameActivity:

  ... 
    ...   
    ... 

Updating a library project

If you want to update the build properties (build target, location) of the library project, use this command:

android update lib-project \--target 
\--path path/to/your/project

Referencing a Library Project


If you are developing an application and want to include the shared code or resources from a library project, you can do so easily by adding a reference to the library project in the application project's build properties.

To add a reference to a library project, navigate to the <sdk>/tools/ directory and use this command:

android update project \--target 
\--path path/to/your/project--library path/to/library_projectA

This command updates the application project's build properties to include a reference to the library project. Specifically, it adds an android.library.reference.n property to the project's project.properties file. For example:

android.library.reference.1=path/to/library_projectA

If you are adding references to multiple libraries, note that you can set their relative priority (and merge order) by manually editing the project.properties file and adjusting the each reference's .n index as appropriate. For example, assume these references:

android.library.reference.1=path/to/library_projectAandroid.library.reference.2=path/to/library_projectBandroid.library.reference.3=path/to/library_projectC

You can reorder the references to give highest priority to library_projectC in this way:

android.library.reference.2=path/to/library_projectAandroid.library.reference.3=path/to/library_projectBandroid.library.reference.1=path/to/library_projectC

Note that the .n index in the references must begin at "1" and increase uniformly without "holes". References appearing in the index after a hole are ignored.

At build time, the libraries are merged with the application one at a time, starting from the lowest priority to the highest. Note that a library cannot itself reference another library and that, at build time, libraries are not merged with each other before being merged with the application.

Declaring library components in the manifest file

In the manifest file of the application project, you must add declarations of all components that the application will use that are imported from a library project. For example, you must declare any <activity><service><receiver><provider>, and so on, as well as <permission><uses-library>, and similar elements.

Declarations should reference the library components by their fully-qualified package names, where appropriate.

For example, the  example application declares the library Activity GameActivity like this:

  ... 
    ...   
    ... 

For more information about the manifest file, see the documentation for .

Building a dependent application

To build an application project that depends on one or more library projects, you can use the standard Gradle build commands and compile modes, as described in . The tools compile and merge all libraries referenced by the application as part of compiling the dependent application project. No additional commands or steps are necessary.

原文地址:

转载地址:http://kqsmi.baihongyu.com/

你可能感兴趣的文章
面向V2C场景的ADAS数字孪生模型构建方法
查看>>
Comma2k19数据集使用
查看>>
面向自动驾驶车辆验证的抽象仿真场景生成
查看>>
一种应用于GPS反欺骗的基于MLE的RAIM改进方法
查看>>
筑牢网络安全基座,安全护航经济数字化转型大会成功举办
查看>>
单元测试工具:单元测试的测试前置驱动条件
查看>>
汽车智不智能?“智能座舱”有话说
查看>>
自动驾驶汽车CAN总线数字孪生建模(一)
查看>>
自动驾驶汽车CAN总线数字孪生建模(二)
查看>>
自动驾驶汽车GPS系统数字孪生建模(一)
查看>>
自动驾驶汽车GPS系统数字孪生建模(二)
查看>>
上海控安入选首批工控安全防护能力贯标咨询机构名单
查看>>
自动驾驶汽车传感器数字孪生建模(一)
查看>>
CUDA 学习(四)、线程
查看>>
CUDA 学习(五)、线程块
查看>>
CUDA 学习(八)、线程块调度
查看>>
CUDA 学习(九)、CUDA 内存
查看>>
CUDA 学习(十一)、共享内存
查看>>
游戏感:虚拟感觉的游戏设计师指南——第十四章 生化尖兵
查看>>
游戏感:虚拟感觉的游戏设计师指南——第十五章 超级马里奥64
查看>>