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
828
votes
31 answers

How do I add a library project to Android Studio?

How do I add a library project (such as Sherlock ABS) to Android Studio? (Not to the old ADT Eclipse-based bundle, but to the new Android Studio.)
Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
160
votes
19 answers

Adding external library in Android studio

I want to add external library https://github.com/foursquare/foursquare-android-oauth to my Android application (I use Android Studio, the instructions provided by lib author for Eclipse didn't work for Android Studio). I've tried to do it with…
Marian Paździoch
  • 8,813
  • 10
  • 58
  • 103
144
votes
6 answers

Android studio add external project to build.gradle

I have a sample project, with the following setup: /root + Pure Java Lib + Android Test Lib + Android Test Project Where the 'Test Project' is dependent on the 'Test Lib', and the last depends on the 'Pure Java Lib' Compiling the project and…
TacB0sS
  • 10,106
  • 12
  • 75
  • 118
131
votes
8 answers

Adding a library/JAR to an Eclipse Android project

This is a two-part question about adding a third-party library (JAR) to an Android project in Eclipse. The first part of the question is, when I try to add a third-party JAR (library) to my Android project I first get the problem of Error parsing…
Russ Bateman
  • 18,333
  • 14
  • 49
  • 65
119
votes
6 answers

Android Studio 1.0 and error "Library projects cannot set applicationId"

After updating Android Studio to 1.0, I see this error: Error: Library projects cannot set applicationId. applicationId is set to 'com.super.app' in default config. I updated the Gradle plugin as suggested but I did not understand how to fix this.
Seraphim's
  • 12,559
  • 20
  • 88
  • 129
113
votes
13 answers

Android - java.lang.SecurityException: Permission Denial: starting Intent

I have a library (jar) on build path of my project. The project accesses the MainActivity in the jar, using the following intent: final Intent it = new Intent(); it.setClassName("com.example.lib",…
Ramanathan
  • 1,663
  • 4
  • 17
  • 24
104
votes
7 answers

Publish an Android library to Maven with AAR and sources JAR

Can somebody give me a hint on how to use the maven-publish Gradle plugin to publish a com.android.library project/module with AAR and source jar? I am able to do this with the old maven plugin - but I would like to use the new maven-publish plugin.
ligi
  • 39,001
  • 44
  • 144
  • 244
103
votes
8 answers

Transitive dependencies not resolved for aar library using gradle

I have investigated a while and probably saw most popular answers here related to aar and transitive dependencies but somehow it is still not clear for me how to make this working. So: I have android library with given gradle config: apply plugin:…
mkorszun
  • 4,461
  • 6
  • 28
  • 43
102
votes
10 answers

How to create a release Android library package (AAR) in Android Studio (not debug)

I have built my Android library package (AAR) and the result of build is created in the "..\app\build\outputs\aar" folder. The file within this folder is called "app-debug.aar", so I guess it has been built in debug mode, so I would like to know how…
Willy
  • 9,848
  • 22
  • 141
  • 284
91
votes
18 answers

Import Android volley to Android Studio

I wanna use the google's volley library I am using Android Studio and I know how to add .jar libraries. But I could not create a .jar library with the volley files: https://android.googlesource.com/platform/frameworks/volley Here what I did:…
nsvir
  • 8,781
  • 10
  • 32
  • 47
90
votes
27 answers

Cannot resolve symbol AppCompatActivity - Support v7 libraries aren't recognized?

I'm trying to figure out why the heck my Android studio isn't recognizing the AppCompat v7 library correctly. The import statement below shows up as gray and says there's no package for support.v7.app. Below is my activity file: import…
89
votes
5 answers

Require Gradle project from another directory

I have a directory/project setup like this: C:\ _dev\ Projects\ Logger MyProject Logger is an Android library project using Gradle. MyProject is a standard Android project project that needs to make use of the…
Euan T
  • 2,041
  • 3
  • 20
  • 28
86
votes
14 answers

BuildConfig.DEBUG always false when building library projects with gradle

BuildConfig.DEBUG is not working (= logically set to false) when I run my app in debug mode. I use Gradle to build. I have a library project where I do this check. BuildConfig.java looks like this in the build debug folder: /** Automatically…
user1324936
  • 2,187
  • 4
  • 36
  • 49
85
votes
15 answers

Android Activity ClassNotFoundException - tried everything

I've just refactored an app into a framework library and an application, but now when I try and start the app in the emulator I get the following error stack trace: 06-02 18:22:35.529: E/AndroidRuntime(586): FATAL EXCEPTION: main 06-02 18:22:35.529:…
76
votes
7 answers

Is it possible to dynamically load a library at runtime from an Android application?

Is there any way to make an Android application to download and use a Java library at runtime? Here is an example: Imagine that the application needs to make some calculations depending on the input values. The application asks for these input…
llullulluis
  • 3,472
  • 3
  • 27
  • 30
1
2 3
99 100