使用 firestore 时找不到满足版本限制的 'com.google.code.gson:gson' 版本
Cannot find a version of 'com.google.code.gson:gson' that satisfies the version constraints when using firestore
在我的 gradle 中删除 implementation 'com.google.firebase:firebase-firestore:21.3.0'
依赖项时不会发生它,它只会导致何时不测试 运行 app。
这里是完整的错误信息
Cannot find a version of 'com.google.code.gson:gson' that satisfies the version constraints:
Dependency path 'myapp:app:unspecified' --> 'androidx.room:room-testing:2.2.1' --> 'androidx.room:room-migration:2.2.1' --> 'com.google.code.gson:gson:2.8.0'
Constraint path 'myapp:app:unspecified' --> 'com.google.code.gson:gson:{strictly 2.7}' because of the following reason: debugRuntimeClasspath uses version 2.7
Dependency path 'myapp:app:unspecified' --> 'com.google.firebase:firebase-firestore:21.3.0' --> 'io.grpc:grpc-android:1.21.0' --> 'io.grpc:grpc-core:1.21.0' --> 'com.google.code.gson:gson:2.7'
我该怎么办?
首先,您始终可以像这样检查您的依赖关系树:gradlew app:dependencies
(假设您的模块名为 app;对于 linux,您可能必须这样称呼它./gradlew app:dependencies
)
也就是说,您的日志似乎已经包含了您需要的所有内容:room 使用的是 2.8.0,firebase 使用的是 2.7。请尝试从房间 (exclude group: 'com.google.code.gson'
) 中排除 gson 传递依赖,让我们看看是否有帮助。
在我的 gradle 中删除 implementation 'com.google.firebase:firebase-firestore:21.3.0'
依赖项时不会发生它,它只会导致何时不测试 运行 app。
这里是完整的错误信息
Cannot find a version of 'com.google.code.gson:gson' that satisfies the version constraints:
Dependency path 'myapp:app:unspecified' --> 'androidx.room:room-testing:2.2.1' --> 'androidx.room:room-migration:2.2.1' --> 'com.google.code.gson:gson:2.8.0'
Constraint path 'myapp:app:unspecified' --> 'com.google.code.gson:gson:{strictly 2.7}' because of the following reason: debugRuntimeClasspath uses version 2.7
Dependency path 'myapp:app:unspecified' --> 'com.google.firebase:firebase-firestore:21.3.0' --> 'io.grpc:grpc-android:1.21.0' --> 'io.grpc:grpc-core:1.21.0' --> 'com.google.code.gson:gson:2.7'
我该怎么办?
首先,您始终可以像这样检查您的依赖关系树:gradlew app:dependencies
(假设您的模块名为 app;对于 linux,您可能必须这样称呼它./gradlew app:dependencies
)
也就是说,您的日志似乎已经包含了您需要的所有内容:room 使用的是 2.8.0,firebase 使用的是 2.7。请尝试从房间 (exclude group: 'com.google.code.gson'
) 中排除 gson 传递依赖,让我们看看是否有帮助。