我有一个应用程序,它使用 WorkManager 执行一些计划任务,我正在一堆不同框架的帮助下对其进行测试。我正在使用 robolectric 和 androidx.work:work-testing 这似乎与这个问题有关。
我能够成功运行单元测试,但是当我尝试运行检测测试时,Calculate task graph失败了
Could not determine the dependencies of task ':myModule:mergeDebugAndroidTestResources'.
> Could not resolve all task dependencies for configuration ':myModule:debugAndroidTestRuntimeClasspath'.
> Could not resolve com.google.guava:listenablefuture:{strictly 1.0}.
Required by:
project :myModule
> Cannot find a version of 'com.google.guava:listenablefuture' that satisfies the version constraints:
Dependency path 'MyApp:myModule:unspecified' --> 'androidx.work:work-testing:2.0.1' --> 'androidx.work:work-runtime:2.0.1' --> 'com.google.guava:listenablefuture:1.0'
Constraint path 'MyApp:myModule:unspecified' --> 'com.google.guava:listenablefuture:{strictly 1.0}' because of the following reason: debugRuntimeClasspath uses version 1.0
Dependency path 'MyApp:myModule:unspecified' --> …Run Code Online (Sandbox Code Playgroud) 说我有Callbacks两个方法的接口onCurrentLocation和onError:
public interface Callbacks {
void onCurrentLocation(ClientLocation location);
void onError();
}
Run Code Online (Sandbox Code Playgroud)
还有一个在其构造函数中采用此接口的类,例如:
public MyLocationClient(Callbacks callbacks) {...}
Run Code Online (Sandbox Code Playgroud)
现在,在Kotlin中,我应该能够以这种方式实例化MyLocationClient:
val myLocationClient = MyLocationClient(
{ location: ClientLocation ->
updateClientLocation(location)
},
{})
Run Code Online (Sandbox Code Playgroud)
如果没有,为什么不呢?
我看到的行为是:当接口只有一种方法时,此对象的构造可以很好地编译。但是,一旦我向中添加了更多方法Callbacks,编译器就会抱怨
“类型不匹配。必需:回调!找到:(ClientLocation)->单位”
编辑:删除了空检查,location因为它与问题无关。