Gradle Warning "not specified, depends on libraries, but is a jar" when compiling the android module in the user module of the java library

I am new to Gradle. I have a simple project structure (see below) with the main Android application module, one Android module (myandroidlibrary) and one pure java module (myjavalibrary). They have simple dependencies, app โ†’ myjavalibary, myjavalibary โ†’ myandroidlibrary (see Figure below). Below are snapshots of Gradle files.

However, when synchronizing Gradle, it throws the following error:

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

Help me! I spent all this day to deal with this to no avail!

 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:

 gradle file for app module: ---------------------------- 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') } Gradle file for myjavalibrary module: ------------------------------------- apply plugin: 'java' dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':myandroidlibrary') } gradle file for myandroidlibrary module: ---------------------------- 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' } The settings.gradle: --------------------- include ':app', ':myjavalibrary', ':myandroidlibrary' 

Now when I sync 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 
+6
source share
2 answers

The warning is triggered by the pure-jave myjavalibrary myjavalibrary , which has a dependency on myandroidlibrary one, which is the Android library.

Gradle warns you that the pure-java module does not know anything about Android-specific myandroidlibrary tags (such as Android resources, assets, etc.). Having this dependency (pure-java for the android library), you may lose some of the things you expect.

A clearer direction of dependencies would be from the android library to the pure-java library. In this case, Gradle will not give you any warnings.

+6
source

If you want to create an Android application 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-created jar files, do not create any project for them. Just add them to the projects, in the libs folder, which depend on them. compile fileTree(dir: 'libs', include: ['*.jar']) in dependencies will take care of them.

0
source

Source: https://habr.com/ru/post/985630/


All Articles