0

Along the lines of this:

Build.Gradle

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 19
        ...
    }

    android.buildTypes {
        debug
        release
    }
    ...
}

//How to access model.android.buildTypes outside model?
$(model.android.buildTypes).each { buildType ->
    task "task$buildType" << {
        ...
    }
}

This document briefly explains the $() syntax within the model for accessing other model.android.* properties: gradle experimental

I'm using gradle 2.10

My attempts with "${}" and $("") syntax are not working, and usually fail along the lines of:

Could not find property 'android' on task ':app:model'.

I believe property access outside of that block used to work with 'apply plugin: com.android.application' instead of the new model.

Since model is a task, I looked up Task (see the dynamic properties section) and tried model.property(android) but that didn't work either. I'm guessing it's in there somewhere but I can't query for a list of properties.

I understand this is gradle-experimental; any tips on where to look in the gradle source code for an answer would be graciously accepted!

Andrew Smart
  • 351
  • 5
  • 11

1 Answers1

0

Turns out the android.* properties are exposed as properties on the project (e.g. project.buildTypes).

Example:

task ptest() << {
  println buildTypes.collect{it}.join('\n')
  println platforms.collect{it}.join('\n')
  println flavors.collect{it}.join('\n')
}

Output:

user@debian:~/dev/androidinputrouter$ ./gradlew :app:ptest
:app:ptest
build type 'debug'
build type 'release'
platform 'arm64-v8a'
platform 'armeabi'
platform 'armeabi-v7a'
platform 'mips'
platform 'mips64'
platform 'x86'
platform 'x86_64'
flavor ''
Andrew Smart
  • 351
  • 5
  • 11