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

How to add Android Support Repository to Android Studio?(如何将 Android 支持存储库添加到 Android Studio?)
本文介绍了如何将 Android 支持存储库添加到 Android Studio?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

I'm using Android Studio with an external Android SDK. I have installed the support library and the support repository. The support repository is in:

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

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

When I add a dependency to the support library in the build.gradle file, like:

...

repositories {
    mavenCentral()
}

...

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

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

Android Studio cannot find the support libraries (cannot resolve symbol etc) and Gradle also cannot find the libraries:

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 支持存储库的位置?

How do I specify in Android Studio and/or the build.gradle file the location of the Android support repository?

推荐答案

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

You are probably hit by this bug which prevents the Android Gradle Plugin from automatically adding the "Android Support Repository" to the list of Gradle repositories. The work-around, as mentioned in the bug report, is to explicitly add the m2repository directory as a local Maven directory in the top-level build.gradle file as follows:

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 Studio?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)