Android facebook applicationId cannot be null

后端 未结 5 2142
小鲜肉
小鲜肉 2020-12-02 12:08

I\'ve been following the following tutorial to integrate my app with Facebook. Facebook tutorial

I\'ve followed everything on the tutorial, but I\'ve been getting

相关标签:
5条回答
  • 2020-12-02 12:21

    Since today the answer is not quite correct. If someone didn't use this: AppEventsLogger.activateApp(this);

    Since last update you must do it or your app will crashed. And you also should pass Application here not Context

    https://developers.facebook.com/docs/android/getting-started

    // Add this to the header of your file:
    import com.facebook.FacebookSdk;
    
    public class MyApplication extends Application {
        // Updated your class body:
        @Override
        public void onCreate() {
            super.onCreate();
            // Initialize the SDK before executing any other operations,
            FacebookSdk.sdkInitialize(getApplicationContext());
            AppEventsLogger.activateApp(this);
        }
    }
    
    0 讨论(0)
  • 2020-12-02 12:26

    Actually you do not have to use flavor codes in gradle...

    if you have number longer than 4 Bytes, you should this code in strings.xml

    Note: Attention this quotation mark (")

    <string name="facebook_app_id">"1111111111111"</string>
    
    0 讨论(0)
  • 2020-12-02 12:27

    This little code modification at the activity helped me.

    @Override
        protected void onCreate(Bundle savedInstanceState) {
    
            FacebookSdk.sdkInitialize(getApplicationContext());
            AppEventsLogger.activateApp(getApplication());
    
            super.onCreate(savedInstanceState);
            ...................
            ...................    
    }
    
    0 讨论(0)
  • 2020-12-02 12:28

    The problem is that the id is being converted to integer: https://code.google.com/p/android/issues/detail?id=78839

    In my case the facebook_app_id was being set from the build.gradle file per flavor.

    The solution was to wrap the id with ":

    flavor.resValue "string", "facebook_app_id", "\"1111111111111\""
    

    or if you would rather avoid escaping:

    flavor.resValue "string", "facebook_app_id", '"1111111111111"'
    
    0 讨论(0)
  • 2020-12-02 12:41

    TL;DR: you have to write your application's ID in your strings.xml and then reference (i.e. @strings/fb_app_id), because if you put it directly (as value) into AndroidManifest.xml it won't work.

    you must define your applicationId in the AndroidManifest.xml like this:

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

    under <application android:label="@string/app_name".... tag

    where app_id is a string within your strings.xml.


    sample:

     <application android:label="@string/app_name"
                     android:icon="@drawable/icon"
                     android:theme="@android:style/Theme.NoTitleBar"
                >
            <activity android:name=".HelloFacebookSampleActivity"
                      android:label="@string/app_name"
                      android:windowSoftInputMode="adjustResize">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
            <activity android:name="com.facebook.LoginActivity"
                      android:theme="@android:style/Theme.Translucent.NoTitleBar"
                      android:label="@string/app_name" />
            <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
        </application>
    

    ** please note <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> is within <application> tag

    -- and in strings.xml

    <string name="app_id">1389xxxxxxxx</string>
    
    0 讨论(0)
提交回复
热议问题