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,901
  • 21
  • 84
  • 115
tir38
  • 9,810
  • 10
  • 64
  • 107

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
  • 1
  • 19
  • 155
  • 216