Questions tagged [android-library]

An Android library project is a development project that holds shared Android source code and resources. Other Android application projects can reference the library project and, at build time, include its compiled sources in their .apk files.

An Android library project is a development project that holds everything needed to build an app, including source code, resource files, and an Android manifest. However, instead of compiling into an APK that runs on a device, an Android library compiles into an Android Archive (AAR) file that can be used as a dependency for an Android app module.

Android Team started revamping the whole design of Android library project since SDK r14 and is going to move from source-based mechanism to compiled-code based library mechanism, in order to support distributing Android library project as a single self-contained jar file. More details in their official blog.

A library module is useful in the following situations:

  • When you're building multiple apps that use some of the same components, such as activities, services, or UI layouts.
  • When you're building an app that exists in multiple APK variations, such as a free and paid version and you need the same core components in both.

Useful links

1883 questions
75
votes
8 answers

How to create jar for Android Library Project

I have to create a library that I am going to export to the client in a jar file. Is there any way to create a jar with the resources in it? The Google adMob have such a jar, which includes resource file such as R$layout.class in it. This page…
Aayush Rana
  • 1,303
  • 1
  • 12
  • 19
73
votes
7 answers

Could not find Library.apk!

I managed to restructure my application pretty nicely so that, except for a few methods in a derived Activity class, everything is in a Library Project. It works beautifully, except that Eclipse's Console (not LogCat!) issues the following error…
an00b
  • 11,338
  • 13
  • 64
  • 101
73
votes
21 answers

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader

Is there someone who had experience with this error? java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.swig.simple-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find…
developergg
  • 837
  • 1
  • 7
  • 12
71
votes
8 answers

How to set name of AAR output from Gradle

I have a project with several modules in it one of which is a Android Library named (poorly) as sdk. When I build the project it outputs an AAR named sdk.aar. I haven't been able to find anything in the Android or Gradle documentation that allows me…
Affian
  • 3,380
  • 5
  • 22
  • 26
71
votes
6 answers

Convert existing project to library project in Android Studio

How can I convert an existing Android project into an Android library project in Android Studio? In Eclipse, that is possible. Actually, I want to convert an old Android project into an Android library project so that I can use existing code of that…
vijay
  • 2,034
  • 3
  • 19
  • 38
70
votes
5 answers

Is it possible to get application's context in an Android Library Project?

I would like to get the context of application which has reference/hosted my library at run-time inside one class of my library project. Is it possible? If yes, how? Thanks Update I don't want my user to pass context in parameter to my library…
Haris Hasan
  • 29,856
  • 10
  • 92
  • 122
67
votes
5 answers

Can't find import module option in project structure (Android Studio 0.3.4 - 0.5.2)

I'm getting really confused and frustrated because I just can't understand how to import my android library project as dependency for my application project. I tried to find online and most of the answers suggested to go to project structure of my…
58
votes
3 answers

How to make Proguard ignore external libraries?

I want to use Proguard mainly for obfuscation reasons. My problem is that I have three libraries, Twitter4J and two signpost libraries. These libraries caused errors when I tried to create an signed APK. To get over this I put the following in the…
Mel
  • 6,214
  • 10
  • 54
  • 71
55
votes
2 answers

Does an Android Library need a manifest ,app_name,Icon?

I have an android Library that outputs an aar library. This library will be built into different projectFlavors of Mobile, TV and Wear apps. I think that each of these platforms' should be the ones that set variables like the app name, icon, and…
BillHaggerty
  • 6,157
  • 10
  • 35
  • 68
54
votes
7 answers

how to reference an asset in a library project

In a class belonging to a Library project I call: webview.loadUrl("file:///android_asset/info.html", null); Unfortunately, this only works if I duplicate the file info.html into the Application's project asset folder as well. Is there a way to tell…
an00b
  • 11,338
  • 13
  • 64
  • 101
48
votes
6 answers

REST API Client Library for Android

We are building a location based messaging app which uses Parse.com as back-end (Parse.com is similar to Urban Airship/PubNub, etc) and we now want to switch to our own back-end for better control. For this, we have built a node.js based back-end…
Madhur
  • 2,119
  • 1
  • 24
  • 31
44
votes
8 answers

Using an Android library project Activity within another project

I have an Android library project that I would like to use from within another Android project. The library has a Activity declared in its AndroidManifest. When I try the following within the second project: Intent intent = new Intent(this,…
Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
44
votes
4 answers

Using the new "manifestmerger" property in Android

In the newest version of ADT (version 20 preview 3), they say that it's possible to make the libraries' manifest file become mergeable with projects that use them: Automatic merging of library project manifest files into the including project's…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
43
votes
8 answers

Retrofit 2 example tutorial but GsonConverterFactory display error "Cannot resolve symbol"

I'm trying to follow Retrofit's 2 tutorial, but on this part of the code there is a GsonConverterFactory that displays error Cannot resolve symbol: public class ServiceGenerator { public static final String API_BASE_URL =…
StackOverflower
  • 480
  • 1
  • 4
  • 9
43
votes
9 answers

Imported module in Android Studio can't find imported class

I recently downloaded the ViewPagerIndicator library and imported it into android studio. After adding it to my project I get a rendering error "The following classes could not be found:" and points to com.viewpagerindicator.IconPageIndicator. The…
user1971
  • 698
  • 2
  • 6
  • 18