简体   繁体   中英

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. Now LibX depends on another android library project LibY. How can I build my project using ant.

Here is the android documentation I am referencing to -

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:

"... 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. ..."

I went through a similar problem when using the library Rajawali (version 0.9). There was a need to distribute a file. Single jar and applications would use this JAR to display 3D screens. The problem was that our library was a customization that used library resources 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.

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. The solution was exported JAR folder with the internal assets / and the bytecode ( . Class) and our 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. The ANT script was used to run the XML below and a JAR file was generated. The file "lib3d_NAME_HERE.jar" (.JAR) will be generated in the /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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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