Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 248
hopia Avatar asked May 09 '16 23:05

hopia


People also ask

What is sourceCompatibility in build Gradle?

According to Gradle documentation: sourceCompatibility is "Java version compatibility to use when compiling Java source." targetCompatibility is "Java version to generate classes for."

How would you specify in your build Gradle file?

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.

How do I change the Gradle wrapper version?

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.

Where is Gradle settings in Android Studio?

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).


1 Answers

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
       }
    }
}
like image 200
F. Eccard Avatar answered Oct 23 '22 23:10

F. Eccard