简体   繁体   English

使用 ant/teamcity 构建引用 android 库项目的 android 项目

[英]Building an android project referencing android library project using ant / teamcity

I got a android project say project A..now this project project A depends on a Android lib project say LibX.我有一个 android 项目说项目 A..现在这个项目项目 A 依赖于一个 Android lib 项目说 LibX。 Now LibX depends on another android library project LibY.现在 LibX 依赖于另一个 android 库项目 LibY。 How can I build my project using ant.如何使用 ant 构建我的项目。

Here is the android documentation I am referencing to -这是我引用的 android 文档 -

http://developer.android.com/guide/developing/projects/projects-cmdline.html http://developer.android.com/guide/developing/projects/projects-cmdline.html

Here's what it says这是它说的

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.请注意,一个库本身不能引用另一个库,并且在构建时,库在与应用程序合并之前不会相互合并。

Is there a way around this?有没有解决的办法?

by Android Developer site: source in http://developer.android.com/tools/projects/index.html , section at Library Projects:作者:Android 开发者网站:来源http://developer.android.com/tools/projects/index.html ,图书馆项目部分:

"... Structurally, a library project is similar to a standard Android application project. For example, it includes a manifest file at the project root, as well as src/, res/ and similar directories. The project can contain the same types of source code and resources as a standard Android project, stored in the same way. For example, source code in the library project can access its own resources through its R class. ”...从结构上来说,一个library项目类似于一个标准的Android应用项目,比如在项目根目录下包含一个manifest文件,还有src/、res/等类似的目录,项目可以包含相同的类型源代码和资源作为一个标准的Android项目,以同样的方式存储。例如library项目中的源代码可以通过其R class访问其自身的资源。

However, a library project differs from a standard Android application project in that you cannot compile it directly to its own.apk and run it on an Android device.但是,库项目不同于标准的 Android 应用项目,您不能将其直接编译为自己的 apk 并在 Android 设备上运行。 Similarly, you cannot export the library project to a self-contained JAR file, as you would do for a true library.同样,您不能将库项目导出到独立的 JAR 文件,就像对真正的库所做的那样。 Instead, you must compile the library indirectly, by referencing the library in the dependent application and building that application.相反,您必须通过在相关应用程序中引用该库并构建该应用程序来间接编译该库。

When you build an application that depends on a library project, the SDK tools compile the library into a temporary JAR file and uses it in the main project, then uses the result to generate the.apk.当您构建依赖于库项目的应用程序时,SDK 工具将库编译为临时 JAR 文件并在主项目中使用它,然后使用结果生成 .apk。 In cases where a resource ID is defined in both the application and the library, the tools ensure that the resource declared in the application gets priority and that the resource in the library project is not compiled into the application.apk.在应用程序和库中都定义了资源 ID 的情况下,这些工具会确保应用程序中声明的资源获得优先权,并且不会将库项目中的资源编译到 application.apk 中。 This gives your application the flexibility to either use or redefine any resource behaviors or values that are defined in any library.这使您的应用程序可以灵活地使用或重新定义在任何库中定义的任何资源行为或值。

To organize your code further, your application can add references to multiple library projects, then specify the relative priority of the resources in each library.为了进一步组织您的代码,您的应用程序可以添加对多个库项目的引用,然后指定每个库中资源的相对优先级。 This lets you build up the resources actually used in your application in a cumulative manner.这使您能够以累积的方式构建应用程序中实际使用的资源。 When two libraries referenced from an application define the same resource ID, the tools select the resource from the library with higher priority and discard the other.当应用程序引用的两个库定义相同的资源 ID 时,工具 select 优先级较高的库中的资源并丢弃另一个。

Once you have added references to library projects to your Android project, you can set their relative priority.将对库项目的引用添加到 Android 项目后,您可以设置它们的相对优先级。 At build time, the libraries are merged with the application one at a time, starting from the lowest priority to the highest.在构建时,库一次一个地与应用程序合并,从最低优先级开始到最高优先级。

Library projects can reference other library projects and can import an external library (JAR) in the normal way.库项目可以引用其他库项目,并可以正常方式导入外部库(JAR)。 ..." ……”

I went through a similar problem when using the library Rajawali (version 0.9).我在使用 Rajawali 库(0.9 版)时遇到了类似的问题。 There was a need to distribute a file.需要分发文件。 Single jar and applications would use this JAR to display 3D screens.单个 jar 和应用程序将使用此 JAR 来显示 3D 屏幕。 The problem was that our library was a customization that used library resources Rajawali.问题是我们的图书馆是使用图书馆资源 Rajawali 的定制。 So two project structures were created (such as library project).因此创建了两个项目结构(例如库项目)。 When generating.生成时。 JAR application that used the resources did not work for the reasons you explain above), this because the library uses Rajawali features of images to be loaded with IDs that were not recognized in the version of the target application. JAR 由于您上面解释的原因,使用资源的应用程序无法运行),这是因为库使用图像的 Rajawali 功能加载目标应用程序版本中无法识别的 ID。

The solution of the single JAR can be validated by modifying the code to not use the Rajawali resources via R.raw.X (Android approach) to go to use the folder assets / , and make the component use Rajawali AsseptManager to open resources.单个JAR的解决方案可以通过修改代码通过R.raw.X(Android方式)不使用Rajawali资源验证为go使用文件夹assets/ ,让组件使用Rajawali AsseptManager打开资源。 The solution was exported JAR folder with the internal assets / and the bytecode ( . Class) and our LIB Rajawali.该解决方案导出了 JAR 文件夹,其中包含内部资产/和字节码(.Class )以及我们的 LIB Rajawali。

By Fat-JAR Eclipse PlugIn (or 0.0.31 +) [update site http://kuruczgrafika.de/fatjar] could generate a single JAR and use it in the target application.通过 Fat-JAR Eclipse 插件(或 0.0.31 +)[更新站点 http://kuruczgrafika.de/fatjar] 可以生成单个 JAR 并在目标应用程序中使用它。 The ANT script was used to run the XML below and a JAR file was generated.下面使用ANT脚本运行XML,生成了一个JAR文件。 The file "lib3d_NAME_HERE.jar" (.JAR) will be generated in the /build/lib3d_NAME_HERE.jar文件“lib3d_NAME_HERE.jar”(.JAR)将在 /build/lib3d_NAME_HERE.jar 中生成

<?xml version="1.0"?>
<project name="lib3d_NAME_HERE" default="main" basedir=".">

    <property name="projectPath" value="D:\Development\lib3d_NAME_HERE"/>


    <!-- this file was created by Fat-Jar Eclipse Plug-in -->
    <!-- the ANT-Export is in a very early stage, so this -->
    <!-- is only experimental, ANT 1.6 or above is        -->
    <!-- required, feedback is always welcome:            -->
    <!--       http://sourceforge.net/projects/fjep       -->
    <!-- uncomment the following lines if using ANT outside Eclipse -->
    <!--
        <property name="fjepPath" value="reference:file:plugins/net.sf.fjep.fatjar_0.0.31/fatjar.jar"/>
        <taskdef name="fatjar.build" classname="net.sf.fjep.anttask.FJBuildTask" classpath="${fjepPath}"/>
        <typedef name="fatjar.manifest" classname="net.sf.fjep.anttask.FJManifestType" classpath="${fjepPath}"/>
        <typedef name="fatjar.exclude" classname="net.sf.fjep.anttask.FJExcludeType" classpath="${fjepPath}"/>
        <typedef name="fatjar.jarsource" classname="net.sf.fjep.anttask.FJJarSourceType" classpath="${fjepPath}"/>
        <typedef name="fatjar.filesource" classname="net.sf.fjep.anttask.FJFileSourceType" classpath="${fjepPath}"/>
    -->
    <!-- uncomment the above lines to use ANT outside of Eclipse -->
    <target name="main">
        <fatjar.build output="build/lib3d_NAME_HERE.jar">
            <fatjar.manifest/>
            <fatjar.filesource path="${projectPath}/bin/classes" relpath=""/>
            <fatjar.filesource path="${projectPath}/assets/" relpath="assets"/>
        </fatjar.build>
    </target>
</project>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM