How do I get Gradle for Android to find the library test code from another test code?

I have an Android application with two layers of library under it. Each library has its own test code. I would like the test code of the upper library to extend the test code of the lower library, but I cannot figure out how to get Gradle to find the test code of the lower libraries (it finds only production code).

My file structure is as follows:

myproject/ + myapp/ + src/ + main/ + java + com/myapp + lib1/ + src/ + main/ + java + com/myapp/lib1 + androidTest + java + com/myapp/lib1/test + lib2/ + src/ + main/ + java + com/myapp/lib2 + androidTest + java + com/myapp/lib2/test 

The Gradle file for the application looks like this:

 apply plugin: 'com.android.application' android { ... } dependencies { compile project(':lib2') } 

The Gradle file for lib2 looks like this:

 apply plugin: 'com.android.library' android { ... } dependencies { compile project(':lib1') } 

The Gradle file for lib1 looks like this:

 apply plugin: 'com.android.library' android { ... } 

When I run "gradle connectedCheck", I get the following:

 ... :lib2:generateDebugTestSources UP-TO-DATE :lib2:compileDebugTestJava myproject/lib2/src/androidTest/java/com/myapp/lib2/test/SubClass.java:10: error: package com.myapp.lib1.test does not exist import com.myapp.lib1.test.BaseClass; 

I tried adding various androidTestCompile lines to the dependencies section of the lib2s Gradle file, but none of them help.

Does anyone know how to make this work?

EDIT: Unfortunately, I did not mention that I also have a .gradle option in myproject folder that looks like this:

 include ':lib1' include ':lib2' include ':myapp' 
+6
source share
1 answer

The problem is that your gradle does not know the connection of the myapp, lib1 and lib2 modules.

Try adding some .gradle options to modules that use another. For your structure, I recommend making additional gradle files in the root:

e.g. in myproject /

settings.gradle:

 rootProject.name = 'myproject' include 'myapp' include 'lib1' include 'lib2' 

and then write gradle.build for all modules, where you specify the type of the whole project, for example, ear, etc.

You can also connect modules separately.

+1
source

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


All Articles