FacebookSDK 在 Android Studio 中集成到 Android

FacebookSDK Integration into Android in Android Studio

我正在为我的应用程序添加“分享到 FB”功能。我已经下载了 SDK 并将 facebook 目录作为模块导入到我的项目中。我已经更新 settings.gradle 如下所示:

include ':facebook'
include ':SwipeMenuListView'
include ':FloomIt'

并且我已经更新了特定应用 build.gradle,如下所示:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'


android {
    compileSdkVersion 21
    buildToolsVersion '22.0.1'

defaultConfig {
    applicationId "com.floomit.floomit"
    minSdkVersion 16
    targetSdkVersion 21
    multiDexEnabled = true
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

dexOptions {
    preDexLibraries = false
}


packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
}
}

dependencies {
    compile 'com.adobe.creativesdk:image:4.0.0'
    // compile 'com.aviary.android.feather.sdk:aviary-sdk:3.6.3'
    // compile project(':showcaseView')
    compile project(':facebook')
    // compile project(':mediarouter')
    // compile 'com.facebook.android:facebook-android-sdk:4.2.0'
    compile project(':SwipeMenuListView')
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.google.android.gms:play-services:7.5.+'
    compile 'com.google.android.gms:play-services-appinvite:7.5.0'
    compile 'org.apache.httpcomponents:httpmime:4.3.6'
    compile 'org.apache.httpcomponents:httpcore:4.3.3'
    compile 'commons-codec:commons-codec:1.9'
    compile 'commons-io:commons-io:2.4'
    compile files('libs/tape-1.1.0.jar')
}

两个文件都只有一个额外的 "facebook" 行

当我尝试构建项目时,没有添加任何 facebook SDK 特定代码,构建失败并出现以下错误:(如果我从 build.gradle 和 settings.gradle 中删除 facebook 条目,则构建成功)

:FloomIt:compileDebugNdk UP-TO-DATE
:FloomIt:compileDebugSources
:FloomIt:collectDebugMultiDexComponents UP-TO-DATE
:FloomIt:packageAllDebugClassesForMultiDex
:FloomIt:shrinkDebugMultiDexComponents
:FloomIt:createDebugMainDexClassList
:FloomIt:dexDebug
AGPBI: {"kind":"simple","text":"UNEXPECTED TOP-LEVEL ERROR:","sources":[{}]}
AGPBI: {"kind":"simple","text":"java.lang.OutOfMemoryError: GC overhead limit exceeded","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat java.util.TreeMap.put(TreeMap.java:577)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.dex.file.StringIdsSection.intern(StringIdsSection.java:134)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.dex.file.StringIdsSection.intern(StringIdsSection.java:111)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.dex.file.MemberIdItem.addContents(MemberIdItem.java:56)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.dex.file.FieldIdItem.addContents(FieldIdItem.java:43)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.dex.file.UniformItemSection.prepare0(UniformItemSection.java:75)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.dex.file.Section.prepare(Section.java:213)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.dex.file.DexFile.toDex0(DexFile.java:505)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.dex.file.DexFile.toDex(DexFile.java:214)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.writeDex(Main.java:813)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.createDexFile(Main.java:576)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.processClass(Main.java:721)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.access0(Main.java:83)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.processFileBytes(Main.java:602)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.processOne(Main.java:632)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.processAllFiles(Main.java:505)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.runMultiDex(Main.java:334)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:244)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:215)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.Main.main(Main.java:106)","sources":[{}]}


 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':FloomIt:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java'' finished with non-zero exit value 3

有人可以建议如何进行吗

与其将 Facebook 添加为模块,不如添加

dependencies {
             compile 'com.facebook.android:facebook-android-sdk:4.2.0'
}

build.gradle

添加这个

dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}