Thursday, May 28, 2015

Run Unity-generated android APK file in device, with FB app installed (Part 2)

From previous post, now we can proceed to test on the Android device. If you are directly generated the APK, then you are wrong (partially. If your device does not has Facebook app, then it works fine mostly, but it'll not work if other way round)

1) Make sure you have Android SDK installed. Go to Unity Editor, click on "Build Settings"


2) Add the interactive scene, and click "Android" platform, then click "Player Settings ...". Configure the "Company Name", "Product Name, and "bundle identifier"


3) Click "Build" button in "Build Settings" to generate APK file.

4) Copy the APK file to your device, and install it. Some of the tools (eg. "ASTRO File Manager" you might need it. You need to enable third-party apps installation on android phones too.

5) After installation is done, launch the app you installed. Click the "FB.Init" and follow by "Login". Everything should be fine.




6) But if you install Facebook app in your device and run the sample interactive apk. This time will fail.

7) To generate the debug log (idea is from here; You might need these tools: adb, logcat), connect your device to laptop with cable, and run this in command prompt:

$ adb logcat -d > logcat.txt

then start the app in device again. Repeat the login process until you hit the login error. Then press Ctrl-C to stop the logging in command prompt.

8) I saw this message "Login cancelled by player" in the log captured. By printing the keyHash sent to server, then I realized it was caused by missing keyhash.

9) To run in Andoid, you need to get a keyhash. To get a keyhash,  you need OpenSSL.
If you are on Windows, you need to install OpenSSL. If you use 64-bit Windows, download and install "Win64 OpenSSL v1.0.2a". If you use 32-bit Windows, download and install "Win32 OpenSSL v1.0.2a". Make sure you configure the "PATH" variable in "Environment Variables" too. I get the idea here.
(I was reported this step is not needed in MacOS.)

10) Restart the Unity Editor, Click on "Facebook" menu. This time you go to: "Android Build Facebook Settings". You see the "Debug Android Key Hash" automatically now.



*If you found out you see nothing in the "Debug Android Key Hash" then you probably miss the above step (9), it is needed, as in GetKeyHash() function in "~\Assets\Facebook\Editor\android\FacebookAndroidUtil.cs"(see more here)


* Execute the command can see the same result too(you can use OpenSSL version 0.9.8h too):

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | C:\openssl-0.9.8h-1-bin\bin\openssl.exe sha1 -binary | C:\openssl-0.9.8h-1-bin\bin\openssl.exe base64

default password for debugging purpose is: android



11) This time, I built the APK file and run again in device. Still failed. From the debug log, this time I get:

OnLoginComplete({"cancelled":true})

12) I have to go to Facebook developer page again (the one you created early to get the AppId) to add configuration for Android. (got the idea here) Go to "Settings" and click "Add Platform".


13) Choose "Android"


14) Copy all the values "Package Name", "Class Name" and "Debug Android Key Hash" from Unity Editor and paste in the new "Android" setting.


15) Build the APK again and run from device. This time everything is OK, even with Facebook app installed. (this time the the login pop up will be from Facebook app)



Phew! Finally done.






5 comments:

liza brown said...

Thanks for sharing nice information . i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job.
go to blog article

Unknown said...

Do you realize there's a 12 word phrase you can communicate to your partner... that will trigger deep emotions of love and instinctual attraction to you deep within his heart?

Because deep inside these 12 words is a "secret signal" that fuels a man's instinct to love, please and guard you with his entire heart...

12 Words Who Fuel A Man's Love Instinct

This instinct is so built-in to a man's mind that it will make him work harder than before to make your relationship the best part of both of your lives.

In fact, fueling this dominant instinct is so essential to having the best possible relationship with your man that once you send your man one of these "Secret Signals"...

...You'll immediately notice him open his mind and heart for you in such a way he never expressed before and he will see you as the only woman in the world who has ever truly understood him.

Niketa Sharma said...

I found this post very useful regarding Unity Game Engine. Thanks for sharing the details.

Fonts Mania said...

Wao, Great man! If you like this online converter then you can easily convert the android file to other formats;

Files Converter Online

Fonts Mania said...

That can support various formats including those;

Wmv to Flv

Swf to Jpeg

M4v to Jpg

3gp file to Jpeg

3gp to Mp3