【问题标题】:Unable to add Facebook SDK as a dependency in Android Studio无法将 Facebook SDK 添加为 Android Studio 中的依赖项
【发布时间】:2015-10-05 23:50:51
【问题描述】:

这是我得到的错误:

错误:(14, 13) 无法解决:com.facebook.android:facebook-android-sdk:4.6.0 在文件中显示
在项目结构对话框中显示

我可以在 Gradle 控制台中看到它正在本地 SDK 库中查找 lib,尽管我确保未选中 gradle 设置中的脱机工作复选框。

这是我的 build.gradle 文件:

buildscript {
    repositories {
        jcenter()
        mavenCentral()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}


apply plugin: 'com.android.application'

dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    compile 'com.facebook.android:facebook-android-sdk:4.6.0'
    compile 'com.google.android.gms:play-services-identity:8.1.0'
    compile 'com.google.android.gms:play-services-gcm:8.1.0'
}

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'
    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')
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    defaultConfig {
        targetSdkVersion 23
    }
    productFlavors {
    }
}

有什么想法吗?

【问题讨论】:

    标签: android android-studio gradle build.gradle facebook-sdk-4.0


    【解决方案1】:

    您需要在应用级别的 build.grade 中执行此操作

    buildscript {
        repositories {
            jcenter()
            mavenCentral()
    
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.3.0'
        }
    }
    

    这个在应用级文件夹的 build.grade 中

    apply plugin: 'com.android.application'
    
    dependencies {
        compile fileTree(include: '*.jar', dir: 'libs')
        compile 'com.facebook.android:facebook-android-sdk:4.6.0'
        compile 'com.google.android.gms:play-services-identity:8.1.0'
        compile 'com.google.android.gms:play-services-gcm:8.1.0'
    }
    
    android {
        compileSdkVersion 23
        buildToolsVersion '23.0.1'
        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')
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
        defaultConfig {
            targetSdkVersion 23
        }
        productFlavors {
        }
    }
    

    【讨论】:

    • 嗨@Aakash,感谢您的协助。能否详细说明一下什么是app级文件夹中的build.gradle,什么是应用级?
    • 检查你的项目结构你会发现两个build.gradle文件,一个在应用程序级别,另一个在app文件夹中,这就是我所说的应用程序和应用程序级别
    • 在我的项目中只有一个 build.gradle 位于 app 文件夹中。我应该在哪里找到另一个?
    • 在应用层面,你能把你的项目结构截图发给我解释一下
    • 双击顶部的项目图标或右键单击项目并打开模块设置并尝试在那里检查
    【解决方案2】:

    正在寻找同样的问题,下面的答案让我开始思考,因为我在开发时总是使用 Charles Proxy,目前它没有运行。当我再次启动它时,它开始使用初始设置。

    只是为了分享信息,我遇到了同样的问题,解决方案是 不同。

    在我的情况下,使用了代理服务器并导致了问题。我需要 配置 https 代理设置,如 gradle behind proxy 中所述 在 Android Studio 1.3 中。

    Source

    【讨论】:

      猜你喜欢
      • 2014-08-26
      • 1970-01-01
      • 2018-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-10
      • 2014-03-14
      • 1970-01-01
      相关资源
      最近更新 更多