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

标签 android ant teamcity

我有一个 android 项目说项目 A ..现在这个项目项目 A 依赖于一个 Android lib 项目说 LibX。现在 LibX 依赖于另一个 android 库项目 LibY。如何使用 ant 构建我的项目。

这是我引用的 android 文档 -

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

上面写着

在构建时,库一次一个地与应用程序合并,从最低优先级到最高优先级开始。 请注意,一个库本身不能引用另一个库,并且在构建时,库在与应用程序合并之前不会相互合并。

有解决办法吗?

最佳答案

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.

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. Similarly, you cannot export the library project to a self-contained JAR file, as you would do for a true library. 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. 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. 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.

Once you have added references to library projects to your Android project, you can set their relative priority. 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. ..."

我在使用 Rajawali 库(0.9 版)时遇到了类似的问题。需要分发文件。单个 jar 和应用程序将使用此 JAR 来显示 3D 屏幕。问题是我们的图书馆是使用图书馆资源 Rajawali 的定制。因此创建了两个项目结构(例如图书馆项目)。生成时。由于上述原因,使用资源的 JAR 应用程序无法运行),这是因为该库使用图像的 Rajawali 功能来加载目标应用程序版本无法识别的 ID。

单个JAR的解决方案可以通过修改代码验证不通过R.raw.X使用Rajawali资源(Android方式)去使用文件夹assets/,让组件使用Rajawali AssepManager 打开资源。解决方案是使用内部 Assets /和字节码(。类)和我们的 LIB Rajawali 导出 JAR 文件夹。

通过 Fat-JAR Eclipse 插件(或 0.0.31 +)[更新站点 http://kuruczgrafika.de/fatjar] 可以生成单个 JAR 并在目标应用程序中使用它。 ANT 脚本用于运行下面的 XML,并生成了一个 JAR 文件。/build/lib3d_NAME_HERE.jar 中将生成文件“lib3d_NAME_HERE.jar”(.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>

关于android - 使用 ant/teamcity 构建引用 android 库项目的 android 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10036216/

相关文章:

android - 如何在android中实现scrollview的动态布局中添加更多 View

java - 在 Eclipse 设置中运行现有项目

android - 用户更改从设置屏幕授予权限

eclipse - 通过Eclipse在Windows上设置Docker Toolbox

github - 如何删除 GitHub 状态检查?

android - actionNext(或任何 ImeOption)不适用于我的 Edittext,当选择此特定文本字段时,我也无法选择任何其他文本字段

ant - 如何仅在 Ant 中列出一级子目录?

java - Junit Ant 任务,输出堆栈跟踪

teamcity - 我需要包含哪些来自 Gallio 的 dll 才能让 TeamCity 运行测试

c# - 在 32 位版本的 Windows (Teamcity) 上编译 x64