Facebook-sdk-for-unity: Android SDK setup

Created on 7 Apr 2020  Â·  8Comments  Â·  Source: facebook/facebook-sdk-for-unity

Hi, as I can see in the code, Facebook recognizes if android sdk is correctly setup using EditorPrefs: https://github.com/facebook/facebook-sdk-for-unity/blob/master/Facebook.Unity.Editor/android/FacebookAndroidUtil.cs#L104

With Unity 2019.3, that value is not set anymore when the " Installed with Unity" checkbox is selected. In result, although my sdk path is correct, I can see warning in Facebook Settings "You don't have the Android SDK setup!"

Most helpful comment

Even new v8.1.0 version tries to obtain SDK incorrectly when Embedded SDK Check is marked.
Value in EditorPrefs for "AndroidSdkRoot" can be set to custom anyway.
Here's is my workaround to get rid of the error message about SDK during build (GPGS plugin obtains real embedded values the same way):

        _log.Log("preferences to use embedded JDK and android SDK/NDK");
        EditorPrefs.SetInt("JdkUseEmbedded", 1);
        EditorPrefs.SetInt("SdkUseEmbedded", 1);
        EditorPrefs.SetInt("NdkUseEmbedded", 1);

        // workaround to fix android build error message in Unity 2020.1.9 + FacebookSDK v8.1.0 
        // reset any custom value specified in settings even when embedded setting is marked
        //    because thirparty (FacebookSDK v8.1.0 looks to the following values instead of using embedded ones)
        //    possibly it's Unity issue - we need the way to obtain default values too
        var androidPlayerDir = BuildPipeline.GetPlaybackEngineDirectory(BuildTarget.Android, BuildOptions.None);
        if (string.IsNullOrEmpty(androidPlayerDir))
            throw new Exception("BuildPipeline.GetPlaybackEngineDirectory(BuildTarget.Android) failed");
        void SetDefaultToolsDir(string prefsKey, string subDir)
        {
            var dir = Path.Combine(androidPlayerDir, subDir);
            if (!Directory.Exists(dir)) 
                throw new Exception($"failed to find installed with unity external tool: {prefsKey}: {dir}");
            EditorPrefs.SetString(prefsKey, dir);
        }
        SetDefaultToolsDir("JdkPath", "OpenJDK");
        SetDefaultToolsDir("AndroidSdkRoot", "SDK");
        SetDefaultToolsDir("AndroidNdkRoot", "NDK");
        SetDefaultToolsDir("AndroidNdkRootR19", "NDK");

        _log.Log($"JdkPath: {EditorPrefs.GetString("JdkPath")}");
        _log.Log($"AndroidSdkRoot: {EditorPrefs.GetString("AndroidSdkRoot")}");
        _log.Log($"AndroidNdkRoot: {EditorPrefs.GetString("AndroidNdkRoot")}");
        _log.Log($"AndroidNdkRootR19: {EditorPrefs.GetString("AndroidNdkRootR19")}");

All 8 comments

Bump, this is annoying and should be fixed

Android SDK Tools installed via Unity Hub are located in your editor. Try unchecking 'Installed with Unity' and entering that path (mine is C:Program FilesUnity2019.2.7f2EditorDataPlaybackEnginesAndroidPlayerSDK)

Android SDK Tools installed via Unity Hub are located in your editor. Try unchecking 'Installed with Unity' and entering that path (mine is C:Program FilesUnity2019.2.7f2EditorDataPlaybackEnginesAndroidPlayerSDK)

That works, but it should be fixed anyway

Android SDK Tools installed via Unity Hub are located in your editor. Try unchecking 'Installed with Unity' and entering that path (mine is C:Program FilesUnity2019.2.7f2EditorDataPlaybackEnginesAndroidPlayerSDK)

That works, but it should be fixed anyway

Yeah, that works but it's just a workaround. In fact, then you can check "installed with unity" again but in EditorPrefs there still will be saved value from input field. This is confusing, specially for new developers

Even new v8.1.0 version tries to obtain SDK incorrectly when Embedded SDK Check is marked.
Value in EditorPrefs for "AndroidSdkRoot" can be set to custom anyway.
Here's is my workaround to get rid of the error message about SDK during build (GPGS plugin obtains real embedded values the same way):

        _log.Log("preferences to use embedded JDK and android SDK/NDK");
        EditorPrefs.SetInt("JdkUseEmbedded", 1);
        EditorPrefs.SetInt("SdkUseEmbedded", 1);
        EditorPrefs.SetInt("NdkUseEmbedded", 1);

        // workaround to fix android build error message in Unity 2020.1.9 + FacebookSDK v8.1.0 
        // reset any custom value specified in settings even when embedded setting is marked
        //    because thirparty (FacebookSDK v8.1.0 looks to the following values instead of using embedded ones)
        //    possibly it's Unity issue - we need the way to obtain default values too
        var androidPlayerDir = BuildPipeline.GetPlaybackEngineDirectory(BuildTarget.Android, BuildOptions.None);
        if (string.IsNullOrEmpty(androidPlayerDir))
            throw new Exception("BuildPipeline.GetPlaybackEngineDirectory(BuildTarget.Android) failed");
        void SetDefaultToolsDir(string prefsKey, string subDir)
        {
            var dir = Path.Combine(androidPlayerDir, subDir);
            if (!Directory.Exists(dir)) 
                throw new Exception($"failed to find installed with unity external tool: {prefsKey}: {dir}");
            EditorPrefs.SetString(prefsKey, dir);
        }
        SetDefaultToolsDir("JdkPath", "OpenJDK");
        SetDefaultToolsDir("AndroidSdkRoot", "SDK");
        SetDefaultToolsDir("AndroidNdkRoot", "NDK");
        SetDefaultToolsDir("AndroidNdkRootR19", "NDK");

        _log.Log($"JdkPath: {EditorPrefs.GetString("JdkPath")}");
        _log.Log($"AndroidSdkRoot: {EditorPrefs.GetString("AndroidSdkRoot")}");
        _log.Log($"AndroidNdkRoot: {EditorPrefs.GetString("AndroidNdkRoot")}");
        _log.Log($"AndroidNdkRootR19: {EditorPrefs.GetString("AndroidNdkRootR19")}");

Same problem here. Very annoying and has to be fixed.

Android SDK is used only to obtain "Debug Android Key Hash".

You can get it without this panel:
keytool -exportcert -alias <ALIAS_NAME> -keystore <KEYSTORE_PATH> | openssl sha1 -binary | openssl base64
debug keystore: <home>/.android/debug.keystore
debug alias: androiddebugkey

And better do it yourself, because there are other issues with this panel's
section:

  1. your Project Settings can have custom keystore/alias settings and panel
    doesn't use them
  2. you can have custom alias name (not androiddebugkey)
  3. your keystore can have password and then you'll get incorrect Hash from
    inner message like "keytool error: java.io.IOException: Keystore was
    tampered with, or password was incorrect" ))

I even think it's much easier to just replace the section with a link to
docs.)

On Tue, Nov 3, 2020 at 10:17 PM Karam000 notifications@github.com wrote:

Same problem here. Very annoying and has to be fixed.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/facebook/facebook-sdk-for-unity/issues/426#issuecomment-721325106,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AKBLQ2YIJNFPWECOB4QJRELSOBJL5ANCNFSM4MDIHWJQ
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

charanjeet5ingh picture charanjeet5ingh  Â·  6Comments

laijingfeng picture laijingfeng  Â·  6Comments

MorganMoon picture MorganMoon  Â·  7Comments

michelleran picture michelleran  Â·  6Comments

SeriouslySam picture SeriouslySam  Â·  6Comments