繁体   English   中英

Android Studio的项目gradle文件改了?

[英]Android Studio's project gradle file changed?

我刚刚更新了 Android Studio 并开始了一个新项目。 但是现在项目成绩文件似乎有所不同。

以下是这些行:

plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
}
 
task clean(type: Delete) {
    delete rootProject.buildDir
}

现在,例如,我需要将 Firebase 行粘贴到项目级别的 Gradle 文件中。 我应该在哪里做?

这是 Firebase 代码:

buildscript {
  repositories {
    google()  // Google's Maven repository

  }
  dependencies {
    classpath 'com.google.gms:google-services:4.3.10'

  }
}

allprojects {
  repositories {
    google()  // Google's Maven repository

  }
}

在我之前的所有项目中,Gradle 结构也是如此。 现在我有点困惑该怎么做。

但是现在项目成绩文件似乎有所不同。

是的,从 Android Studio 的新Bumblebee更新开始,build.gradle(项目)文件已更改。 为了能够使用 Google 服务,您必须在 build.gradle(项目)文件中添加以下行:

plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
    id 'com.google.gms.google-services' version '4.3.0' apply false 👈
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

在您的 build.gradle(模块)文件中,有以下插件 ID:

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services' 👈
}

这样,您的 Firebase 服务最终将起作用。

PS 不能 100% 确定Firebase 助手是否使用这些新的 Android Studio 更改进行更新。

编辑 2022-14-07

这是一个使用这种新结构的仓库:

编辑:

在 build.gradle(模块)文件中添加依赖项的方式没有任何变化。 例如,如果您想添加 Firestore 和 Glide,请使用:

dependencies {
    //Regular dependecies
    implementation platform("com.google.firebase:firebase-bom:29.0.4")
    implementation "com.google.firebase:firebase-firestore"
    implementation "com.github.bumptech.glide:glide:4.12.0"
}

编辑2:

有了新的更新,您无需担心在存储库 { } 下添加任何行。 这是以前版本的要求。

Alex Mamo 的解决方案适用于 firebase 和 glide 库,无需在存储库 {} 下添加任何行。

但我试图添加以下库并遇到错误。

https://github.com/denzcoskun/ImageSlideshow

像这样的东西,

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.github.denzcoskun:ImageSlideshow:0.1.0.
Show Details
Affected Modules: app

在做了一些研究之后,我发现在某些情况下,您实际上需要在存储库 { } 下添加行。 但是在新的 Android Studio 更新后,gradle 结构发生了变化。 您需要将所需的行粘贴到 settings.gradle 文件而不是项目级 build.gradle 文件中。

所以在 settings.gradle 文件中,我添加了如下几行...

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

图书馆开始正常工作。

我在 gradle.build 项目中添加了同样的问题

id 'com.google.gms.google-services' 版本 '4.3.0' 应用 false

然后添加 gradle.build 模块

dependencies { //常规依赖实现 platform("com.google.firebase:firebase-bom:30.4.0") implementation "com.google.firebase:firebase-firestore"

}

您将从https://console.firebase.google.com/找到您的类路径

您会在 firebase 中找到类似的内容(如果您已经获得了类路径,则可以忽略此部分)

buildscript {
  repositories {
    // Make sure that you have the following two repositories
    google()  // Google's Maven repository

    mavenCentral()  // Maven Central repository

  }
  dependencies {
    ...
    // Add the dependency for the Google services Gradle plugin
    classpath 'com.google.gms:google-services:4.3.13'

  }
}

allprojects {
  ...
  repositories {
    // Make sure that you have the following two repositories
    google()  // Google's Maven repository

    mavenCentral()  // Maven Central repository

  }
}

只需复制类路径

1)在插件进行这些更改之前的 build.gradle(project) 中-->

         buildscript {

    dependencies {

        classpath 'com.google.gms:google-services:4.3.13'

    }
}

plugins {
    id 'com.android.application' version '7.2.2' apply false
    id 'com.android.library' version '7.2.2' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

2) 在 build.gradle(module) 中,在 pulgins 和依赖项部分添加这些行

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'

} 
dependencies {
implementation platform('com.google.firebase:firebase-bom:30.2.0')
implementation 'com.google.firebase:firebase-analytics'
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM