Build script error, unsupported Gradle DSL method found: 'runtime()'!

build.gradle file:

apply plugin: ''
//apply plugin: 'android'
//apply plugin: ''
  android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"
      defaultConfig {
        minSdkVersion 9
        targetSdkVersion 21
      buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
  dependencies {
    runtime files('libs/opt-classes.jar')
    compile ''

I’ve tried with the other plugin options “android”, and “”, but it makes no difference.

From the docs, I thought this wouldn’t be a problem, and have no idea why I’m getting the runtime plugin error.

Anyone got a clue as to what I’m doing wrong?

The Android Gradle plugin does not create a configuration named ‘runtime’. You can, however, use the ‘apk’ configuration to include a file in the final packaged APK while excluding it form the compile time classpath.

Oh, okay, sorry that’s a misunderstanding on my part, actually. What I want is actually the opposite, I want a library to build with reference to another jar, but not package / include it. With Eclipse ADT this was achieved by not including the jar to be packaged at compilation time. That basically assumed the class files will be on the device already when referenced at runtime, not included in that build.

This is, for instance how China Mobile billing services operate.

Got it, then simply add it to the ‘compile’ configuration and exclude it from ‘apk’.

apk.exclude files(‘opt-classes.jar’)

Ok, thanks for that Mark, that definitely works for the main application, but this is a android library project. Is there an equivalent to “apk” here? I’ve tried “lib.exclude”, “library.exclude” and googled for similar, but can’t find what’s correct here.

I’m not certain if there is a similar configuration for library projects. The documentation is somewhat lacking in this area. You could however just exclude the file when packaging the AAR.

android.libraryVariants.all {

packageLibrary {

exclude ‘opt-classes.jar’



Yeah, I saw similar mentioned from!topic/adt-dev/WIjtHjgoGwA

Their version is,

android.libraryVariants.all { variant ->
    variant.packageLibrary.exclude( 'libs/somejars.jar' )

Which gives me the error,

Error:(22, 0) Could not find property 'packageLibrary' on

Your version gives me the error,

Error:(22, 0) Gradle DSL method not found: 'packageLibrary()'

So it feels like we’re close, but still not quite there. To make 100% sure, where should I putting this block, in the android { } section, or just anywhere at the root of the build.gradle file?

Thanks for your help!

It should probably go at the end of your build script, to ensure all requisite plugins are applied and configuration exists. It does not need to inside the ‘android {…}’ block.

Got it, from

android.libraryVariants.all { variant ->
    variant.outputs.each { output ->

Now all’s working perfectly! Thanks Mark, much appreciated.

Glad you got it working. In the future, stackoverflow might be a better resource for these types of questions. This forum is primarily for inquires regarding core Gradle capabilities.

Ok, getcha. I had made a post on StackOverflow earlier about one of the problems I’ve been having, and it got no response, or attention, as well as trying on the IRC channel (which seems unfortunately quite inactive).