Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Warning "unspecified depends on libraries but is a jar " while compiling an android module within a custom java library module

I am a newbee in Gradle. I have a simple project structure (shown bellow) having a main android app module, one android module (myandroidlibrary), and one pure java module (myjavalibrary). They have simple dependencies, app -> myjavalibary, and myjavalibary -> myandroidlibrary (pls see fig. below). Gradle files snapshots are also given below.

However, while sync the gradle it produces following error:

 D:\MyTestCodes\MyTestApplication\app\build.gradle
 Warning:Module version MyTestApplication:myjavalibrary:unspecified depends on libraries but is a jar

Pls help me out! I have spent this whole day to sort it out with no result!

MyProject
  - app
  - myjavalibrary  (pure java library)
  - myandroidlibrary (android library)

Now the dependency is as follows:

"app" depends on -> "myjavalibrary"
"myjavalibrary" depends on -> "myandroidlibrary"

Gradle files for each of the modules are as follows:

build.gradle for app:

apply plugin: 'com.android.application'
android {
    // ommitting other detail

 dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile project(':myjavalibrary')
} 

build.gradle for myjavalibrary:

apply plugin: 'java'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':myandroidlibrary')
}

build.gradle for myandroidlibrary:

apply plugin: 'com.android.application'
android {

   //ommiting other detail.

 dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile 'com.android.support:appcompat-v7:22.0.0'
}     

settings.gradle:

include ':app', ':myjavalibrary', ':myandroidlibrary'

Now while I sync the gradle files it shows the following error:

 D:\MyTestCodes\MyTestApplication\app\build.gradle
 Warning:Module version MyTestApplication:myjavalibrary:unspecified depends on libraries but is a jar 
like image 902
Mahbubul Syeed Avatar asked Apr 21 '15 18:04

Mahbubul Syeed


2 Answers

Warning is caused by pure-jave myjavalibrary module having a dependency on the myandroidlibrary one, which is an Android library.

Gradle warns you that a pure-java module doesn't know anything about Android specific stuff of myandroidlibrary (like Android resources, assets etc.). By having this dependency (pure-java to android library one) you might lose some stuff you expect to have.

A much cleaner dependency direction would be the one from a android library to a pure-java library. In this case Gradle won't give you any warnings.

like image 136
sergej shafarenka Avatar answered Oct 29 '22 17:10

sergej shafarenka


If you want to create an Android app project from java code, use apply plugin: 'com.android.application'.

If you want to create a library project from java code, use apply plugin: 'com.android.library'.

If you want to use pre-built jar files, do not create any project for them. Just add them into the projects, into the libs folder, which depend on them. The compile fileTree(dir: 'libs', include: ['*.jar']) in the dependencies would take care of them.

like image 1
jayatubi Avatar answered Oct 29 '22 18:10

jayatubi