AndroidStudio如何自动添加必要的依赖?
How to automatically add the necessary dependencies in Android Studio?
我有一个与 Firebase 集成的 Kotlin Android Studio 项目。我将 Firebase 说明中列出的所有必需行添加到项目级别和应用程序级别的 build.gradle 中。
但这不包括我的项目似乎需要的任何依赖项,我在尝试构建时遇到错误并收到这些警告:
我的应用程序模块的 声明的依赖项 列表只有两个 Firebase 依赖项,没有上述警告列出的任何依赖项:
我注意到在 所有模块:
中有一些我认为需要的依赖项
有没有办法将它们添加到我的应用程序模块文件夹中?我不确定这是否有效,所以请告诉我。
如果不是这样,请告诉我如何将所有这些必需的依赖项快速添加到我的项目中(最好不要手动搜索每个人的存储库 url 等)以便我可以同步和构建没有任何错误。
Gradle 同步刚刚成功,这是发生的事情:
- 在 build.gradle 文件的编辑过程中,Google Firebase 的说明是将这行代码添加到项目级别的 build.gradle 文件:
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,因为它还包含存储库和依赖项。解决方法是删除 dependencyResolutionManagement 代码块 settings.gradle.
这是我修复所有同步警告和构建错误所做的工作:
- 将在 settings.gradle 中找到的相同依赖项添加到项目级别的 build.gradle:
gradlePluginPortal()
google()
mavenCentral()
- 它还没有工作,所以我注意到你还需要将它添加到 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 这次花了很长时间并成功完成,没有任何错误,并且构建工作正常并且 运行 符合预期。
我有一个与 Firebase 集成的 Kotlin Android Studio 项目。我将 Firebase 说明中列出的所有必需行添加到项目级别和应用程序级别的 build.gradle 中。
但这不包括我的项目似乎需要的任何依赖项,我在尝试构建时遇到错误并收到这些警告:
我的应用程序模块的 声明的依赖项 列表只有两个 Firebase 依赖项,没有上述警告列出的任何依赖项:
我注意到在 所有模块:
中有一些我认为需要的依赖项有没有办法将它们添加到我的应用程序模块文件夹中?我不确定这是否有效,所以请告诉我。
如果不是这样,请告诉我如何将所有这些必需的依赖项快速添加到我的项目中(最好不要手动搜索每个人的存储库 url 等)以便我可以同步和构建没有任何错误。
Gradle 同步刚刚成功,这是发生的事情:
- 在 build.gradle 文件的编辑过程中,Google Firebase 的说明是将这行代码添加到项目级别的 build.gradle 文件:
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,因为它还包含存储库和依赖项。解决方法是删除 dependencyResolutionManagement 代码块 settings.gradle.
这是我修复所有同步警告和构建错误所做的工作:
- 将在 settings.gradle 中找到的相同依赖项添加到项目级别的 build.gradle:
gradlePluginPortal()
google()
mavenCentral()
- 它还没有工作,所以我注意到你还需要将它添加到 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 这次花了很长时间并成功完成,没有任何错误,并且构建工作正常并且 运行 符合预期。