如何在build.gradle项目中添加类路径依赖项?

8
Gradle 更新后,每个新项目在 build.gradle 文件中都有这种格式 (project:"...")。
// Top-level build file where you can add configuration options common to all sub-projects/modules.
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
}

现在我该如何在这里添加classpath依赖项?

2个回答

10
如果你想要将 Firebase 添加到你的 Android 应用上,需要像下面这样。

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'

    }
}



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


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

0
只需按照Gradle文档中所示添加一个dependencies部分/方法即可。
dependencies{
    implementation 'group.id:artifact-id:version' 
} 

如果一个依赖项在编译和运行时都应该可用,将其声明为implementation(不可用于依赖项)或api(也可用于依赖项)。有关apiimplementation之间差异的更多详细信息,请参见this

如果它只应在编译时可用,请使用compileOnly

同样,您可以使用runtimeOnly来处理仅在运行时使用的依赖项。

如果一个依赖项只应在测试期间可用,请在其前面添加test,例如testImplementation

Java库插件文档提供了更多详细信息。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接