Vic Zhou Vic Zhou - 1 month ago 5x
Java Question

How to import android project as library and NOT compile it as apk (Android studio 1.0)

I tried to import a project(projLib) as dependency for another project(projAPK).

projAPK gradle has this :

dependencies {
compile project(':libs:NewsAPI')
compile project(':projLib')

but when i sync the gradle it gives this error:

Error:Dependency Android_2015:projLib:unspecified on project projAPK resolves to an APK archive which is not supported as a compilation dependency. File: /Users/myname/Documents/Development/Android_2015/libs/projAPK/build/outputs/apk/projLib-release-unsigned.apk

so I guess there are two solution to this:

  1. somehow make gradle think that projLib is a library that shouldn't be compiled to apk

  2. somehow make gradle NOT compile the projLib explicitly

The problem is, I couldn't find how to do any of that.
Would be awesome if you guys can help :)


In projLib's build.gradle file, you'll see a statement like this:

apply plugin: ''

which tells Gradle to build it as an application, generating an APK. If you change it to this:

apply plugin: ''

it will build as a library, generating an AAR, and it should work.

If you also need projLib to generate a separate APK, then you'll have to do some refactoring to pull the common code that you need out into a third library module, and have both APKs depend on it.

Libraries aren't allowed to set an applicationId, so if you see an error message to that effect, remove it from the library's build script.