英文:
Adding Firebase dependencies to Android Project with settings.gradle file
问题
我在配置我的Android Gradle项目时遇到了很大的困难。我尝试了许多在互联网上找到的解决方案,但仍然无法成功构建和运行我的项目。我尝试将Firebase库添加到我的应用程序中。
该应用程序是通过最新的Android Studio导航模板生成的。
以下是我的gradle文件:
settings.gradle
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
gradlePluginPortal()
}
}
rootProject.name = "RowingBG Achievements"
include ':app'
build.gradle (Project)
buildscript {
ext {
gradle_version = "8.0.2"
kotlin_version = '1.8.20'
gms_version = '4.3.15'
}
}
plugins {
id 'com.android.application' version "$gradle_version" apply false
id 'com.android.library' version "$gradle_version" apply false
id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false
id "com.google.gms.google-services" version "$gms_version" apply false
}
build.gradle (Module:App)
apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'com.google.gms.google-services'
android {
namespace 'com.bzahov.rowingbg'
compileSdk 33
defaultConfig {
applicationId "com.bzahov.rowingbg"
minSdk 28
targetSdk 33
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 JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation platform('com.google.firebase:firebase-bom:32.1.0')
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-core'
implementation "com.google.firebase:firebase-firestore-ktx"
implementation "com.google.firebase:firebase-database-ktx"
implementation "com.google.firebase:firebase-storage-ktx"
implementation "com.google.android.gms:play-services-auth-ktx"
...
}
我遇到了一些奇怪的错误:
未找到':app'的任何变体。请检查构建文件,确保至少存在一个变体。位置: com.android.tools.idea.gradle.project.sync.AndroidModule.prepare(GradleModules.kt:266)
解决了这个问题后,我遇到了以下问题:
找不到 com.google.firebase:firebase-core:。由以下项目所需: project :app
解决失败:com.google.android.gms:play-services-auth-ktx
添加Google Maven存储库并同步项目
受影响的模块:
F:/Projects/IntelijProjects/RowingBGAchievementsMobile/app/build.gradle 中的 app
以及
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: 无法为配置':app:debugRuntimeClasspath'解析所有文件。
当我同步项目时,我会收到这些警告,好像我的项目无法访问Google Maven存储库。
我尝试了许多不同的方法,但我对新的设置和Gradle方法了解不足。你能帮我解决这些问题,或者给我一些建议和指导吗?
如果你能帮助我解决这个问题,我将非常感激,因为我已经尝试了很长时间,但没有成功。
非常感谢您的帮助!
英文:
I have big struggles with the configuration of my Android Gradle Project. I tried a large number of solutions found on the internet, but still can't build and run my project successfully. I try to add Firebase libraries to my app.
The app was generated via the latest Android Studio Navigation Template.
Here are my gradle files:
settings.gradle
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
gradlePluginPortal()
// jcenter()
}
}
rootProject.name = "RowingBG Achievements"
include ':app'
build.gradle (Project)
buildscript {
ext {
gradle_version = "8.0.2"
kotlin_version = '1.8.20'
gms_version = '4.3.15'
}
// repositories {
// google()
// mavenCentral()
// gradlePluginPortal()
// maven { url "https://maven.google.com" }
// maven { url "https://jitpack.io" }
// }
// dependencies {
// classpath "com.android.tools.build:gradle:$gradle_version"
// classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// classpath 'com.google.dagger:hilt-android-gradle-plugin:2.41'
// classpath "com.google.gms:google-services:$gms_version"
// }
}
plugins {
id 'com.android.application' version "$gradle_version" apply false
id 'com.android.library' version "$gradle_version" apply false
id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false
id "com.google.gms.google-services" version "$gms_version" apply false
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
build.gradle (Module:App)
apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'com.google.gms.google-services'
//apply plugin: 'kotlin-android'
//apply plugin: 'kotlin-kapt'
android {
namespace 'com.bzahov.rowingbg'
compileSdk 33
defaultConfig {
applicationId "com.bzahov.rowingbg"
minSdk 28
targetSdk 33
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 JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:32.1.0')
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-core'
implementation "com.google.firebase:firebase-firestore-ktx"
implementation "com.google.firebase:firebase-database-ktx"
implementation "com.google.firebase:firebase-storage-ktx"
implementation "com.google.android.gms:play-services-auth-ktx"
...}
I got so strange errors:
> No variants found for ':app'. Check build files to ensure at least one variant exists. at:
com.android.tools.idea.gradle.project.sync.AndroidModule.prepare(GradleModules.kt:266)
After I resolved this one I got folowing one:
> Could not find com.google.firebase:firebase-core:.
Required by:
project :app
>Failed to resolve: com.google.android.gms:play-services-auth-ktx
<a href="add.google.maven.repository">Add Google Maven repository and sync project</a>
Affected Modules: <a href="openFile:F:/Projects/IntelijProjects/RowingBGAchievementsMobile/app/build.gradle">app</a>
and
> Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
when I sync project I get these warnings like my project don't access Google Maven repository
I tried a lot of different approaches but I don't have enough knowledge on new Settings. Gradle Approach. Can you help me resolve the issues or give me some advice and guidance?
I will be very grateful if you could help me to solve it because I already tried to do it alone, without success, for so much time
Thank you for your help in advance.
答案1
得分: 1
在 build.gradle(Module: App)中,您应该从 "com.google.android.gms:play-services-auth-ktx" 中移除 "-ktx":
implementation "com.google.android.gms:play-services-auth"
英文:
in build.gradle (Module:App) you should remove -ktx
from "com.google.android.gms:play-services-auth-ktx"
:
implementation "com.google.android.gms:play-services-auth"
答案2
得分: 1
引发问题的代码行是:
implementation 'com.google.firebase:firebase-core'
这个库目前也已经被弃用。除此之外,您已经移除了 kotlin-android
和 kotlin-kapt
插件。为了解决这个问题,请在您的配置文件中添加以下依赖项:
settings.gradle:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "RowingBG Achievements"
include ':app'
build.gradle (Project):
buildscript {
ext {
gradle_version = '7.4.0'
kotlin_version = '1.8.20'
google_services_version = '4.3.15'
firebase_bom_version = '32.0.0'
play_services_auth_version = '20.5.0'
}
dependencies {
classpath "com.google.gms:google-services:$google_services_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
}
}
plugins {
id 'com.android.application' version "${gradle_version}" apply false
id 'com.android.library' version "${gradle_version}" apply false
id 'org.jetbrains.kotlin.android' version "${kotlin_version}" apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (Module:App):
plugins {
id "com.android.application"
id "kotlin-android"
id "kotlin-kapt"
id "com.google.gms.google-services"
}
android {
namespace "com.bzahov.rowingbg"
compileSdk 33
defaultConfig {
applicationId "com.bzahov.rowingbg"
minSdk 21
targetSdk 33
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 JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}
dependencies {
// Firebase
implementation platform("com.google.firebase:firebase-bom:$firebase_bom_version")
implementation "com.google.firebase:firebase-analytics-ktx"
implementation "com.google.firebase:firebase-auth-ktx"
implementation "com.google.firebase:firebase-firestore-ktx"
implementation "com.google.firebase:firebase-database-ktx"
implementation "com.google.firebase:firebase-storage-ktx"
// Play Services Auth
implementation "com.google.android.gms:play-services-auth:$play_services_auth_version"
}
请注意,这些依赖项适用于实现 Firebase 产品。但是,您还需要添加相应的 Android 依赖项。
英文:
The line of code that is causing you problems is:
implementation 'com.google.firebase:firebase-core'
Which is also currently deprecated. Besides that, you have removed the kotlin-android
and kotlin-kapt
plugins. To solve this, please add the following dependencies in your configuration files:
settings.gradle:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "RowingBG Achievements"
include ':app'
build.gradle (Project):
buildscript {
ext {
gradle_version = '7.4.0'
kotlin_version = '1.8.20'
google_services_version = '4.3.15'
firebase_bom_version = '32.0.0'
play_services_auth_version = '20.5.0'
}
dependencies {
classpath "com.google.gms:google-services:$google_services_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
}
}
plugins {
id 'com.android.application' version "${gradle_version}" apply false
id 'com.android.library' version "${gradle_version}" apply false
id 'org.jetbrains.kotlin.android' version "${kotlin_version}" apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (Module:App):
plugins {
id "com.android.application"
id "kotlin-android"
id "kotlin-kapt"
id "com.google.gms.google-services"
}
android {
namespace "com.bzahov.rowingbg"
compileSdk 33
defaultConfig {
applicationId "com.bzahov.rowingbg"
minSdk 21
targetSdk 33
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 JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}
dependencies {
//Firebase
implementation platform("com.google.firebase:firebase-bom:$firebase_bom_version")
implementation "com.google.firebase:firebase-analytics-ktx"
implementation "com.google.firebase:firebase-auth-ktx"
implementation "com.google.firebase:firebase-firestore-ktx"
implementation "com.google.firebase:firebase-database-ktx"
implementation "com.google.firebase:firebase-storage-ktx"
//Play Services Auth
implementation "com.google.android.gms:play-services-auth:$play_services_auth_version"
}
Please note that these dependencies will work for implementing Firebase products. However, you also need to add the corresponding dependencies for Android.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论