如 here 中提到的使用 FragmentScenario 测试片段我添加了依赖项:
debugImplementation "androidx.fragment:fragment-testing:1.3.2"
但是我不能从这个库中调用任何东西,而且 android studio 不知道它们。 没有访问 EmptyFragmentActivity 或 launchFragmentInContainer 的权限。
答案 0 :(得分:0)
您需要先在 build.gradle
中定义 Google 的 Maven 存储库:
allprojects {
repositories {
google()
// If you're using a version of Gradle lower than 4.1, you must instead use:
// maven {
// url 'https://maven.google.com'
// }
// An alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
还有您提到的正确编程语言的依赖项:
dependencies {
def fragment_version = "1.3.2"
// Java language implementation
implementation "androidx.fragment:fragment:$fragment_version"
// Kotlin
implementation "androidx.fragment:fragment-ktx:$fragment_version"
// Testing Fragments in Isolation
debugImplementation "androidx.fragment:fragment-testing:$fragment_version"
}