FacebookSDK在Android Studio中集成到Android中

时间:2015-06-24 02:01:57

标签: android gradle facebook-sdk-4.0

我正在为我的应用添加分享到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.access$300(Main.java:83)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main$1.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

有人可以建议如何继续

2 个答案:

答案 0 :(得分:3)

添加此

dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}

答案 1 :(得分:0)

不要将Facebook添加为模块,而是添加

apt-get -y update
add-apt-repository ppa:ondrej/php5-5.6
apt-get -y update
apt-get -y install php5 php5-mhash php5-mcrypt php5-curl php5-cli php5-mysql php5-gd php5-intl
build.gradle

中的