Thursday, December 17, 2015

Google Identity Toolkit for Android - weird compilation error

I’m hacking tiny Android app, one of the libraries I use is Google Identity Toolkit (it’s super easy to integrate). A documentation states that a Play Services should be added as dependency:
compile 'com.google.android.gms:play-services:8.3.0'
For any non trivial application it’s going to be a problem resulting in below error (or similar):
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 2
Search on Internet points to StackOverflow question: com.android.build.transform.api.TransformException. Apparently the bugs are related. The exit return code 2 is meaningless unless one has any clues. Anyway, the problem can be solved by replacing the dependency by:
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
I’ve opened an issue on Google Identity Toolkit - Android sample project asking for more documentation.
The error is related to a constraint of Android Dalvik runtime of to 65K Reference Limit. There are two solutions for the problem: decreasing the references (usually by chosing smaller dependencies, in our case subpackages instead of the full Play Services) and using so called multidex (some 3rd party blog).