0

I am getting this Error. Error:Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : Attribute activity#com.facebook.FacebookActivity@theme value=(@android:style/Theme.Translucent.NoTitleBar) from AndroidManifest.xml:28:13-72 is also present at [com.facebook.android:facebook-common:4.35.0] AndroidManifest.xml:32:13-63 value=(@style/com_facebook_activity_theme). Suggestion: add 'tools:replace="android:theme"' to element at AndroidManifest.xml:25:9-35:20 to override.

This is my MainActivity.java file package com.example.advanced.loginactivity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;


 public class MainActivity extends AppCompatActivity {
 private CallbackManager callbackManager;
 @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);


    callbackManager = CallbackManager.Factory.create();

    LoginManager.getInstance().registerCallback(callbackManager,
            new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    // App code
                    Log.d("Success", "Login");
                }

                @Override
                public void onCancel() {
                    // App code
                    Log.d("Cancel", "Login Cancelled");
                }

                @Override
                public void onError(FacebookException exception) {
                    // App code
                    Log.d("Error", "An Error Occured");
                }});
}


  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent        data) {
    callbackManager.onActivityResult(requestCode, resultCode, data);
    super.onActivityResult(requestCode, resultCode, data);
}


}

This is my AndroidManifest.XML file

 <?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET"/>


<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    >
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"
        android:label="@string/app_name"/>

</application>

This is my activity_main.xml file

     <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.advanced.loginactivity.MainActivity"
    android:id="@+id/email_login_form"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <com.facebook.login.widget.LoginButton
            android:id="@+id/facebook_sign_in_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:layout_marginBottom="10dp"
            android:layout_gravity="center_horizontal" />
</LinearLayout>

This is my build.gradle(Module: app) file

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.advanced.loginactivity"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.facebook.android:facebook-android-sdk:[4,5)'

}

2 Answers2

0

Solution is to revert to previous FB SDK in build.gradle:

dependencies {
// ...
compile 'com.facebook.android:facebook-android-sdk:4.15.0'
}
Rishav Singla
  • 485
  • 4
  • 10
  • I don't think it is a good idea to downgrade the dependecies version, since it works fine with the last version com.facebook.android:facebook-android-sdk:[4,5) – Soon Santos Aug 18 '18 at 14:38
0

delete this line: android:theme="@android:style/Theme.Translucent.NoTitleBar"

AndroidManifest.xml

<meta-data android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>


    <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name" />
    <activity

    <!-- If you want the custom tabs when the facebook website is oppened -->
        android:name="com.facebook.CustomTabActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
    </activity>

You'll see that with custom tabs enabled the facebook website will open with a tab in the top and it will occupy the whole screen. Without this the website will open like a pop up and you can still see the app in the background if you look at the corners.

Or if you want to keep this line you need to add tools:replace="android:theme" in your manifest. But I see no reason to keep this line (correct me if I am wrong).

<activity android:name="com.facebook.FacebookActivity"
            android:configChanges=
                "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            tools:replace="android:theme"/>

For facebook login guide.

ADITIONAL

An additional tip while working with facebook login, you will notice that when you added the facebook dependecie, com.android.support:appcompat-v7:... gives a warning saying that you have dependecies with different versions. You need to override this dependencie in order to get rid of this error

implementation 'com.android.support:customtabs:27.1.1'
Soon Santos
  • 2,107
  • 22
  • 43