[英]Add custom *.jar file into build.gradle project dependencies and set up the classpath
[英]How to add classpath dependencies in build.gradle project?
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
}
现在如何在这里添加类路径依赖项?
如果您要将 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
}
只需添加dependencies
项部分/方法,如gradle 文档中所示:
dependencies{
implementation 'group.id:artifact-id:version'
}
如果依赖项在编译和运行时都应该可用,请将其声明为implementation
(对依赖项不可用)或api
(对依赖项也可用)。 有关api
和implementation
之间差异的更多详细信息,请参阅此。
如果它应该只在编译时可用,请使用compileOnly
。
同样,您可以将runtimeOnly
用于只应在运行时使用的依赖项。
如果依赖只在测试期间可用,请在它之前添加test
,例如testImplementation
。
Java 库插件上的文档提供了更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.