Android Studio 中的 Gradle:无法解析第三方库 [英] Gradle in Android Studio: Failed to resolve third-party libraries

查看:36
本文介绍了Android Studio 中的 Gradle:无法解析第三方库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将我的项目从 Intellij 切换到 Android Studio,这需要我创建一个 build.gradle 文件.我知道我可以将其中的每一个添加为库依赖项,但我理想情况下希望能够使 Maven 存储库依赖项工作.

I have been trying to switch my project from Intellij to Android Studio, which has required me to create a build.gradle file. I know I can add each of these as a library dependency, but I ideally want to be able to get the maven repository dependency working.

每次同步时,我的支持库都同步得很好,但是对于每个第三方库,我都会得到类似

Every time I sync, my support libraries are synced fine, but for each third-party library, I get something like

"错误:(30, 13) 无法解决:com.facebook.android:facebook-android-sdk:3.23.1"

"Error:(30, 13) Failed to resolve: com.facebook.android:facebook-android-sdk:3.23.1"

对于每个库.

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'com.android.application'

dependencies {

compile fileTree(dir: 'libs', include: '*.jar')

// Google Play Services
compile 'com.google.android.gms:play-services:6.5.87'

// Support Libraries
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:gridlayout-v7:21.0.3'
compile 'com.android.support:mediarouter-v7:21.0.3'
compile 'com.android.support:palette-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
compile 'com.android.support:support-annotations:21.0.3'
compile 'com.android.support:support-v13:21.0.3'
compile 'com.android.support:support-v4:22.0.0'

// third-party libraries
compile 'com.amazonaws:aws-java-sdk:1.9.24'
compile 'com.facebook.android:facebook-android-sdk:3.23.1'
compile 'com.github.markushi:android-ui:1.2'
compile 'de.hdodenhof:circleimageview:1.2.2'
compile 'it.neokree:MaterialNavigationDrawer:1.3.2'

}

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }

    // Move the tests to tests/java, tests/res, etc...
    instrumentTest.setRoot('tests')

    // Move the build types to build-types/<type>
    // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
    // This moves them out of them default location under src/<type>/... which would
    // conflict with src/ being used by the main source set.
    // Adding new build types or product flavors should be accompanied
    // by a similar customization.
    debug.setRoot('build-types/debug')
    release.setRoot('build-types/release')
}
}

推荐答案

添加:

repositories {
   mavenCentral()
}

build.gradle.现在您只在构建脚本中定义了 repositories,它只为 buildscript 本身而不是为项目解析依赖项.

to the build.gradle. Now you have repositories defined only in build script which resolves dependencies only for the buildscript itself not for the project.

这篇关于Android Studio 中的 Gradle:无法解析第三方库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆