I want to make an app with facebook integration. I'm using Android Studio 1.1.0. I'm able to import the facebook skd 4.0.0 in build.gradle (Module:app) and use it in the Java code:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "package.test"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
}
I also put the LoginButton into the layout file from my activity:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
...
tools:context=".MainActivity">
<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginTop="30dp" />
</RelativeLayout>
This exception is thrown at setContentView(layoutfile)
.
I already checked the samples in facebook sdk on github but it doesn't helped me to fix this problem. Is the import of facebook sdk correctly?
Thanks in advance!
You need to call FacebookSdk.sdkInitialize in your Activity or Application onCreate.