如何在Android Studio中自动添加必要的依赖项?

发布于 2025-01-11 15:46:40 字数 853 浏览 0 评论 0 原文

我正在制作一个与 Firebase 集成的 Kotlin Android Studio 项目。我将 Firebase 说明中列出的所有所需行添加到项目级别和应用级别的 build.gradle 中。

但这不包括我的项目似乎需要的任何依赖项,我在尝试构建时收到错误和这些警告:

Gradle Sync 警告

我的应用的声明的依赖项列表模块仅具有两个 Firebase 依赖项,而不具有上述警告列出的任何依赖项:

声明的依赖项

我注意到我认为所有模块中需要一些依赖项:

有没有办法将它们添加到我的应用程序模块文件夹中?我不确定它是否是这样工作的,所以请告诉我。

如果不是这样,请让我知道如何将所有这些必需的依赖项快速添加到我的项目中(最好不要手动搜索每个项目的存储库 URL 等),以便我可以同步和构建而不会出现任何错误。

I have a Kotlin Android Studio project I am making that integrates with Firebase. I added all the lines required listed in Firebase's instructions into build.gradle for both the Project level and the App level.

But this doesn't include any of the dependencies my project seems to need, I get an error when trying to build and these warnings:

Gradle Sync Warnings

The Declared Dependencies list for my app module only has the two Firebase dependencies, and not any of the dependencies as listed by the above warnings:

Declared Dependencies

I noticed there are some dependencies I assume I need in All Modules:

Is there a way I can add those into my app module folder? I am not sure if that's how it works so let me know.

If this is not the way, please let me know how I can add all these required dependencies quickly onto my Project (preferrably without manually searching each one's repository url and such) so that I can Sync and Build without any errors.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱格式化 2025-01-18 15:46:40

Gradle Sync 刚刚成功,发生了以下情况:

  • 在编辑 build.gradle 文件期间,Google Firebase 的说明是将这行代码添加到项目级别的 build.gradle< /strong> 文件:
    buildscript {
      repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository
    
      }
      dependencies {
        ...
        // Add this line
        classpath 'com.google.gms:google-services:4.3.10'
    
      }
    }
    
    allprojects {
      ...
      repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository
    
        ...
      }
    }
  • 通过 Gradle 同步文件时,发生错误,指出 settings.gradle 优先于 build.gradle,因为它还包含存储库和依赖项。修复方法是删除 settings.gradle 中的dependencyResolutionManagement代码块。

以下是我为修复所有同步警告和构建错误所做的操作:

  1. 将 settings.gradle 中找到的相同依赖项添加到项目级别的 build.gradle 中:
        gradlePluginPortal()
        google()
        mavenCentral()
  1. 它还没有工作,所以我注意到了你还需要将其添加到 allprojects 代码块下。然后它看起来像这样:
    buildscript {
      repositories {
        // Check that you have the following line (if not, add it):
        gradlePluginPortal()
        google()    // Google's Maven repository
        mavenCentral()  
    
      }
      dependencies {
        ...
        // Add this line
        classpath 'com.google.gms:google-services:4.3.10'
    
      }
    }
    
    allprojects {
      ...
      repositories {
        // Check that you have the following line (if not, add it):
        gradlePluginPortal()
        google()    // Google's Maven repository
        mavenCentral()  
    
        ...
      }
    }

仅此而已。之后,Gradle Sync 这次花了很长时间,成功完成,没有任何错误,并且 Build 工作得很好,运行得很好,符合预期。

The Gradle Sync was just now successful, here's what happened:

  • During the editing of the build.gradle files, Google Firebase's instructions were to add this line of code to the Project level's build.gradle file:
    buildscript {
      repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository
    
      }
      dependencies {
        ...
        // Add this line
        classpath 'com.google.gms:google-services:4.3.10'
    
      }
    }
    
    allprojects {
      ...
      repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository
    
        ...
      }
    }
  • When Syncing the files through Gradle, an error occurred stating that settings.gradle was prefered to build.gradle, as it also contains repositories and dependencies. The fix was to remove the dependencyResolutionManagement code block in settings.gradle.

Here's what I did to fix all the Sync Warnings and Build errors:

  1. Added the same dependencies found in settings.gradle to build.gradle in the Project level:
        gradlePluginPortal()
        google()
        mavenCentral()
  1. It did not work yet, so then I noticed you also need to add it under the allprojects code block. It will then look something like this:
    buildscript {
      repositories {
        // Check that you have the following line (if not, add it):
        gradlePluginPortal()
        google()    // Google's Maven repository
        mavenCentral()  
    
      }
      dependencies {
        ...
        // Add this line
        classpath 'com.google.gms:google-services:4.3.10'
    
      }
    }
    
    allprojects {
      ...
      repositories {
        // Check that you have the following line (if not, add it):
        gradlePluginPortal()
        google()    // Google's Maven repository
        mavenCentral()  
    
        ...
      }
    }

And that was all. After that the Gradle Sync took a long time this time and completed successfully without any errors, and the Build worked as well and ran fine as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文