RSS

Tag Archives: Android Studio

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.

simpleuitesting_activities

Read the rest of this entry »

 
Leave a comment

Posted by on November 25, 2016 in Android

 

Tags: , , , ,

Kotlin for Android (I) Why I love Kotlin


If there is only one sentence to describe Kotlin, it would be: “Kotlin is great”!

You will not appreciate the beauty of it if you do not suffer from the repetitive, boilerplate coding in java. Let’s see an example first.

Consider you have two classes, as shown below, they do the same thing, interchangeable, exactly the same in terms of functionality, which one do you choose? Left or right one?

  image  image

The left one is java implementation, and the right, Kotlin.

This is a real example that I encountered in developing an Android App. The App tries to get the new questions on StackOverflow site: Open the link below in your browser to see how you can get the json from StackExchange API:

https://api.stackexchange.com/2.2/questions?site=stackoverflow&key=JE1srJAZi8)AoOEHcHUWdg((

You will be presented a similar json as below:

stackoverflow-questions

In order to display a list of such questions in Android views, I need to deserialize this json string to a POJO (Plain Old Java Object) representation. To avoid hands dirty,  we can go to http://pojo.sodhanalibrary.com/ and paste the json string to get the POJO class:

Read the rest of this entry »

 
Leave a comment

Posted by on June 27, 2016 in General

 

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:

android:versionCode

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. […]

android:versionName

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: , , , , , , , ,

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 com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:130).

To troubleshoot this problem, follow below procedures:

Select Android Studio in Applications:

image

Right click Android Studio > Show Package Contents

image

Open the Info.plist

image

Change the JVMVersion from 1.6* or whatever –> 1.8

image

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

image

 
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/some.package.name/abc.apk“],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn’t find “abcxyz.so

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:
      lib\armeabi-v7a

      lib\armeabi
    5. Zip the lib folder into a file, e.g. abc.zip;
    6. Rename this abc.zip –> 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!

 

 

 
3 Comments

Posted by on December 3, 2015 in Android, Programming

 

Tags: , , , , , , , , ,