7/05/2016

dx process limitation (dexOptions is specifying a maximum number of 2 concurrent dx processes, but the Gradle daemon was initialized with 4)

When I enable multidex and executing ./gradlew build command, I meet the problem about 'dx process limitation' when

Error message:

To initialize with a different maximum value, first stop the Gradle daemon by calling ‘gradlew —-stop’.
dexOptions is specifying a maximum number of 2 concurrent dx processes, but the Gradle daemon was initialized with 4.

To fix the problem, I change the maxProcessCount to 1 in my gradle file.



android {

  ...

  dexOptions {

        jumboMode = true // Eabled it to allow a larger number of strings in the dex files

        maxProcessCount 1 // The maximum number of concurrent processes that can be used to dex. Defaults to 4.

        threadCount 1 // Number of threads to use when running dx. Defaults to 4.

        dexInProcess false   //To disable dexing-in-process, add the following code to your module-level build.gradle file:

        preDexLibraries true // Whether to pre-dex libraries. This can improve incremental builds, but clean builds may be slower.

    }

 }

DEX 64K Reference Limit

When the source of your Android app grew too much or you use too much 3rd party libraries, you might meet DEX 64K Reference Limit. As you are building and install your APK, the error happens like below:

Conversion to Dalvik format failed:
Unable to execute dex: method ID not in [0, 0xffff]: 65536

What is DEX 64K Reference Limit 

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536(64K)—including Android framework methods, library methods, and methods in your own code.

How to resolve or avoid it


1. Use Proguard to shrinks, optimizes and obfuscates your code by removing unused code and renaming classes, fields and methods with semantically obscure names. I won't tell too in this article.

2. Enable multidex.Configure your app build process to generate more than one DEX file

3. Use Jar Jar Links utility repackage Java libraries, remove some unnecessary packages from 3rd parties libraries.


Reference:
https://developer.android.com/studio/build/multidex.html#about

6/28/2016

Fail to remount user/userdebug device after Andriod M

  After Android M, by default, Android OS will turn on system verified boot for user or userdebug build. It means it will fail to change or push any files under system partition.

  If your ROM is userdebug, you can use the below commands to remount system partition which will be able to read/write.
  $ adb root 
  $ adb disable-verity 
  $ adb reboot 
  $ adb wait-for-device 
  $ adb remount
adb disable-verity/enable-verit can only be executed if your ROM is userdebug, and you cannot remount system partition if your image is user build.

  If you can flash the image by yourself, you can build eng ROM which eng build will disable verified boot. Alternatively, you can disable verified boot by setting ro.secure to be 0 even if it is userdebug build. You can change the value of ro.secure in [AOSP]/build/core/main.mk, you can refer to the below screenshot.

6/25/2016

Old versions of Android NDK and ndk download script

6/17/2016

OpenCL on Android

Introduction and setup
  In android, Android/Google doesn't support OpenCL officially. Fortunately, many chip vendors like Qualquam90/ Nvidia/ Intel / MTK provide their libraries to support OpenCL on Android. 

  To use OpenCL on Android. If you want to use OpenCL, you need to check if there is OpenCL library on the device. You can download apps from Google Play to query OpenCL information like the version of OpenCL, device type, and benchmark tests. You can also go through List of Android Device with OpenCL support to see the benchmarks. 
The OpenCL libraries for the major chip vendors can be found in the devices. The followings are the location of the OpenCL library:

Qualquam(QUALCOMM Adreno)/Intel(HD Graphics)/Nvidia
/system/vendor/lib/libOpenCL.so
or /system/lib/libOpenCL.so (older devices)
ARM Mali:
/system/vendor/lib/egl/libGLES_mali.so
or /system/lib/egl/libGLES_mali.so
PowerVR:
/system/vendor/lib/libPVROCL.so
  1. Create NDK project to include OpenCL headers, compile your C/C++ code and link to CL shared library, and test them on the device as executable. Moreover, you can write JNI glue code and Java code to run on Java layer.

Quick setup and use Boost.Compute which is a GPU/parallel-computing library for C++ based on OpenCL.

You can refer to Boost.Compute-AndroidIf you like it, please give a star to this git repository.









Image annotation tool / Create bounding box for training images

5/15/2016

Ubuntu 安裝新細明體

下載字型

$ wget http://mingliu.myweb.hinet.net/MingLiu/MingLiU.zip ; uznip MingLiU.zip ;

$ sudo mkdir -p /usr/share/fonts/myfonts; sudo cp MingLiU.ttc /usr/share/fonts/myfont/新細明體.ttc

重新載入字型
$ fc-cache -v /usr/share/fonts/myfonts
查看所有已安裝的所有字型

$ fc-list

4/24/2016

Facial Landmarks implemented by DLib on Android

  In the past, Google had provided Vision API to detect facial landmark. However, if you would like to use that, it requires Android Play Services SDK level 26 or greater. Besides, the number of landmarks might not be enough for you. Luckily, after the release of dlib, v18.10, it includes a number of new minor features.  The main addition in that release is an implementation of an excellent paper from this year's Computer Vision and Pattern Recognition Conference:
One Millisecond Face Alignment with an Ensemble of Regression Trees by Vahid Kazemi and Josephine Sullivan
The implementation of facial landmark extraction is fast enough, and it has 68 landmarks. Therefore, I spent a while to implement this feature to Android platform. 

Hope it can be helpful to Android developers. If it is helpful to you, please give me stars on my Github repositories, dlib-android and dlib-android-app

Setup and install Web server on ubuntu

In the article, I will show simple commands to install apache web server for local development and run a web page on Ubuntu.

Install Apache
$ sudo apt-get install apache2

Open your browser, and go to http://localhost/

Now, you can see the HTML file in /var/www/html/. Then, you can replace html file with yours.

For example, I clone my own web page from my github, and display it on browser.

$ git clone https://github.com/tzutalin/tzutalin.github.io.git
$ cd tzutalin.github.io; sudo cp -rf . /var/www/html/

Finally, open your browser and type "localhost", then you can see the web page



Note:
If you would like to register your own domain name, you can find DNS providers like GoDaddy, Namecheap, 1&1 Internet, Dotster.com, etc.




4/20/2016

Add Singleton Pattern to AndroidStudio Live Templates

AndroidStudio provides Live Templates to increase productivity for Android developers.

You can complete and insert code snippets into your code by typing their abbreviation and pressing tab. You can see and change those settings in the Editor section of the Preferences.


You can add your own templates. E.g. I add Singleton pattern, thus I can implement and add Singleton Pattern in a class quickly by type my defined abbreviation('singleton').


abbreviation : singleton 
description : Generate Singleton template for the current class
template text:
private $class$() {
    
}

private static class $class$LazyHolder {
   private static final $class$ INSTANCE = new $class$();
}

public static $class$ getInstance() {
   return $class$LazyHolder.INSTANCE;
}

Remember to let it be applicable in Java

Finally, in your java editor