Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an apklib for a non maven project

My android application depends on an android library project which comes from a 3rd party. I am switching my build environment over to maven and following the samples has gone fairly smooth but the last step is this. I don't understand what I actually need to do. I've read the apklib page here. I've never seen a document dance around what you actually do better than this document. It contains 1 snippet of how you reference an apklib but no information at all about how you actually generate it?

Also, my project structure looks like this

/projectroot/app   (main application android project source code)
/projectroot/shared/lib1  
/projectroot/shared/lib2 (3rd party lib i don't want to create pom.xml for)

I have projectroot/pom.xml with a modules section like so:

<modules>
    <module>shared/lib1</module>
    <module>shared/lib2</module>
    <module>app</module>
</modules>

Is this the correct? In all the module examples I see they refer to folders direct children whereas mine are nested further.

Main thing I'm looking for is how to make lib2 an apklib to reference from app/pom.xml.

like image 334
Matt Wolfe Avatar asked Dec 14 '12 18:12

Matt Wolfe


1 Answers

It is mentioned in the link you referenced:

Compatible with non-Maven Android Library Projects!

The generated .apklib file will have the layout of a standard Android/Eclipse library project. This means that regardless of your Maven layout, the layout inside the .apklib file will be that source code is in "src/" instead of "src/main/java/", but still interpreted correctly when used in an Android/Maven application project. This is to be compatible with non-Maven developers' library projects, which is important to grow the Android developer community.

Use other non-Maven developers' libraries

It also means we can take any external Android library project zip file (from non-Maven developers) and do mvn install:install-file ... on it and simply start using it as a dependency.

Share your .apklib with non-Maven developers

To share your .apklib file with a non-Maven developer, they will probably feel more comfortable if you rename it to .zip. They can then simply unpack it in a directory and use it from there.

If it is a mavenized Android library project, simply run mvn clean install to create the apklib and get it installed in your local Maven repository.

If it is a regular Android library project, simply zip the project folder (better to strip all unnecessary IDE generated files), rename my-lib.zip to my-lib.apklib, then run mvn install:install-file to install my-lib.apklib into your local Maven repository.

Note that in your multi-module maven project, if the child module lib2 is not mavenized, you may get some configuration error when running maven build, it is called multi-module Maven project after all so does not make much sense to include a non-mavenized child project. If the lib2 is not mavenized yet, either mavenize it as part of the mutli-module maven project or remove it from mutli-module maven project and maintain it separately (from both command-line build via apklib and IDE development via the source).

Also note that project building in Maven and Eclipse are totally different story, if you are creating/importing the project into IDE, you need the library project source anyway. If lib2 is mavenized as part of the multi-module project, it will be imported and setup automatically when import the parent project, otherwise, you may need import and setup the standalone project manually. Check out this answer and this answer for more details.

like image 195
yorkw Avatar answered Oct 05 '22 23:10

yorkw