我想使用androidx / jetpack库(导航,constrintlayout等)使用Firebase(firestore)。但是,当在根build.gradle中添加google services插件,并在应用程序模块build.gradle中添加诸如auth和firestore之类的Firebase库时,构建会失败。
1)根项目build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.10'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0-alpha04'
classpath 'android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha07'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
(2)应用模块项目build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs'
android {
compileSdkVersion 28
defaultConfig {
applicationId "org.bitbucket.marlonlom.elcorral"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.10'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha07'
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-alpha07'
implementation 'com.google.android.material:material:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.synnapps:carouselview:0.1.5'
implementation "com.google.firebase:firebase-firestore:17.1.3"
implementation "com.google.firebase:firebase-auth:16.0.5"
implementation "com.google.firebase:firebase-core:16.0.5"
implementation "com.google.android.gms:play-services-auth:16.0.1"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
apply plugin: 'com.google.gms.google-services'
(3)根项目build.gradle
ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-api:[16.0.3].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-base:[16.0.4].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.firebase:firebase-analytics-impl:[16.2.3].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-api:[16.0.3].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-base:[16.0.4].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.firebase:firebase-analytics-impl:[16.2.3].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-api:[16.0.3].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-base:[16.0.4].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.firebase:firebase-analytics-impl:[16.2.3].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-api:[16.0.3].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-base:[16.0.4].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.firebase:firebase-analytics-impl:[16.2.3].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-api:[16.0.3].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-base:[16.0.4].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.firebase:firebase-analytics-impl:[16.2.3].
Show Details
Affected Modules: app
对此有任何帮助吗?
最诚挚的问候,
答案 0 :(得分:1)
遇到相同的问题,请尝试以前的版本。 适用于我的最新版本(截至今天)是17.1.0
https://mvnrepository.com/artifact/com.google.firebase/firebase-firestore
答案 1 :(得分:0)
首先,感谢您的评论:@ peter-haddad和@ achraf-amil
毕竟,我是通过检查我使用的库的版本来修复我之前提到的build.gradle文件的。
(1)在根 build.gradle 中:
...
dependencies{
...
classpath 'com.android.tools.build:gradle:3.4.0-alpha05'
...
//noinspection GradleDependency
classpath 'com.google.gms:google-services:4.0.2'
...
}
此外,我在此处列出了依赖项的版本。
...
ext {
kotlin_version = '1.3.10'
/* androidx related dependencies */
androidx_appcompat_version = '1.0.2'
androidx_core_ktx_version = '1.0.1'
androidx_constraintlayout_version = '2.0.0-alpha2'
androidx_legacy_support_v4_version = '1.0.0'
android_arch_navigation_fragment_ktx_version = '1.0.0-alpha07'
android_arch_navigation_ui_ktx_version = '1.0.0-alpha07'
google_material_version = '1.1.0-alpha01'
/* firebase dependencies */
firebase_firestore_version = '17.1.1'
firebase_auth_version = '16.0.4'
firebase_storage_version = '16.0.3'
firebase_core_version = '16.0.4'
play_services_auth_version = '16.0.1'
/* other dependencies */
synnapps_carouselview_version = '0.1.5'
/* Testing dependencies versions*/
junit_version = '4.12'
androidx_test_runner_version = '1.1.0'
androidx_test_espresso_core_version = '3.1.0'
}
(2)在应用程序模块 build.gradle 中,我将版本作为变量应用到依赖项块中:
...
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$rootProject.kotlin_version"
implementation "androidx.core:core-ktx:$rootProject.androidx_core_ktx_version"
implementation "androidx.constraintlayout:constraintlayout:$rootProject.androidx_constraintlayout_version"
implementation "android.arch.navigation:navigation-fragment-ktx:$rootProject.android_arch_navigation_fragment_ktx_version"
implementation "android.arch.navigation:navigation-ui-ktx:$rootProject.android_arch_navigation_ui_ktx_version"
implementation "com.google.android.material:material:$rootProject.google_material_version"
implementation "androidx.legacy:legacy-support-v4:$rootProject.androidx_legacy_support_v4_version"
implementation "com.synnapps:carouselview:$rootProject.synnapps_carouselview_version"
implementation "com.google.android.gms:play-services-auth:$rootProject.play_services_auth_version"
//noinspection GradleDependency
implementation "com.google.firebase:firebase-firestore:$rootProject.firebase_firestore_version"
//noinspection GradleDependency
implementation "com.google.firebase:firebase-auth:$rootProject.firebase_auth_version"
//noinspection GradleDependency
implementation "com.google.firebase:firebase-storage:$rootProject.firebase_storage_version"
//noinspection GradleDependency
implementation "com.google.firebase:firebase-core:$rootProject.firebase_core_version"
testImplementation "junit:junit:$rootProject.junit_version"
androidTestImplementation "androidx.test:runner:$rootProject.androidx_test_runner_version"
androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.androidx_test_espresso_core_version"
}
apply plugin: 'com.google.gms.google-services'
// noinspection GradleDependency文本部分有助于检查库的不同版本与Google Play库的版本。
如果建议这样做,则使用IDK,但目前仍有效。
此致