Assembly library project

all. I created an android library project and it works great when I link to it from the main project. But when I create the library project separately, it doesn't contain R.java and resources. Is there a way to create a library project with resources and R.java?

+3


source to share


2 answers


This is no longer possible.

Now we can create a binary-only library project by following these steps:

  • Create an android library project, with your source code etc. this is your master project from which you will build a version of the library project to distribute
  • Compile your Java source (like ant compile) and turn it into a JAR file
  • Create an Android to Android library project, with the same resources as the main library project, but the source code
  • Place the JAR file in the Android libs project distribution / directory The resulting Android library distribution will have everything the main project needs without the source code.


This solution has some limitations:

  • We still need to send resources.
  • We must rewrite our code to avoid using R values ​​as they will be wrong. We'll have to search for all resource IDs using getResources (). getIdentifier () and / or reflection.
+5


source


I use Eclipse and never build my Android library project myself myself, but I think the development considerations outlined in the official dev guide here should answer your question:

Each library project creates its own R class

When you create a dependent application project, the library projects are compiled and merged with the application project. Each library has its own R class, named after the library package name. The R class generated from the main project and the library project are generated in all packages that are needed, including the main project package and library packages.



Update with another note given in the official dev giude Library projects :

However, the library project differs from the standard Android application project in that you cannot compile it directly into your own .apk and run it on an Android device. Likewise, you cannot export a library project to a standalone JAR file like you can for a true library. Instead, you must compile the library indirectly by referencing the library in the dependent application and building that application.

+5


source







All Articles