android - 如何将 Android 支持存储库添加到 Android Studio?

标签 android gradle android-studio android-support-library android-gradle-plugin

我正在使用带有外部 Android SDK 的 Android Studio。我已经安装了支持库和支持存储库。支持存储库位于:

~/Development/Tools/android/sdk/extras/android/m2repository

当我在 build.gradle 文件中向支持库添加依赖项时,例如:

...

repositories {
    mavenCentral()
}

...

dependencies {
   compile "com.android.support:support-v4:18.0.+"
}

Android Studio 找不到支持库(无法解析符号等),Gradle 也找不到这些库:

Gradle: A problem occurred configuring project ':TestAndroidStudio'.
> Failed to notify project evaluation listener.
   > Could not resolve all dependencies for configuration ':TestAndroidStudio:_DebugCompile'.
      > Could not find any version that matches com.android.support:support-v4:18.0.+.
        Required by:
            TestAndroidStudio:TestAndroidStudio:unspecified

如何在 Android Studio 和/或 build.gradle 文件中指定 Android 支持存储库的位置?

最佳答案

你可能被 this bug 击中了这会阻止 Android Gradle 插件自动将“Android 支持存储库”添加到 Gradle 存储库列表中。如错误报告中所述,解决方法是将 m2repository 目录显式添加为顶级 build.gradle 文件中的本地 Maven 目录,如下所示:

allprojects {
    repositories {
        // Work around https://code.google.com/p/android/issues/detail?id=69270.
        def androidHome = System.getenv("ANDROID_HOME")
        maven {
            url "$androidHome/extras/android/m2repository/"
        }
    }
}

关于android - 如何将 Android 支持存储库添加到 Android Studio?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19958213/

相关文章:

php - 从 heroku php 服务器通过 firebase 发送 android 通知

java - 使用Gradle添加Google Identity Toolkit时出错

android - 在 Apple Store 和 Google Play 中发布

android - 使用 AndroidAnnotations 在 fragment 中注入(inject) View

java - 带有 Tomcat 插件的简单 Gradle 项目不起作用

java - 使用 Gradle 生成 Querydsl 类的问题

android - Gradle 构建 : Execution failed for task ':app:lint'

android - 如何将 ActiveAndroid ORM 添加到 Gradle?

默认情况下禁用的 Android : How to enable logging Log. v 值

android - 使用 delete 时出现空指针异常