Android Maven Plugin apklib Mojo does not include compiled R in the resulting apklib

I am trying to extract the Android /res folder into a separate project, which is included in my main project as an apklib dependency. The problem is that although the contents of /res included in the resulting .apklib , the compiled R.class not. Even more confusing is that the mvn clean install .apklib generates .apklib as well as a .jar file, and the jar file has R.class , but none of the contents of the /res folder. How to create a single package (either .jar or .apklib) that contains all my resources, as well as compiled classes?

pom.xml

 <packaging>apklib</packaging> ... <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <configuration> <attachSources>true</attachSources> <sdk> <platform>12</platform> </sdk> </configuration> <plugin> 

What generates the following

.jar

 ./morseflash-resources.jar com/.../R.class 

.apklib

 ./morseflash-resorces.apklib META-INF AndroidManifest.xml res/ layout/ values/ 

I would like all this content to be contained in a single file, and I would like to specify it as a dependency in my main Android project. Is this possible, and if so, how could I do it?

+5
android maven apk
source share
1 answer

This is how the Android-maven-plugin module should work in order to add a library project to a dependency of your main project, add the following dependency to your main pom.xml project:

 <dependencies> <dependency> <groupId>com.company.common.lib</groupId> <artifactId>common-lib</artifactId> <version>1.0.0-SNAPSHOT</version> <type>apklib</type> </dependency> </dependencies> 

Note that this is different from the usual jar dependencies, apklib is just the zip of all your src and res folders, which have a standard Android / Eclipse library project library structure structure ( src/com/... instead of src/main/java/com/... ). The reason for this is support for using apklib in other unmotivated projects (for more details see the ApkLib documentation ). You do not add your library as a compiled jar dependency; instead, you add your library dependency as source code and resources, simply from a zip file.

When you run mvn clean install on the target android-maven-plugin:3.0.0:generate-sources , the android-maven-plugin will unzip your apklib dependency and merge the source code and resources into your main project before compiling your project; this is how Android library projects should work. A library project is not just a compilation of everything. To save memory and disk space, only used parts are copied and compiled into the final apk. You can easily override resources in the main project, as they simply replace the library material at the merge stage until the final compilation.

This is ugly, but at the moment everything works, the Android Dev team is currently working on it and will support jar dependencies in the future, possibly in r17 (which also requires changing / updating the Android-maven-plugin)), in more detail in its official blog post " Changes to library projects in Android SDK Tools, r14 ."

+10
source share

All Articles