2

I have a similar problem to this question

Could not get unknown property 'applicationVariants' for object of type com.android.build.gradle.LibraryExtension.

I am trying to check for this property and do something if I have it. I assumed I could follow this answer:

// for application modules
if (project.hasProperty('applicationVariants')) {
    println "has applicationVariants"
    android.applicationVariants.all { variant ->
       // ... do something
    }
}

// for library modules
if (project.hasProperty('libraryVariants')) {
    println "has libraryVariants"
    android.libraryVariants.all { variant ->
        // ... do something
    }
}

However I'm not seeing any of the print statements and none of the inner code is executing. What am I missing?

Phantômaxx
  • 37,352
  • 21
  • 80
  • 110
tir38
  • 8,776
  • 6
  • 56
  • 93

1 Answers1

1

these are properties of project.android - and within task afterEvaluate they have a value.

task afterEvaluate {

    if(project.android.hasProperty('applicationVariants')) {
        println("*** has applicationVariants")
    }

    if(project.android.hasProperty('libraryVariants')) {
        println("*** has libraryVariants")
    }
}
Martin Zeitler
  • 59,798
  • 15
  • 122
  • 186