Facebook integration with Libgdx Gradle android studio
I am new to libgdx on android studio. I am trying to integrate facebook with an android project. I am following this link ( Getting Started ) to integrate it with android module. When I click sync, I should be able to import com.facebook.FacebookSdk;
But it doesn't work like that. No matter what I am trying to get, the error cannot be resolved by symbol 'facebook'
In the build.gradle of the android module, I added:
repositories {
mavenCentral()
}
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile files('libs/twitter4j-core-4.0.4.jar')
compile files(some adnetwork jars)
}
I also tried adding compilation 'com.facebook.android:facebook-android-sdk:4.1.0' in main build.gradle in project (": android") doesn't work either.
I tried to sync gradle several times by restarting android studio, also File-> invalidatecaches / restart helps nothing.
I missed a step. Please advice.
thank
I found the problem myself. I used cmd to create the project and I found it failed due to "Failed to execute dex" issue (too many methods) See here .
For people with a similar problem in the future, run this in your project root folder with cmd: gradlew build --stacktrace
`This will clearly explain why the build failed.
You may have added it in the wrong place. At the root of you Libgdx Project open build.gradle
add your line:
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
inside dependencies in project(":android")
Run build.gradle again to keep it in sync and you should see:
Download https://repo1.maven.org/maven2/com/facebook/android/facebook-android-sdk/4.1.0/facebook-android-sdk-4.1.0.pom
Download https://repo1.maven.org/maven2/com/parse/bolts/bolts-android/1.2.0/bolts-android-1.2.0.pom
Download https://repo1.maven.org/maven2/com/parse/bolts/bolts-android/1.2.0/bolts-android-1.2.0.jar
Download https://repo1.maven.org/maven2/com/facebook/android/facebook-android-sdk/4.1.0/facebook-android-sdk-4.1.0.aar