mardi 17 mai 2016

Gradle build fails while using Android internal API

I'm trying to use Android internal API (android.telecom.DisconnectCause) in one of my projects, with the help of Java Reflection. I extracted core.jar and framework.jar from my device and converted it to custom jars which have access to Android internal classes: core-dex2jar.jar and framework-dex2jar.jar. I added these two jars in my library build path and now, the Android Studio can successfully resolve the Android internal classes.

enter image description here

I've also added the following dependencies in my Gradle file:

compile files('libs/core-dex2jar.jar')
compile files('libs/framework-dex2jar.jar')

Here is my code snippet where I'm trying to work with Android internal API:

//Testing Java Reflection
    try{
        Method[] methods = android.telecom.DisconnectCause.class.getMethods();
        for (Method mthd : methods) {
            Log.i("DISCONNECT_CAUSE", mthd.getName());
        }

    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }

For testing purpose, I'm just trying to list down all methods in DisconnectCause class.

My problem is, whenever I try to compile, the Gradle build gives the following error:

Error:Execution failed for task ':app:preDexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1

I've tried adding the following compile options to rule out any compatibility issues, but nothing seems to work!

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

Can anyone please tell me what might be wrong here? Your help will be highly appreciated! Thanks in advance!





Aucun commentaire:

Enregistrer un commentaire