Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Wednesday, November 5, 2014

Facebook SDK for Android

[Install the Prerequisites]
1. Prepare your Android development environment
    * Get the Android SDK: http://developer.android.com/sdk/index.html
    * Development tools: JDK 6 (JRE alone is not sufficient), Apache Ant 1.8 or later
    * Create AVD: http://developer.android.com/tools/devices/managing-avds.html
    * Adding SDK Packages: http://developer.android.com/sdk/installing/adding-packages.html
    * Building Your First App: http://developer.android.com/training/basics/firstapp/index.html

2. You'll need to have the Android 2.2 (API 8) components installed in order to use the Facebook SDK.

[Download the Facebook SDK and install Facebook APK for AVD]
1. Download them:
    https://developers.facebook.com/resources/facebook-android-sdk-current.zip
    https://developers.facebook.com/resources/Facebook-11.zip

2. Export PATH:
    * set_env_android.sh:
       $ cat set_env_android.sh
       ANDROID_SDK_HOME="/home/linst/ws/android/ws/adt-bundle-linux-x86_64-20140702/sdk";

       export PATH="${PATH}:${ANDROID_SDK_HOME}/platform-tools";
       export PATH="${PATH}:${ANDROID_SDK_HOME}/tools";

    * source it:
       $ source set_env_android.sh
       $ which adb
       /home/linst/ws/android/ws/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb
 
3. Install Facebook APK to emulator:
    * Reason:
"The Facebook SDK uses Facebook's native app to provide support for authentication when it's present. On a real device, you can test this by simply installing this app for free from Google Play. However, it's not possible to access Google Play on an emulator. If you want to test the flow there, you can download and extract the APK of the Facebook app. It should be named Facebook-11.apk or similar. To install it onto an Android emulator ... "
    * Start AVD
    * Install:
       $ unzip Facebook-11.zip
       Archive:  Facebook-11.zip
         inflating: Facebook-11.apk      

       $ adb devices
       List of devices attached
       emulator-5554 device

       $ adb install ./Facebook-11.apk
       2533 KB/s (40683138 bytes in 15.680s)
        pkg: /data/local/tmp/Facebook-11.apk
       Success

4. Import the SDK into Eclipse:
    * Unzip the Facebook SDK:
       $ unzip facebook-android-sdk-3.20.0.zip
    * Import the Facebook SDK library and the samples to Eclipse:
"The installation folder contains a directory called facebook, which is the SDK project itself. There is
also a selection of sample projects in the 
samples folder."

"To import the SDK library project and the samples, with the new SDK, go to Eclipse's 'File' > 'Import' menu, and select 'General' / 'Existing Projects into Workspace'"

"Browse to select the root of your SDK folder, facebook-android-sdk-3.16. The SDK should appear in the list as 'FacebookSDK' along with all of the samples."

"You must unselect the 'Copy projects into workspace' option so that each of the sample projects retains a correct reference to the neighboring SDK. However, this means that Eclipse creates a link to the project in the SDK installation, rather than making a copy of it."

    * Clean your projects to remove build errors: Project -> Clean... -> Clean all projects.
    * Some important paths:
       Facebook SDK root path: /home/linst/ws/android/ws/facebook-android-sdk-3.20.0
       Facebook SDK library: /home/linst/ws/android/ws/facebook-android-sdk-3.20.0/facebook
       Basic Samples: /home/linst/ws/android/ws/facebook-android-sdk-3.20.0/samples
       AudienceNetwork Samples: /home/linst/ws/android/ws/facebook-android-sdk-3.20.0/AudienceNetwork

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

Friday, September 19, 2014

Debug Android executables using gdb and gdbserver

About 3 monthes ago I created a POC which is a cross-built executable running on a rooting Android device, but it crashed unexpectedly with only "Segmentation fault" messages. Because there is no GDB available in my Google Nexus 7, so after some studies, I found that I can cross debugging with GDB and GDBServer in NDK folder:
$ find ndk9c/ -name "gdbserver" -type f
ndk9c/prebuilt/android-mips/gdbserver/gdbserver
ndk9c/prebuilt/android-arm/gdbserver/gdbserver
ndk9c/prebuilt/android-x86/gdbserver/gdbserver
$ find ndk9c/ -name "arm*gdb" -type f
ndk9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb
ndk9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb

Here are my steps:

On Host

$ adb push ndk9c/prebuilt/android-arm/gdbserver/gdbserver /data/working
$ adb forward tcp:1234 tcp:1234

On Device

$ cd /data/working
$ ./gdbserver localhost:1234 MyProgram
Process ./MyProgram created; pid = 729
Listening on port 1234

On Host

$ ./arm-linux-androideabi-gdb ./MyProgram
GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
...
Reading symbols from /home/steven/working/bin/MyProgram...done.

(gdb) target remote 169.254.255.1:1234
Remote debugging using 169.254.255.1:1234
warning: Unable to find dynamic linker breakpoint function.
GDB will retry eventurally.  Meanwhile, it is likely
that GDB is unable to debug shared library initializers
or resolve pending breakpoints after dlopen().
0xb0001000 in ?? ()

(gdb)

On Device

After Host machine "target remote 169.254.255.1:1234", Device gdbserver will show below message:
...
Listening on port 1234
Remote debugging from host 169.254.255.2

On Host

Finally you can start the executable on Host machine and waiting for the crashed, then debug it:
(gdb) b UnicodeConversion.cpp:373
(gdb) c
Continuing.
...
Program received signal SIGSEGV, Segmentation fault.
...
(gdb) bt
...
(gdb)

References

http://www.kandroid.org/online-pdk/guide/debugging_gdb.html
http://appleapplecat.pixnet.net/blog/post/32464205-gdbserver-on-android [Chinese]