IT TIP

Android facebook applicationId는 null 일 수 없습니다.

itqueen 2020. 10. 30. 21:21
반응형

Android facebook applicationId는 null 일 수 없습니다.


내 앱을 Facebook과 통합하기 위해 다음 튜토리얼을 따라 왔습니다. Facebook 튜토리얼

나는 튜토리얼의 모든 것을 따랐지만 applicationId cannot be null두 가지 경우에 이르렀고 정말 실망 스럽습니다.

My FacebookActivity onCreate에는 다음이 있으며 이는 튜토리얼과 똑같습니다.

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);
    setContentView(R.layout.main_fb);

    FragmentManager fm = getSupportFragmentManager();
    fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
    fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);

    FragmentTransaction transaction = fm.beginTransaction();
    for(int i = 0; i < fragments.length; i++) 
    {
        transaction.hide(fragments[i]);
    }
    transaction.commit();
}

그러나 내가 얻는 활동을 표시하려고 할 때 applicationId cannot be nullLogCat이 가리키는 줄은 다음과 같습니다.uiHelper.onCreate(savedInstanceState);

그래서 그 줄에 주석을 달아 보았습니다. 그리고 활동이 표시됩니다. 그러나 이제를 클릭 LoginButton하면 동일한 오류가 발생하지만 이번에는 facebook의 LoginButton 클래스에있는 applicationId 필드를 가리 킵니다.

내 문자열 값과 다음과 같은 매니페스트에 이미 Id가 있습니다.

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

코드를 사용하여 ID를 얻으려고했지만 아무것도 변경되지 않았습니다.

이 모든 원인이 정확히 무엇입니까?


TL; DR : 당신 당신의 응용 프로그램의 ID를 작성하는 strings.xml(즉, 다음 기준 @strings/fb_app_id에 당신이 (값) 직접 넣으면 때문에) AndroidManifest.xml이 작동하지 않습니다.

당신은 당신을 정의해야합니다 applicationId에서 AndroidManifest.xml이 같은 :

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

<application android:label="@string/app_name"....태그 아래

은 ( app_id는) strings.xml.


견본:

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

**주의 사항 <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/><application>태그 내에 있습니다.

-그리고 strings.xml

<string name="app_id">1389xxxxxxxx</string>

오늘부터 대답은 정확하지 않습니다. 누군가 이것을 사용하지 않은 경우 :AppEventsLogger.activateApp(this);

마지막 업데이트 이후로해야합니다. 그렇지 않으면 앱이 충돌합니다. 또한 여기에 Context가 아닌 Application 을 전달해야합니다.

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);
    }
}

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

This little code modification at the activity helped me.

@Override
    protected void onCreate(Bundle savedInstanceState) {

        FacebookSdk.sdkInitialize(getApplicationContext());
        AppEventsLogger.activateApp(getApplication());

        super.onCreate(savedInstanceState);
        ...................
        ...................    
}

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>

참고URL : https://stackoverflow.com/questions/16156856/android-facebook-applicationid-cannot-be-null

반응형