How to specify sourceCompatibility compile options when using the Android Gradle Experimental plugin
Asked Answered
J

1

9

I'm currently using the Android Gradle Experimental plugin in one of my apps and I would like to be able to use the retrolambda library. One of the requirements is to specify some compileOptions. In the normal android build plugin, this works:

  android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
  }

For the new Experimental plugin, I added this under model.android:

model {
  android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
  }
}

However, the above results in a gradle sync error:

Gradle 'ApkTestRunner' project refresh failed
Error:Cause: com.android.build.gradle.managed.AndroidConfig$Impl

How can I set sourceCompatibility and targetCompatibility using the new Android Experimental Gradle plugin?

Thanks.

Jetpropelled answered 9/5, 2016 at 23:29 Comment(0)
G
12

Must be like this:

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.1"
        compileOptions.encoding = 'windows-1251'

       compileOptions.with {
         sourceCompatibility = JavaVersion.VERSION_1_6
         targetCompatibility = JavaVersion.VERSION_1_6
       }
    }
}
Geoponics answered 24/5, 2016 at 18:6 Comment(1)
Just to add: this is in the android\app\build.gradle file and not in the root gradle fileCichocki

© 2022 - 2024 — McMap. All rights reserved.