Building an android project referencing an android library project using ant / teamcity

I got an android project, said project A .. Now this project of project A depends on the Android lib project, they say LibX. Now LibX depends on another Android library project. How can I create my project using ant.

Here is the android documentation I'm referring to -

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

That's what he says

At build time, libraries are combined with the application one at a time, starting with the lowest priority and ending with the highest. Please note: the library itself cannot refer to another library and that during the assembly the libraries do not merge with each other and then merge with the application.

Is there any way around this?

+6
source share
1 answer

on the Android developer site: source at http://developer.android.com/tools/projects/index.html , section in library projects:

"... Structurally, the library project is similar to the standard Android application project. For example, it includes the manifest file in the root project, as well as src /, res / and similar directories. The project may contain the same types of source code and resources as the standard An Android project saved in the same way, for example, the photographer code in the library project can access its own resources through its R class.

However, the library project differs from the standard Android application in that you cannot compile it directly into your own .apk and run it on your Android device. Likewise, you cannot export a project library to a standalone JAR file, just like for a true library. Instead, you should compile the library link library in the dependent application and create the application.

When you create an application that depends on the library project, the SDK Tools will compile the library into a temporary JAR file and use it in the main project, then use the result to generate the .apk. In cases where the resource identifier is defined both in the application and in the library, the tools ensure that the resource declared in the application takes priority and that the resource in the library project is not compiled into the .apk application. This gives your application the flexibility to use or override any resource behavior or values โ€‹โ€‹defined in any library.

To organize your code further, your application can add links to several library projects, then indicate the relative priority of resources in each library. This allows you to build up the resources actually used in your application in a cumulative way. When the two libraries referenced by the application identify the same resource identifier, the tools select the resource from the library with a higher priority and discard the other.

Once you have added links to library projects to your Android project, you can set their relative priority. During assembly, libraries are combined with the application one at a time, starting with the lowest priority - the highest.

Library projects can reference other library projects and can import an external library (JAR) in the usual way .... "

I encountered a similar problem when using the Rajawali library (version 0.9). It was necessary to distribute the file. A single jar and applications will use this JAR to display 3D screens. The problem was that there was a setting in our library that used Rajawali library resources. Thus, two project structures were created (for example, a library project). When generating. The JAR application that used the resources did not work for the reasons you explain above), this is because the library uses Rajawali image properties to load identifiers that were not recognized in the version of the target application.

The solution to a single JAR can be verified by changing the code to not use Rajawali resources through R.raw.X (Android approach), to use the resources of the / folder, and force the component to use the Rajawali AsseptManager to open Resources. The solution was exported to a JAR folder with internal assets / and bytecode (. Class) and our Rajawali LIB.

Fat-JAR Eclipse Plugin (or 0.0.31 +) [update the site http://kuruczgrafika.de/fatjar] can generate one JAR and use it in the target application. ANT script was used to run the XML below and a JAR file was created. The file "lib3d_NAME_HERE.jar" (.JAR) will be generated in the file / build / lib 3d_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> 
0
source

Source: https://habr.com/ru/post/912538/


All Articles