【问题标题】:Cannot install Support repository and sync project in Android Studio无法在 Android Studio 中安装支持存储库和同步项目
【发布时间】:2017-09-15 16:08:28
【问题描述】:

我正在尝试使用 25.2.0 版本的支持库 这样我就可以使用CameraKit 库了。

我已经下载了最新的构建工具:

和支持存储库:

我的 gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
    defaultConfig {
        applicationId "com.sample.myapp"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    maven {
        url "https://jitpack.io"
    }
    mavenCentral()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'

    // Google libraries
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:design:25.2.0'
    compile 'com.android.support:support-v4:25.2.0'
    compile 'com.google.android.gms:play-services-vision:10.0.1'
    compile 'com.android.volley:volley:1.0.0'

    // Third party libraries
    compile 'com.flurgle:camerakit:0.9.17'

    compile 'com.android.support:recyclerview-v7:25.2.0'
    compile 'com.android.support:cardview-v7:25.2.0'
}

问题: 对于每个支持库,我都会遇到问题:

Failed to resolve com.android.support:cardview-v7:25.2.0

如果我尝试点击安装存储库并同步项目,则什么也没有发生。

我以gradle file 为例。会不会是我的错?

【问题讨论】:

  • 也更新支持库
  • 当你点击“Install Repository and sync project”时,会发生什么?
  • @CommonsWare 什么都没有。当鼠标指针悬停在链接上时,它会更改以指示存在可单击的链接。点击后没有任何反应。我已经尝试过文件 -> Infalidate caches / Restart。不幸的是,这没有帮助
  • 如果您在 SDK 工具选项卡中向下滚动(显示在您的问题中),您应该会看到 Android 存储库的条目。它是否表明您拥有最新版本?
  • Android 支持存储库已下载 47.0.0 版?我在帖子中添加了屏幕截图。

标签: android android-studio gradle android-support-library build-tools


【解决方案1】:

之前,Android 支持库依赖项是从 Android SDK 管理器下载的。

现在所有新版本都可以从 Google 的 Maven 存储库中获得。 未来所有的android库都将通过maven.google.com进行分发

因此,通过将以下代码添加到存储库将构建项目。

repositories {
    maven {
        url "https://maven.google.com"
    }
}

【讨论】:

    【解决方案2】:

    我必须将以下内容添加到我的项目级 build.gradle。然后按钮安装和工作。

    allprojects {
        repositories {
            maven {
                url "https://maven.google.com"
            }
            jcenter()
        }
    }
    

    【讨论】:

    • 我不明白他们为什么不在新项目中包含这个。
    【解决方案3】:

    尝试使用最新的支持库版本:

    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.google.android.gms:play-services-vision:10.2.1'
    compile 'com.android.volley:volley:1.0.0'
    // Third party libraries
    compile 'com.flurgle:camerakit:0.9.17'
    
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    

    这里是详细信息Dependencies

    编辑

    使用Google Maven Repository

    要将它们添加到您的构建中,您需要首先将 Google 的 Maven 存储库包含在您的顶级 build.gradle 文件中:

    项目 -- build.gradle(不是应用程序build.gradle

     allprojects {
        repositories {
            // 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/'
    
           jcenter()
        }
    }
    

    【讨论】:

    • 我已应用您建议的更改并遇到问题:无法解决:com.android.support:design:25.3.1
    • 依赖来自官方文档...清理构建并确保您已连接到互联网
    • @jublikon 由于没有在你的Android studio中列出,你需要拉取最新的。你有一段时间没有更新了。
    • 在 build.gradle 中输入 maven 的 url 可以解决我的问题...谢谢..
    【解决方案4】:

    请务必将其放在allprojects 下!我的错误是把它放在buildscript 下。

    不要这样做:

    buildscript {
        repositories {
            jcenter()
             maven {
                 url 'https://maven.google.com' //don't put it here
             }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.3'
        }
    }
    

    但要这样做:

    allprojects {
        repositories {
            jcenter()
            maven {
                url 'https://maven.google.com' //put it here
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-07
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 2016-08-24
      • 2013-05-11
      相关资源
      最近更新 更多