I have an Android application with two library layers underneath it. Each library has its own test code. I would like the upper library’s test code to extend the lower library’s test code, but I can’t figure out how to get Gradle to find the lower library’s test code (it only finds the production code).
我有一个Android应用程序,下面有两个库层。每个库都有自己的测试代码。我想上层库的测试代码扩展下层库的测试代码,但我无法弄清楚如何让Gradle找到下层库的测试代码(它只找到生产代码)。
My file structure looks like this:
我的文件结构如下所示:
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 app looks like:
该应用程序的gradle文件如下所示:
apply plugin: 'com.android.application'
android { ... }
dependencies {
compile project(':lib2')
}
The gradle file for lib2 looks like:
lib2的gradle文件如下所示:
apply plugin: 'com.android.library'
android { ... }
dependencies {
compile project(':lib1')
}
The gradle file for lib1 looks like:
lib1的gradle文件如下所示:
apply plugin: 'com.android.library'
android { ... }
When I run “gradle connectedCheck” I get this:
当我运行“gradle connectedCheck”时,我得到了这个:
...
: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 have tried adding various androidTestCompile lines to the dependencies section of lib2’s gradle file, but none of them help.
我已经尝试将各种androidTestCompile行添加到lib2的gradle文件的依赖项部分,但它们都没有帮助。
Anybody know how to make this work?
有谁知道如何使这项工作?
EDIT: Sorry, I didn't mention that I also have a settings.gradle in the myproject folder that looks like this:
编辑:对不起,我没有提到我在myproject文件夹中也有一个如下所示的settings.gradle:
include ':lib1'
include ':lib2'
include ':myapp'
1 个解决方案
#1
1
The issue is that your gradle does not know connections of myapp, lib1 and lib2 modules.
问题是你的gradle不知道myapp,lib1和lib2模块的连接。
Try to add some settings.gradle in modules that are using another one. For your structure i recommend to make additional gradle files in root:
尝试在使用另一个模块的模块中添加一些settings.gradle。对于您的结构,我建议在root中制作其他gradle文件:
for example in myproject/
例如在myproject /中
settings.gradle:
rootProject.name = 'myproject'
include 'myapp'
include 'lib1'
include 'lib2'
and then write gradle.build for all module where you clarify type of all project for example ear etc.
然后为所有模块编写gradle.build,您可以在其中阐明所有项目的类型,例如ear等。
You can also connect modules separately.
您也可以单独连接模块。
#1
1
The issue is that your gradle does not know connections of myapp, lib1 and lib2 modules.
问题是你的gradle不知道myapp,lib1和lib2模块的连接。
Try to add some settings.gradle in modules that are using another one. For your structure i recommend to make additional gradle files in root:
尝试在使用另一个模块的模块中添加一些settings.gradle。对于您的结构,我建议在root中制作其他gradle文件:
for example in myproject/
例如在myproject /中
settings.gradle:
rootProject.name = 'myproject'
include 'myapp'
include 'lib1'
include 'lib2'
and then write gradle.build for all module where you clarify type of all project for example ear etc.
然后为所有模块编写gradle.build,您可以在其中阐明所有项目的类型,例如ear等。
You can also connect modules separately.
您也可以单独连接模块。