如需将其中某个库添加到您的 build 中,请在顶级 build.gradle.kts 文件中包含 Google 的 Maven 代码库:
Kotlin
dependencyResolutionManagement{repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories{google()// If you're using a version of Gradle lower than 4.1, you must instead use:// maven {// url = "https://maven.google.com"// }// An alternative URL is "https://dl.google.com/dl/android/maven2/".}}
Groovy
dependencyResolutionManagement{repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories{google()// If you're using a version of Gradle lower than 4.1, you must instead use:// maven {// url 'https://maven.google.com'// }// An alternative URL is 'https://dl.google.com/dl/android/maven2/'.}}
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-21。"],[],[],null,["When your dependency is something other than a local library or file tree,\nGradle looks for the files in whichever online repositories are specified in the\n`dependencyResolutionManagement { repositories {...} }` block of your\n`settings.gradle` file. The order in which you list each repository determines\nthe order in which Gradle searches the repositories for each project dependency.\nFor example, if a dependency is available from both repository A and B, and you\nlist A first, Gradle downloads the dependency from repository A.\n\nBy default, new Android Studio projects specify [Google's Maven repository](#google-maven), and the\n[Maven central repository](https://search.maven.org/) as\nrepository locations in the project's `settings.gradle` file, as shown below: \n\nKotlin \n\n```kotlin\ndependencyResolutionManagement {\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n google()\n mavenCentral()\n }\n}\n```\n\nGroovy \n\n```groovy\ndependencyResolutionManagement {\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n google()\n mavenCentral()\n }\n}\n```\n| **Warning:** The JCenter repository, which was included by default in the past, became read-only on March 31st, 2021. For more information, see [JCenter service\n| update](/studio/build/jcenter-migration).\n\nIf you want something from a local repository use `mavenLocal()`: \n\nKotlin \n\n```kotlin\ndependencyResolutionManagement {\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n google()\n mavenCentral()\n mavenLocal()\n }\n}\n```\n\nGroovy \n\n```groovy\ndependencyResolutionManagement {\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n google()\n mavenCentral()\n mavenLocal()\n }\n}\n```\n\nOr you can declare specific Maven or Ivy repositories as follows: \n\nKotlin \n\n```kotlin\ndependencyResolutionManagement {\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n maven(url = \"https://repo.example.com/maven2\")\n maven(url = \"file://local/repo/\")\n ivy(url = \"https://repo.example.com/ivy\")\n }\n}\n```\n\nGroovy \n\n```groovy\ndependencyResolutionManagement {\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n maven {\n url 'https://repo.example.com/maven2'\n }\n maven {\n url 'file://local/repo/'\n }\n ivy {\n url 'https://repo.example.com/ivy'\n }\n }\n}\n```\n\nFor more information, see the\n[Gradle Repositories guide](https://docs.gradle.org/current/userguide/dependency_management.html#sec:repositories).\n\nGoogle's Maven repository\n\nThe most recent versions of the following Android libraries are available from\nGoogle's Maven repository:\n\n- [AndroidX Libraries](/jetpack/androidx)\n- [Architecture Components Library](/topic/libraries/architecture)\n- [Constraint Layout Library](/training/constraint-layout)\n- [AndroidX Test](/training/testing)\n- [Databinding Library](/topic/libraries/data-binding)\n- [Android Instant App Library](/topic/instant-apps)\n- [Wear OS](/training/building-wearables)\n- [Google Play services](https://developers.google.com/android/guides/setup)\n- [Google Play Billing Library](/google/play/billing)\n- [Firebase](https://firebase.google.com/docs/android/setup)\n\nYou can see all available artifacts at\n[Google's Maven repository index](https://maven.google.com)\n(see below for [programmatic access](#gmaven-access)).\n\nTo add one of these libraries to your build, include Google's Maven repository\nin your top-level `build.gradle.kts` file: \n\nKotlin \n\n```kotlin\ndependencyResolutionManagement {\n\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n google()\n\n // If you're using a version of Gradle lower than 4.1, you must instead use:\n // maven {\n // url = \"https://maven.google.com\"\n // }\n // An alternative URL is \"https://dl.google.com/dl/android/maven2/\".\n }\n}\n```\n\nGroovy \n\n```groovy\ndependencyResolutionManagement {\n\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n google()\n\n // If you're using a version of Gradle lower than 4.1, you must instead use:\n // maven {\n // url 'https://maven.google.com'\n // }\n // An alternative URL is 'https://dl.google.com/dl/android/maven2/'.\n }\n}\n```\n\nThen add the desired library to your module's `dependencies` block.\nFor example,the [appcompat library](/jetpack/androidx/releases/appcompat)\nlooks like this: \n\nKotlin \n\n```kotlin\ndependencies {\n implementation(\"com.android.support:appcompat-v7:28.0.0\")\n}\n```\n\nGroovy \n\n```groovy\ndependencies {\n implementation 'androidx.appcompat:appcompat:1.7.0'\n}\n```\n\nHowever, if you're trying to use an older version of the above\nlibraries and your dependency fails, then it's not available in the Maven\nrepository and you must instead get the library from the offline repository.\n\nProgrammatic access\n\nFor programmatic access to Google's Maven artifacts, you can get\nan XML list of artifact groups from [maven.google.com/master-index.xml](https://maven.google.com/master-index.xml).\nThen, for any group, you can view its library names and versions at:\n\n*maven.google.com/\u003cvar translate=\"no\"\u003egroup_path\u003c/var\u003e/group-index.xml*\n\nFor example, libraries in the android.arch.lifecycle group are listed at\n[maven.google.com/android/arch/lifecycle/group-index.xml](https://maven.google.com/android/arch/lifecycle/group-index.xml).\n\nYou can also download the POM and JAR files at:\n\n*maven.google.com/\u003cvar translate=\"no\"\u003egroup_path\u003c/var\u003e/\u003cvar translate=\"no\"\u003elibrary\u003c/var\u003e/\u003cvar translate=\"no\"\u003eversion\u003c/var\u003e\n/\u003cvar translate=\"no\"\u003elibrary\u003c/var\u003e-\u003cvar translate=\"no\"\u003eversion\u003c/var\u003e.\u003cvar translate=\"no\"\u003eext\u003c/var\u003e*\n\nFor example: [maven.google.com/android/arch/lifecycle/compiler/1.0.0/compiler-1.\n0.0.pom](https://maven.google.com/android/arch/lifecycle/compiler/1.0.0/compiler-1.0.0.pom).\n\nOffline repository from SDK Manager\n\nFor libraries not available from the Google Maven repository (usually older\nlibrary versions), you must download the offline **Google Repository** package\nfrom the [SDK Manager](/studio/intro/update#sdk-manager).\n\nThen you can add these libraries to your `dependencies` block as usual.\n\nThe offline libraries are saved in\n\u003cvar translate=\"no\"\u003eandroid_sdk\u003c/var\u003e`/extras/`."]]