To integrate the Facebook SDK for Android (Meta SDK), you need to configure your application in the Meta Developers Console, implement the required dependencies using Modern Gradle, and configure your Android manifest.
Below is the complete, up-to-date procedural breakdown for the implementation. 1. Configure the Meta Developers Console
Before adding code, you must register your application on the Meta for Developers platform.
Create App: Navigate to Meta Apps and create a new application. Select your appropriate use case (e.g., Authenticate users or track App Events).
Get Credentials: Note down your App ID and Client Token from Settings > Advanced > Security.
Add Android Platform: Go to Settings > Basic, click Add Platform, and select Android.
Package Details: Enter your exact package name (e.g., com.example.myapp) and your default launch activity class name (e.g., com.example.myapp.MainActivity).
Generate Key Hashes: Meta requires your signing key hash for security verification. Generate it via terminal:For Debug Build (Mac/Linux):
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 Use code with caution.
For Release Build: Extract your SHA-1 deployment fingerprint from the Google Play Console under Setup > App Integrity, then convert that hex string to base64. Paste this resulting string into the Key Hashes field on your Meta console. 2. Add Gradle Dependencies
Meta distributes its SDK as modular components on Maven Central. Only include the modules you actually need to keep your .apk lightweight.
Ensure mavenCentral() is declared inside your root settings.gradle.kts (or build.gradle). Then, add the core or specific modules inside your app-level /app/build.gradle.kts file:
dependencies { // To import the entire SDK suite: implementation(“com.facebook.android:facebook-android-sdk:latest.release”) // OR add individual modules à la carte for optimization: // implementation(“com.facebook.android:facebook-login:latest.release”) // implementation(“com.facebook.android:facebook-share:latest.release”) // implementation(“com.facebook.android:facebook-appevents:latest.release”) } Use code with caution. 3. Update Resources and Android Manifest
You must expose your Meta credentials via your resources file so the manifest can securely reference them. Define Strings Facebook SDK for Android – Meta for Developers
Leave a Reply