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.
According to Gradle documentation: sourceCompatibility is "Java version compatibility to use when compiling Java source." targetCompatibility is "Java version to generate classes for."
You can do this by adding extra properties to the ext block in the top-level build.gradle file. // of properties you can define. // You can also create properties to specify versions for dependencies. // Having consistent versions between modules can avoid conflicts with behavior.
Method 1. Then just click on Build, Execution, Deployment Tab Build → Tools → Gradle → Use default Gradle wrapper (recommended) option. Step 2: Selecting desired Gradle version. Then click on the Project option.
Open your project in Android Studio and select File > Settings... > Build, Execution, Deployment > Build Tools > Gradle (Android Studio > Preferences... > Build, Execution, Deployment > Build Tools > Gradle on a Mac).
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
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With