Question

Ok, this has taken over a week, but I finally found the cause of why I can't seem to log in to facebook using the Facebook SDK (v4.3.4) with Unity3d (v4.3) on my android devices. Now to figure out how to fix it... ?

Symptom: I run the application on the android device. When I press the login button, it opens the permissions prompt from facebook. Then... nothing. The login doesn't complete, and looking through the logs, its clear that the LoginCallback isn't being called. (Although Facebook appcenter does record that you've granted permission to the app). If I asked for multiple permissions, it only prompts for the first one. (normally it will prompt for the first one, appear to go back to the application for a split second, then prompt again for the second).

Cause: The manifest file is being incorrectly generated.

Here's an example of the one manifest file for FriendSmash when its generated CORRECTLY:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:theme="@android:style/Theme.NoTitleBar" android:versionCode="1" android:versionName="1.0" package="com.mycompany.mygame" android:installLocation="preferExternal">
  <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true" />
  <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true">
    <activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:label="@string/app_name" android:launchMode="singleTask" android:name="com.facebook.unity.FBUnityPlayerActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:label="@string/app_name" android:launchMode="singleTask" android:name="com.unity3d.player.UnityPlayerActivity">
    </activity>
    <activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:label="@string/app_name" android:launchMode="singleTask" android:screenOrientation="reverseLandscape" android:name="com.mycompany.mygame.UnityPlayerNativeActivity">
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    </activity>
    <activity android:configChanges="keyboardHidden|orientation" android:name="com.facebook.LoginActivity" android:screenOrientation="portrait">
    </activity>
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\ 586438214724597" />
  </application>
  <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
  <uses-feature android:glEsVersion="0x00020000" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-feature android:name="android.hardware.touchscreen" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>

Here's an example of the manifest file for FriendSmash when its generated INCORRECTLY:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:theme="@android:style/Theme.NoTitleBar" android:versionCode="1" android:versionName="3.0" package="com.mycompany.mygame" android:installLocation="preferExternal">
  <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true" />
  <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true">
    <activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:label="@string/app_name" android:launchMode="singleTask" android:screenOrientation="reverseLandscape" android:name="com.mycompany.mygame.UnityPlayerNativeActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    </activity>
    <activity android:configChanges="keyboardHidden|orientation" android:name="com.facebook.LoginActivity" android:screenOrientation="portrait">
    </activity>
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\ 586438214724597" />
  </application>
  <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
  <uses-feature android:glEsVersion="0x00020000" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-feature android:name="android.hardware.touchscreen" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>

Two main differences: (1) The main activity for the correct manifest file is named "com.facebook.unity.FBUnityPlayerActivity" and for the incorrect file its "com.mycompany.mygame.UnityPlayerNativeActivity", and (2) the correct file also has a "com.unity3d.player.UnityPlayerActivity" and the "com.mycompany.mygame.UnityPlayerNativeActivity" appears after it.

But unfortunately, most of the time, Unity is generating the incorrect version of the file. I've tested it with the FriendSmash game, tested a custom app that adds the facebook sdk, and tested another sample app that only contains the facebook SDK (all on both windows and mac). They all generated the wrong version, except by chance, the first time I downloaded the FriendSmash complete project. And when I downloaded FriendSmash fresh to test on mac, it started generating the file incorrectly as well.

Additionally, if you just try to build the apk file in unity without creating the Google Android Project, it uses the wrong manifest and builds a broken app.

Solution: No Idea. Anyone have any thoughts on how to fix this?

Was it helpful?

Solution

Ok, so it seems the manifest file being provided in the new version of the sample project and in the new SDK unity package are used to build the custom manifest file that the Google Android Project uses. It must have been updated incorrectly and is what is causing the problems.

To fix, after you import the Facebook SDK, just replace the file at Assets/Plugins/Android/AndroidManifest.xml with the old version:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" android:installLocation="preferExternal" android:theme="@android:style/Theme.NoTitleBar" android:versionCode="1" android:versionName="1.0">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true">
    <activity android:name="com.facebook.unity.FBUnityPlayerActivity" android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    </activity>
    <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    </activity>
    <activity android:name="com.facebook.LoginActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation">
    </activity>
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\ 586438214724597" />
  </application>
</manifest>

I haven't yet tested this with building a new Google Android Project, but I was able to directly build the apk file and run it on the phone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top