如何解决Facebook tools:replace =“android:theme”问题?

58

我有

compile 'com.facebook.android:facebook-android-sdk:4.16.0'

我的清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
...
    <application
            android:name=".MyApplication"
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AutoTheme"
            tools:replace="android:theme">

如何解决编译错误:

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:69:13-72
    is also present at [com.facebook.android:facebook-android-sdk:4.16.0] AndroidManifest.xml:32:13-63 value=(@style/com_facebook_activity_theme).
    Suggestion: add 'tools:replace="android:theme"' to <activity> element at AndroidManifest.xml:66:9-70:47 to override.

它在activity标签上显示错误。您需要删除样式或提供 tools:replace="android:theme" 到您的<activity> 标签。请在此粘贴您的整个清单文件。 - Ajith Pandian
1
Facebook SDK v4.16 中出现了一些错误 https://dev59.com/1lkS5IYBdhLWcg3wgXHf#39748440 - oleynikd
你可以通过点击以下链接找到答案:https://dev59.com/1lkS5IYBdhLWcg3wgXHf#39748440 - Ramesh Jaya
1
看起来我们要在AndroidManifest.xml文件中添加tools:replace="android:theme"或删除android:theme="@android:style/Theme.Translucent.NoTitleBar"。这两种方法都适用于我。但哪种方法更好呢?当前的Facebook Android SDK版本是4.16.1,问题是由于[com.facebook.android:facebook-android;sdk:4.16.1]也具有android:theme="@android:style/Theme.Translucent.NoTitleBar",导致清单合并失败。我认为删除android:theme="@android:style/Theme.Translucent.NoTitleBar"更好。 - kimbaudi
6个回答

105

1) 在AndroidManifest文件的<manifest>元素中添加xmlns:tools="http://schemas.android.com/tools"

2) 在(facebook activity) <activity>中添加tools:replace="android:theme"

这是我的清单文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.company.product" xmlns:tools="http://schemas.android.com/tools">

    ...

    <application
      android:allowBackup="true"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:theme="@style/AppTheme"
      android:name="MyApplication">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
        <intent-filter>
            ...
        </intent-filter>
      </activity>

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

        ...

      </application>

</manifest>

21
жҲ‘дёҚеҗҢж„ҸгҖӮжІЎжңүеҝ…иҰҒеңЁ<manifest>дёӯж·»еҠ xmlns:tools="http://schemas.android.com/tools"并еңЁ<activity>дёӯж·»еҠ tools:replace="android:theme"гҖӮжңҖеҘҪеҸӘйңҖд»Һ<activity> xmlж Үи®°дёӯеҲ йҷӨandroid:theme = "@ android:style/Theme.Translucent.NoTitleBar"пјҢеӣ дёәжңҖж–°зҡ„Facebook SDK 4.16.1е·Із»ҸеҢ…еҗ«е®ғгҖӮдҪҶжҳҜдёӨз§Қж–№жі•йғҪеҸҜд»ҘпјҢжүҖд»Ҙд»ҺиҝҷдёӘи§’еәҰжқҘиҜҙ并没жңүе…ізі»гҖӮ - kimbaudi
@kimbaudi你能分享一下你在哪里找到关于Facebook SDK 4.16.1包含android:theme的信息吗?Facebook的官方文档仍然建议添加android:theme属性。 - Srikar Reddy
感谢它帮助了我。 - Jatinkumar Patel
谢谢兄弟,有效了。我想知道是什么样的天才开发了一个SDK,在整合最基本的用例(登录)时还会出现冲突。 - voghDev

7

试试这个。

 <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" />

替换为

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

1
不需要替换。只需删除“android:theme =” @ android:style / Theme.Translucent.NoTitleBar“ - kimbaudi

4

FacebookActivity是一个类文件,它位于库中。 - NickUnuchek
我也喜欢这个解决方案。 - kimbaudi

3
你只需在Manifest文件中使用以下代码,即可使用FacebookActivity功能。
  <activity android:name="com.facebook.FacebookActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            tools:replace="android:theme"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:label="@string/app_name" />

1

移除这行代码:@android:style/Theme.Translucent.NoTitleBar

这样可以解决你的问题。

(这样可以避免清单属性冲突)


0
在我的情况下,我更改了属性android:theme =“$ {appTheme}”(其中在build.gradle manifestPlaceholders [“appTheme”] =“@style/Theme2”),结果出现编译错误:

执行任务':app:processGoogleDebugManifest'失败。 清单合并器失败:AndroidManifest.xml:23:9-42中的Attribute application@theme value =(@style/ Theme)也存在于AndroidManifest.xml:21:9-36中, value =(@style / Theme2)。建议:添加'tools:replace =" android:theme"'到AndroidManifest.xml:15:5-92:19元素以覆盖。

我有3个AndroidManifest 文件。 然后我在所有3个文件中更改了android:theme


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接