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

Wednesday, July 26, 2017

Android Development and Debugging Tips

Removing Whitespace

Options in Eclipse for fixing Whitespace errors  automatically
Automatic whitespace removing before git commit

Kernel Log message


We can get last log after rebooting without rooting
cat /proc/last_kmsg

After updating boot.img for eng mode, we can use "cat /proc/kmsg.


Sunday, February 01, 2015

Building OpenCV for Android from Source

Reference

Introduction

  1. Check Android Version
    1. Most of Example does not run completely on Lollipop because native camera are not supported by OpenCV 2.4.10.  libnative_camera_r5.0.0.so does not exist yet.
  2. Download Android source code and compile it 
    1. For full build including "OpenCV Manager(or Engine)" android platform source tree is needed. Check my previous post (http://jylee-world.blogspot.kr/2013/11/android-platform-nexus-4-rooting.html)
    2. We get opencv_engine.apk(including libOpenCVEngine.so and libOpenCVEngine_jni.so) by setting source tree.
  3. Download android NDK and set ANDROID_NDK
  4. Download android SDK and set ANDROID_SDK
  5. Setup for cmake (explained in detail in the next sections)
    1. Modify cmake_android_arm.sh
    2. Combine cmake_android_service.sh)
  6. Apply minor source modifications (explained in detail in the next sections)
  7. cmake
  8. make
 I use opencv-2.4.10-release, android-ndk-r9d(NDK),  adt-bundle-linux-x86_64-20140702(SDK), android-4.4.2_r1 (Android Source)

Friday, December 12, 2014

A Tutorial on android.hardware.camera2.*

Introduction

Since android.hardware.camera is deprecated after API V21, we use android.hardware.camera2.*. The related reference is http://developer.android.com/reference/android/hardware/camera2/package-summary.html . But this is a kind of a dictionary. We need simple tutorials. There is no good sample code even in http://developer.android.com .


After long googling I found good one :
http://blog.csdn.net/torvalbill/article/details/40378539 . And I made my own document focused on only Camera Preview.

All of my code is here : https://github.com/stereoboy/android_samples

Setup All of related objects

The following list is as follows:

  • CameraManager
    • Select Camera
    • Create CameraDevice
  • CameraDevice
    • Create CaptureRequest
    • Create CameraCaptureSession
  • CaptureRequest, CaptureRequest.CameraBuilder
    • Link Surface for Viewing
    • Make CaptureRequest
  • CameraCaptureSession
    • Capture Camare Image and put the result on the Surface registered in CaptureRequest.

One of reasons why the related objects are a little bit complex is most of set-up process is done asynchronously. For example when we create CameraDevice, at first we register a callback function on CameraManager. When CameraDevice is created and the callback is called, we get CameraDevice in the callback code.

Repeated Capture by using HandlerThread

Main thread should not be blocked by Camera Capture. So we set up a background thread using HandlerThread and Handler

This handler in background thread do repeatedly Capturing set by CaptureRequest and CameraCaptureSession.


Tuesday, November 26, 2013

Nexus 4 Rooting from source code


Intro

There are so many documents dealing with rooting Android devices. But most of webpages describe it using binaries already pre-built by Hacker groups. It is not enough for rookies who want to build their own binaries from source code, kernel to user level. This manual is written for them.

Before Rooting we need to prepare to restore original release binaries. We can get full binary images and vendor specific driver binaries for custom build from here: https://developers.google.com/android/


Android web pages(http://source.android.com/index.html) already contain all information. I just added comments dedicated to Nexus 4 and re-arrange their order.

Sunday, November 24, 2013

Install java6 jdk from oracle binary instead of using "apt-get install sun-java6-jdk"


For Android platform development, we need java6.
But the guide is outdated. "sun-java6-jdk" is deprecated! ;-(

We have to find another way.


First of all, we need oracle java6 jdk binary.

The url is Oracle download page. You need your account on oracle.com for downloading it.
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR




tmax@tmax3:~/work/android$ chmod +x jdk-6u45-linux-x64.bin
tmax@tmax3:~/work/android$ ./jdk-6u45-linux-x64.bin
Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
replace jdk1.6.0_45/db/bin/ij? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
  inflating: jdk1.6.0_45/db/bin/ij
  inflating: jdk1.6.0_45/db/bin/NetworkServerControl
  inflating: jdk1.6.0_45/db/bin/setNetworkClientCP.bat
  inflating: jdk1.6.0_45/db/bin/setEmbeddedCP.bat
  inflating: jdk1.6.0_45/db/bin/stopNetworkServer.bat
...

I set up my  environment by following (https://help.ubuntu.com/community/Java#Oracle_.28Sun.29_Java_6
 ). But I failed. Compiling failed with the error message below.
host Java: jsilver (out/host/common/obj/JAVA_LIBRARIES/jsilver_intermediates/classes)
Note: external/jsilver/src/org/clearsilver/FactoryLoader.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
jar: internal error:
java.io.FileNotFoundException: -C (No such file or directory)
   at gnu.java.nio.channels.FileChannelImpl.open(libgcj.so.12)
   at gnu.java.nio.channels.FileChannelImpl.<init>(libgcj.so.12)
   at gnu.java.nio.channels.FileChannelImpl.create(libgcj.so.12)
   at java.io.FileInputStream.<init>(libgcj.so.12)
   at gnu.classpath.tools.jar.Creator.writeFile(libgcj-tools.so.12)
   at gnu.classpath.tools.jar.Creator.writeCommandLineEntries(libgcj-tools.so.12)
   at gnu.classpath.tools.jar.Creator.writeCommandLineEntries(libgcj-tools.so.12)
   at gnu.classpath.tools.jar.Updater.run(libgcj-tools.so.12)
   at gnu.classpath.tools.jar.Main.run(libgcj-tools.so.12)
   at gnu.classpath.tools.jar.Main.main(libgcj-tools.so.12)
make: *** [out/host/common/obj/JAVA_LIBRARIES/jsilver_intermediates/javalib.jar] Error 1
make: *** Deleting file `out/host/common/obj/JAVA_LIBRARIES/jsilver_intermediates/javalib.jar'

The guide use "update-alternatives" utility for manual setup ("manual" means not-using-apt-get). It looks fancy. But something is wrong: conflict with pre-installed gcj java(GNU Compiler for Java). I could not fix it up. No idea about "update-alternatives".

So I just followed ( http://www.arndaleboard.org/wiki/index.php/O_WiKi#Installing_the_JDK). I set PATH=$JAVA_HOME/bin:$PATH in .bashrc. The site gave good resource.


Tuesday, July 20, 2010

Android Build & Debugging with Emulator

This reference is based on Android 2.2 Froyo source tree.  with Emulator

Reference
http://source.android.com/porting/debugging_gdb.html
Document : ./build/core/build-system.html


  • Source Modification


The following settings are needed in Android.mk.
------------------------------------------------------------------------------------------------------------------
1)
LOCAL_CFLAGS := -O0 -g
LOCAL_CPPFLAGS := -O0 -g

2)
LOCAL_STRIP_MODULE := false
------------------------------------------------------------------------------------------------------------------

LOCAL_STRIP_MODULE inheritate  its value from TARGET_STRIP_MODULE. The variable TARGET_STRIP_MODULE is set as “TARGET_STRIP_MODULE := true” in the file “./build/core/combo/TARGET_linux-arm.mk”. So This setup makes LOCAL_STRIP_MODULE  true. If LOCAL_STRIP_MODULE := true, “strip” remove all symbols from binaries. This means the binaries lost also debug symbols.

  • Setup Emulator

The reference of official homepage (http://source.android.com/porting/debugging_gdb.html) is enough.

Additionally we can set emulator port setup by using  a different way from homepage’s way: “adb forward tcp: tcp:.
When your emulator launches, you can set
------------------------------------------------------------------------------------------------------------------
emulator -avd -qemu -redir [tcp|udp]::[guest_host]:
------------------------------------------------------------------------------------------------------------------

If you want to use your own-generated system.img
------------------------------------------------------------------------------------------------------------------
emulator -avd OpenGLTest -system system.img
------------------------------------------------------------------------------------------------------------------

Just type “emulator -help” for more detailed information.


  • Build partially

If you use ./build/envsetup.sh, you can use shell command “mm”. Command “mm” means “make current directory”.


  • Make clean partially(?)