Category Archives: Android

‘’ not found, the solution

Recently, I build some open source Android libraries, and when building the project, below error occurred:

Error:(2, 0) Plugin with id ‘’ not found.

Quick Solution:

install Yarn, everything works!

Mac: brew install yarn
Windows: refer to this link.


A less elegant solution is to manually change the top level build.gradle:


dependencies {
classpath ‘’

To –>

dependencies {
classpath ‘’
classpath com.github.dcendents:android-maven-gradle-plugin:1.5  //Add this
classpath com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3      //Add this


Rebuild. It should work. But this is tedious, for every project (e.g. react-native), you repeat doing so?  Emmmmmm!

Now try to create a new react-native project using:

react-native init ProjectName

Run the project:

react-native run-android  // or
react-native run-ios

It compiles and works! Happy coding.


Posted by on April 18, 2017 in Android


Tags: , , , , , , , , , , , ,

Android Automated UI Testing with Expresso (I)

I have been trying to write a few articles on Android automated UI testing for a long time, ever since my last job when we started experimenting using Expresso in our commercial Android App.

This article outlines the simplest UI testing with Expresso, with step-by-step snapshots for beginners to walk through.


Read the rest of this entry »

Leave a comment

Posted by on November 25, 2016 in Android


Tags: , , , ,

Step-by-Step guide for developing Android Plugin for Unity3D (II)

In previous blog, I have covered how to handshake Native Android code with Unity3D. The example shown therein is pretty simple: how to call a java function in C#!

In this blog, I am trying to step one more stride further: to create and use an Android View in Unity3D. The example shown here is an Android ImageView, however, this approach is generally applicable to all kinds of Android Views, ViewGroups and custom views.

imageAn Android ImageView

imageUse Android ImageView in Unity3D

Read the rest of this entry »


Posted by on August 10, 2016 in Android, Programming, Unity 3d


Tags: , , , , , , ,

Android: get active, current or foreground Activity

In our recent Android App development, we developed many static utility functions, which needs a Context as the argument:

public static void func1(Context context, …)
public static void func2(Context context, …)
public static void func3(Context context, …)

public static void funcN(Context context, …)

This is very cumbersome. We would like to refactor these utility functions into functions without the context argument/ A natural idea to pass in the application context at the very beginning, e.g. Application.onCreate() function, but not in all cases, can we use the application context. For instance, when you create a dialog or toast window, we need to use Activity as the context. So here comes the function that works:


Visit this gist to get the source code.

Leave a comment

Posted by on July 13, 2016 in Android, Programming


Tags: , , , , , , ,

Android: automatic set or update versionName from versionCode

In Android, version name and version code serve for different purposes, as is found in Android documentation here:


An internal version number. This number is used only to determine whether one version is more recent than another, with higher numbers indicating more recent versions. This is not the version number shown to users; that number is set by the versionName attribute. The value must be set as an integer, such as “100”. You can define it however you want, as long as each successive version has a higher number. […]


The version name shown to users. This attribute can be set as a raw string or as a reference to a string resource. The string has no other purpose than to be displayed to users. The versionCode attribute holds the significant version number used internally.

In practice, it is often the case that the version name simply maps version code in specific ways, e.g.

2016 (version code)  –>  v2.0.1.6 (version name)

Read the rest of this entry »

Leave a comment

Posted by on June 13, 2016 in Android, Programming


Tags: , , , , , , , ,

Android: Handle Custom protocol Urls

You might ever found custom protocol urls like below:


When you copy this custom protocol url in your mobile browser, you will find that an Android App is activated, rather than a new web page. How to implement such functions in your own Android App? This article offers a walk through example to do so.


Read the rest of this entry »

Leave a comment

Posted by on May 13, 2016 in Android, Programming


Tags: , , , ,

Install Statistics plugin for AndroidStudio: crash and troubleshooting

Statistic is a very powerful plugin for IntelliJ IDEA, which is very useful to show files sorted by their extension along with size, line count LOC etc.

However, if you install this into the latest version of Android Studio, you are most likely to get the below error message:

Plugin ‘Statistic’ failed to initialize and will be disabled. Please restart Android Studio. com.intellij.diagnostic.PluginException: com/jpower8/idea/plugin/statictic/StatisticApplicationComponent : Unsupported major.minor version 51.0 [Plugin: Statistic] at

To troubleshoot this problem, follow below procedures:

Select Android Studio in Applications:


Right click Android Studio > Show Package Contents


Open the Info.plist


Change the JVMVersion from 1.6* or whatever –> 1.8


Of course you have to install JDK 1.8! Restart Android Studio and enjoy!


Leave a comment

Posted by on May 4, 2016 in Android


Tags: , , , , , , , ,

How to package native library (*.so) in Android Studio

Recently I was working on some projects where the native library (*.so) is used. It builds in Android Studio without any problem, but when I run it on the Android devices, it crashes with the following error message:

Can’t load xxx library: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/“],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn’t find “

After millions of trial and error, here comes the solution:

    1. Create a folder called “lib” (must be exactly this name)
    2. Create subfolders in lib with desired architecture name such as “armeabi-v7a”, “armeabi” etc.
    3. Put all your *.so file in the just created folder
    4. Now your folder structure should be like this:

    5. Zip the lib folder into a file, e.g.;
    6. Rename this –> abc.jar
    7. Copy this abc.jar to your project subfolder, anywhere should do, but I would typically put it in the app\libs\abc,jar
    8. In the build.gradle, add:

dependencies {
compile files(‘libs/abc.jar’)

Rebuild, that is all! Happy Coding!




Posted by on December 3, 2015 in Android, Programming


Tags: , , , , , , , , ,

Android: How to play RTMP video streams

In the post Android: How to play RTSP or HLS video streams, there is one missing video streaming issue leaving unresolved: the RTMP videos.

This post outlines how to implement rendering RTMP videos on Android platform. This is far from a trivial problem, but I will get it done quickly using the open source Vitamio library.

  1. Download the Vitamio bundle from, extract the zip file if you downloaded the zip file, or if you pull the source out of it, you will see a folder called “vitimio” there.

  2. In Android Studio, create a project, let’s call it VideoStreamPlayer.

  3. In Android Studio, go to File->Import Module, navigate to “VitamioBundle-master” folder you extracted or pulled from the source, select “vitamio” folder and press finish to import the library.

  4. Add compile project(‘:vitamio’) in build.gradle(Module: app) dependencies section


  • Add the internet permission in your manifest, outside <application> node

<uses-permission android:name=”android.permission.INTERNET”/>

  • Build the app and make sure it works.
  • Go to the activity layout, add below code:


android:layout_height=”wrap_content” />

  • In the activity class, add below code:

protected void onCreate(Bundle savedInstanceState) {

    if (!LibsChecker.checkVitamioLibs(this))  //Important!

    mVideoView = (VideoView) findViewById(;
    path = “rtmp://”;

Rebuild and run. That is it!

Tip 1: to make it easier to debug and troubleshooting, you might first make sure an rtmp stream is valid. You can do so by opening the RTMP url in VLC player.

Tip 2: If nothing displays in the activity, make sure  if (!LibsChecker.checkVitamioLibs(this)) is called.

Tip 3: Depending on the network, some RTMP might be very slow, so be patient when it loads.


Posted by on September 20, 2015 in Android, Programming


Tags: , , , , , , , ,

Android: How to play RTSP or HLS video streams

Playing rtsp video streams seems to be a complex task in Android, but actually it is insane easy. Here is how.

  • Create a new project using Android Studio
  • Drag a VideoView control to the UI or add below code in the UI xml file:
        android:id="@+id/videoView" />


image   image

Read the rest of this entry »


Posted by on September 19, 2015 in Android, Programming


Tags: , , , , , , , , , ,