Q:

Android Studio org.gradle.process.internal.ExecException even using multiDexEnabled

I'm trying to porting Apache Flink on Android. This is my build.gradle file:
apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "hk.ust.symlab.mobiflink"
        minSdkVersion 23
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/maven/org.apache.flink/force-shading/pom.xml'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/maven/org.apache.flink/force-shading/pom.properties'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE.txt'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:3.8.1'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'org.apache.flink:flink-java:1.0.0-hadoop1'
    compile 'org.apache.flink:flink-clients:0.10.2-hadoop1'
}

The weird thing is that if I don't include compile 'org.apache.flink:flink-clients:0.10.2-hadoop1' then the projects compile and run without errors, otherwise I have this error:
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 1
I've already read a lot of questions about this problem (like this one), but as you can see I already included the multiDexEnabled option (which was necessary already when I included compile 'org.apache.flink:flink-java:1.0.0-hadoop1')

A:

try this add it in your build.gradle in android section
    dexOptions {
            incremental = true;
            preDexLibraries = false
            javaMaxHeapSize "4g" // 2g should be also OK
        }

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

then add application class like bellow
public class MyApplication extends MultiDexApplication {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(base);
    }

and then mention your application class into your manifest 
<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.NoActionBar">
 </application>

