How to import android project as library and NOT compile it as apk?

0 votes

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 .

May 26 in Java by kartik
• 20,470 points
47 views

1 answer to this question.

0 votes

Hello,

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

apply plugin: 'com.android.application'

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

apply plugin: 'com.android.library'

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.

Hope this work!!

answered May 26 by Niroj
• 43,540 points

Related Questions In Java

+2 votes
1 answer

How to import an existing x509 certificate and private key in Java keystore to use in SSL?

keytool does not provide such basic functionality ...READ MORE

answered Dec 19, 2018 in Java by Daisy
• 8,090 points
766 views
0 votes
1 answer

“Unable to load native-hadoop library for your platform” warning: How to resolve it?

If you are running Hadoop on 64bit CentOS, ...READ MORE

answered Jan 4, 2019 in Java by Daisy
• 8,090 points
1,028 views
0 votes
1 answer

How to download Eclipse on a flash drive and use it on a public computer?

To use Eclipse from a flash drive, ...READ MORE

answered Apr 22, 2019 in Java by Omkar
• 69,040 points
1,593 views
0 votes
1 answer

Are arrays equivalent to objects in Java ?

Yes; the Java Language Specification writes: In the Java ...READ MORE

answered May 10, 2018 in Java by Rishabh
• 3,580 points
154 views
0 votes
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,280 points
158 views
0 votes
1 answer

Performance difference of if/else vs switch statement in Java

The thing you are worried about is ...READ MORE

answered Jul 26, 2018 in Java by geek.erkami
• 2,680 points
976 views
0 votes
1 answer

How to pass an object from one activity to another on Android?

Hello @kartik, Implement your class with Serializable. Let's ...READ MORE

answered Apr 8 in Java by Niroj
• 43,540 points
47 views
0 votes
1 answer

How to make JTable both AutoResize and horizontall scrollable?

Hello @kartik, If for some reason customising JTable ...READ MORE

answered Apr 21 in Java by Niroj
• 43,540 points
39 views