由于未定义存储库,因此无法解析外部依赖项com.google.gms:google-services:4.2.0。
我已经尝试了Stack Overflow的许多解决方案,但没有一个我提到的对我有用的解决方案
这是我的项目级别build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:4.2.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
}
这是我的应用程序级别build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.rsolveapp"
minSdkVersion 19
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'
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:16.0.4'
implementation 'com.google.firebase:firebase-database:16.0.4'
implementation 'com.google.firebase:firebase-storage:16.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.google.firebase:firebase-analytics:17.0.1'
}
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.2.0'
}
}
程序同步后,出现错误“无法解析外部依赖项com.google.gms:google-services:4.2.0,因为未定义存储库。”
答案 0 :(得分:1)
我遇到了类似的问题,我通过添加解决了该问题,
repositories {
google()
jcenter()
}
转到 build.gradle(Module:app)文件中的 buildscript 。祝你有美好的一天
答案 1 :(得分:0)
尝试在“应用”级gradle文件中添加以下内容
repositories {
mavenCentral()
}
答案 2 :(得分:0)
在build.gradle应用程序级别添加以下代码段
repositories {
google()
jcenter()
}
例如
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.3'
}
}