Android Studio - 无法解析符号 FacebookContentProvider

Android Studio - Cannot resolve symbol FacebookContentProvider

我正在使用 Maven 的 Facebook SDK 3.22.0。为 Android SDK 版本 15 构建。我也在使用 Android Studio 1.1.0 和 Gradle。

在 AndroidManifest.xml 中,我尝试使用 FacebookContentProvider,但每次尝试时,我都会遇到无法解析符号 FacebookContentProvider 的问题。关于如何解决这个问题的任何想法?

我遇到问题的具体行是:

<provider android:authorities="com.facebook.app.FacebookContentProvider1234"
              android:name="com.facebook.FacebookContentProvider"
              android:exported="true"/>

这是我的 AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.whatever"
android:versionCode="100"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="11" />

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.MICROPHONE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

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

    <activity
        android:name="com.whatever.MainActivity"
        android:label="@string/app_name" 
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <activity android:name="com.google.android.gms.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode"
              android:theme="@android:style/Theme.Translucent" />

    <activity android:name="com.facebook.LoginActivity"
              android:theme="@android:style/Theme.Translucent.NoTitleBar"
              android:label="@string/app_name" />

    <activity android:name="com.whatever.Friends"
              android:screenOrientation="portrait" />
    <activity android:name="com.whatever.Recent"
              android:screenOrientation="portrait">
    </activity>

    <provider android:authorities="com.facebook.app.FacebookContentProvider1234"
              android:name="com.facebook.FacebookContentProvider"
              android:exported="true"/>
</application>

这是我的 build.gradle:

apply plugin: 'com.android.application'

dependencies {
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    compile('org.apache.httpcomponents:httpmime:4.3') {
        exclude module: "httpclient"
    }
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.facebook.android:facebook-android-sdk:3.22.0'
}

android {
    compileSdkVersion 15
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "com.whatever"
        minSdkVersion 15
        targetSdkVersion 15
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES'
    }
    productFlavors {
    }
}

Quote:

Append your app id to the end of the authorities value. For example if your Facebook app id is 1234, the declaration looks like:

<provider android:authorities="com.facebook.app.FacebookContentProvider1234"
          android:name="com.facebook.FacebookContentProvider"
          android:exported="true" />

你确定你的app id是1234吗?还有为什么 target sdk 是 15 而 min sdk 是 15?你为什么不使用最新的 facebook sdk?修复它,我想一​​切都会好的。

很遗憾,您不能将 FacebookContentProvider 与 Facebook SDK 版本 3.22.0 一起使用,因为它是在版本 4.0.0 中引入的,正如您在 GitHub:

上看到的那样

https://github.com/facebook/facebook-android-sdk/commits/master/facebook/src/com/facebook/FacebookContentProvider.java

你有两个解决方案:

在 Facebook SDK 的 v3.x 中,它被称为 NativeAppCallContentProvider,因此您需要执行以下操作:

<provider
    android:name="com.facebook.NativeAppCallContentProvider"
    android:authorities="com.facebook.app.NativeAppCallContentProvider{Facebook-App-Id}"
    android:exported="true" />