我刚刚创建了一个空的 Android 项目,同时包含了该项目所需的依赖项,仅在添加 com.google.firebase
或 com.google.android.gms 时才出现错误
它将生成下面的错误。
/Users/macbookair/Desktop/ANDROID/APPTEST/app/src/main/AndroidManifest.xml:22:18-91 Error: Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:5:5-21:19 to override.
请谁能帮帮我,我已经尝试了很长时间来修复这个错误。
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.fexample.android.appz"
minSdkVersion 18
targetSdkVersion 28
versionCode 2
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'org.apache.httpcomponents:httpcore:4.4.10'
implementation 'com.squareup.okhttp3:okhttp:3.13.1'
implementation 'com.facebook.android:facebook-login:4.41.0'
//If I uncomment the below line it will trigger error
//implementation 'com.google.android.gms:play-services-safetynet:17.0.0'
//implementation 'com.google.android.gms:play-services-auth:17.0.0'
//implementation 'com.google.firebase:firebase-core:17.2.0'
//implementation 'com.google.firebase:firebase-messaging:20.0.0'
}
android {
useLibrary 'org.apache.http.legacy'
}
apply plugin: 'com.google.gms.google-services'
android { sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/public'] } } }
从下面的屏幕截图来看,这个实现'com.android.support:appcompat-v7:28.0.0'
也有一个错误,但是当我构建apk时它创建成功,我不认为是很好。
Dependencies using groupId com.android.support and androidx.* can not be combined but found IdeMavenCoordinates{myGroupId='com.android.support', myArtifactId='support-fragment', myVersion='28.0.0', myPacking='aar', myClassifier='null'} and IdeMavenCoordinates{myGroupId='androidx.swiperefreshlayout', myArtifactId='swiperefreshlayout', myVersion='1.0.0', myPacking='aar', myClassifier='null'}
最佳答案
我建议您尝试以下方法之一:
1) 迁移整个项目以使用 androidx
库,您可以在菜单栏中的重构> 迁移到 AndroidX 下执行此操作。
2) 将 com.google.firebase
和 com.google.android.gms
版本从 17.x.x 降级到较低版本
关于java - Android gradle 构建失败,包含 firebase 和 gms 服务时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57987909/