[英]I am Trying to use facebook login in My app but I am getting an error that Manifest Merger faild
I am getting this Error. 我收到此错误。 Error:Execution failed for task ':app:processDebugManifest'.
错误:任务':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).
清单合并失败:来自AndroidManifest.xml:28:13-72的属性activity#com.facebook.FacebookActivity@theme value =(@ android:style / Theme.Translucent.NoTitleBar)也出现在[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.
建议:在AndroidManifest.xml:25:9-35:20的元素上添加'tools:replace =“ android:theme”'以进行覆盖。
This is my MainActivity.java file package com.example.advanced.loginactivity; 这是我的MainActivity.java文件包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 这是我的AndroidManifest.XML文件
<?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 这是我的activity_main.xml文件
<?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 这是我的build.gradle(Module:app)文件
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)'
}
Solution is to revert to previous FB SDK in build.gradle : 解决方案是恢复到build.gradle中的先前FB SDK :
dependencies {
// ...
compile 'com.facebook.android:facebook-android-sdk:4.15.0'
}
delete this line: android:theme="@android:style/Theme.Translucent.NoTitleBar" 删除以下行:android:theme =“ @ android:style / Theme.Translucent.NoTitleBar”
AndroidManifest.xml 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. 您会看到启用自定义选项卡后,facebook网站将打开,顶部带有一个选项卡,它将占据整个屏幕。 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. 或者, 如果要保留此行 ,则需要在清单中添加tools:replace =“ android:theme”。 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 . 对于facebook登录指南 。
ADITIONAL 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. 使用Facebook登录时的另一个提示是,您会注意到在添加Facebook依赖项时,com.android.support:appcompat-v7:...会发出警告,提示您具有不同版本的依赖项。 You need to override this dependencie in order to get rid of this error
您需要重写此依赖关系才能摆脱此错误
implementation 'com.android.support:customtabs:27.1.1'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.