Android Is it possible to create a custom library for use in multiple applications?

Is it possible to create a custom library on Android (having its own layout resources) for use in several Android applications?

  • I created a regular * .jar file, but when I tried to dynamically create / style my views, most of the properties did not work. Even links to simple styles from the android.jar file, such as android.attr.listSeparatorTextViewStyle, did not work.

  • I created an Android project without any action, having my own resource files, and then referenced this project from another Android project for use in its build path. Everything seems to be working fine, but the emulator continues to crash (without a meaningful error message in LogCat ) when I try to start the project.

Did I miss something?

+20
android
Dec 01 '09 at 19:51
source share
4 answers

Well, I think there is a way to do this (although I have not tried it myself), but for users of your library you need to create your aapt manually through aapt .

The problem is this: The JAR you are exporting contains a class R file that contains the resource identifiers of your library. This way, any application can access these identifiers simply by linking your JAR. However, this is not enough, because by default only resources in the app folder / folder are associated with the APK. Therefore, you need to create the APK yourself using aapt, telling it to also include any resources from your library. For more information, see the aapt tool help.

Since this means that your library users must enter the manual build process (or at least change it), this leads to poor results.

+13
Dec 02 '09 at 9:46
source share

You may be late to answer, but it is interesting. Library project setup

An Android library project is a development project that has source code and Android resources. Other Android application projects may reference the library project and build time, include its compiled sources in their .apk files. multiple applications can reference the same library project, and any application project can reference multiple library projects.

If you have source code and resources that are common to multiple applications, you can move them into the library project to make it easier to support applications and versions. Here are some common scenarios where you can use library projects:

+17
Feb 04 2018-11-11T00:
source share

Is it possible to create a custom library in android (having its own layout resources) for use through several Android applications?

No. JARs cannot have resources. You can share the code this way, but the resources must be in applications that reuse the JAR.

Even links to simple styles from an android.jar file such as android.attr.listSeparatorTextViewStyle do not work.

Make sure you link the JAR with android.jar. You can see many examples of this in the CWAC components on my github page.

+5
Dec 02 '09 at 5:08
source share

Is this still true with R21? I can export the library project to a jar file and be successfully used in other client projects, both with wise code and with access to resource files.

still http://developer.android.com/tools/projects/index.html still has the following statement, which is no longer true:

You cannot export a library project to a JAR file. A library cannot be distributed as a binary file (for example, a JAR file). This will be added in a future version of the SDK Tools.

0
May 03 '13 at 18:39
source share



All Articles