简体   繁体   English

Android Studio的项目gradle文件改了?

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

I just updated Android Studio and started a new project.我刚刚更新了 Android Studio 并开始了一个新项目。 But now the project grade file seems different.但是现在项目成绩文件似乎有所不同。

Here are the lines:以下是这些行:

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
}

Now, for example, I need to paste the Firebase lines in the project level Gradle file.现在,例如,我需要将 Firebase 行粘贴到项目级别的 Gradle 文件中。 Where should I do it?我应该在哪里做?

Here's the Firebase code:这是 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

  }
}

In all of my previous projects, the Gradle structure was also like that.在我之前的所有项目中,Gradle 结构也是如此。 Now I'm a little confused about what to do.现在我有点困惑该怎么做。

But now the project grade file seems different.但是现在项目成绩文件似乎有所不同。

Yes, starting with the new Bumblebee update of Android Studio, the build.gradle (Project) file is changed.是的,从 Android Studio 的新Bumblebee更新开始,build.gradle(项目)文件已更改。 In order to be able to use Google Services, you have to add to your build.gradle (Project) file the following lines:为了能够使用 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
}

And inside your build.gradle (Module) file, the following plugin IDs:在您的 build.gradle(模块)文件中,有以下插件 ID:

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

In this way, your Firebase services will finally work.这样,您的 Firebase 服务最终将起作用。

PS Not 100% sure if the Firebase Assistant is updated with these new Android Studio changes. PS 不能 100% 确定Firebase 助手是否使用这些新的 Android Studio 更改进行更新。

Edit 2022-14-07 :编辑 2022-14-07

Here is a repo that uses this new structure:这是一个使用这种新结构的仓库:

Edit:编辑:

There is nothing changed regarding the way you add dependencies in the build.gradle (Module) file.在 build.gradle(模块)文件中添加依赖项的方式没有任何变化。 If for example, you want to add Firestore and Glide, please use:例如,如果您想添加 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"
}

Edit2:编辑2:

With the new updates, you don't need to worry about adding any lines under the repositories { }.有了新的更新,您无需担心在存储库 { } 下添加任何行。 That was a requirement in the previous versions.这是以前版本的要求。

Alex Mamo's solution worked fine for firebase and glide libraries without needing to add any lines under the repositories { }. Alex Mamo 的解决方案适用于 firebase 和 glide 库,无需在存储库 {} 下添加任何行。

But I was trying to add the following library and faced errors.但我试图添加以下库并遇到错误。

https://github.com/denzcoskun/ImageSlideshow https://github.com/denzcoskun/ImageSlideshow

Something like this,像这样的东西,

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

After doing some research I found out that you actually need to add lines under repositories { } in some cases.在做了一些研究之后,我发现在某些情况下,您实际上需要在存储库 { } 下添加行。 But after the new Android Studio update the gradle structure has changed.但是在新的 Android Studio 更新后,gradle 结构发生了变化。 You will need to paste the required lines in the settings.gradle file instead of project level build.gradle file.您需要将所需的行粘贴到 settings.gradle 文件而不是项目级 build.gradle 文件中。

So in settings.gradle file, I added those lines like the following...所以在 settings.gradle 文件中,我添加了如下几行...

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

and the library started working fine.图书馆开始正常工作。

I've had the same problem just add in the gradle.build project我在 gradle.build 项目中添加了同样的问题

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

and then add in gradle.build module然后添加 gradle.build 模块

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

} }

You will find your classpath from https://console.firebase.google.com/您将从https://console.firebase.google.com/找到您的类路径

You will find something like this in the firebase (if you already got your classpath then you can ignore this section)您会在 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

  }
}

just copy the classpath只需复制类路径

1)In build.gradle(project) before plugins make these changes--> 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)In build.gradle(module) add these lines in pulgins and dependencies section 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.

相关问题 在最新的 ZC31B32364CE19CA8FCD150A417ECCE5 中将 firebase json 文件添加到 gradle 项目级别面临困难 - facing difficulty to add firebase json file to gradle project level in latest android version 无法解析 Android 应用模块的 Gradle 配置 - Could not parse the Android Application Module's Gradle config 错误:无法解析 Android 应用程序模块的 Gradle 配置。 解析或重新同步(构建 gradle 应用程序中没有存储库) - Error: Could not parse the Android application Module's Gradle Config. Resolve or resync (no repositories in build gradle app) Android Studio 构建错误:Gradle - 找不到平台('com.google.firebase:firebase-bom:30.3.1') - Android Studio build error: Gradle - Could not find platform('com.google.firebase:firebase-bom:30.3.1') 无法解析 Android 应用模块的 Gradle 配置,连接到 Firebase 时 - Could not parse the Android Application Module's Gradle config ,While connecting to Firebase 进程无法访问该文件,因为它正被另一个进程使用 [Android] [Gradle] - Process cannot access the file because it is being used by another process [Android] [Gradle] 将 android 工作室的 google-service.json 更改为 firebase_option.dart 项目项目 Z5ACEBC4CB70DDBBAEZB0AC76AAB176 - Change google-service.json from android studio to firebase_option.dart on flutter project 在新的 Android Studio 项目中,我应该在哪里为 firebase 添加项目级依赖项 - Where should I add project level dependencies for firebase in new Android Studio projects 作为 Gradle Java 项目的一部分在本地运行 Dynamodb - Run Dynamodb local as part of a Gradle Java project “您试图通过调用 firebase.app() 来使用 Android 项目中未安装的 firebase 模块。” - "You attempted to use a firebase module that's not installed on your Android project by calling firebase.app()."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM