Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know the properties in applicationVariants of android gradle plugin?

I'm using Android Studio with gradle plugin to develop applications. I learn some usage of android gradle plugin on DSL Reference. But one thing I found is that the applicationVariants part on doc is hard to understand. It only gives such a description:

DomainObjectSet<ApplicationVariant> applicationVariants

The list of Application variants. Since the collections is built after evaluation, it should be used with Gradle's all iterator to process future items.

But what's the properties in the ApplicationVariant? I don't know. And I found nothing reference link to describe the ApplicationVariant.

Only in the Gradle Plugin User Guide at the very bottom of the page. It documents the available properties in applicationVariants, libraryVariants and testVariants. But I found quite some of these properties are deprecated for a long time, and Android didn't update this page.

So where do I find the most updated properties in ApplicationVariant?

like image 522
Tony Green Avatar asked Apr 17 '16 03:04

Tony Green


People also ask

Where is Gradle properties in Android Studio?

The top-level build.gradle file, located in the root project directory, defines dependencies that apply to all modules in your project. By default, the top-level build file uses the plugins block to define the Gradle dependencies that are common to all modules in the project.

How do I know my Gradle plugin version?

In Android Studio, go to File > Project Structure. Then select the "project" tab on the left. Your Gradle version will be displayed here.

How do I get the current build type in Gradle?

In your build. gradle (:app): tasks. all { Task task -> if (task.name == "preDebugBuild") { doFirst { //for debug build } } else if (task.name == "preReleaseBuild") { doFirst { //for release build } } } dependencies { ... }

What is my Android Gradle plugin version?

Here are at least two ways you can find out the gradle version (not the gradle plugin version) by selecting one of the following on project tab on left: Android > Gradle Scripts > gradle-wrapper. properties (Gradle Version) > distributionURL.


1 Answers

https://android.googlesource.com/platform/tools/build/+/8dca86a/gradle/src/main/groovy/com/android/build/gradle/internal/ApplicationVariant.groovy

I had a hard time finding it too. Here's the interface incase it moves: It will also have any props you define in your flavor, like the versionName, applicationId etc

public interface ApplicationVariant {     String getName()     String getDescription()     String getDirName()     String getBaseName()     VariantConfiguration getConfig()     boolean getZipAlign()     boolean isSigned()     boolean getRunProguard()     FileCollection getRuntimeClasspath()     FileCollection getResourcePackage()     Compile getCompileTask()     List<String> getRunCommand()     String getPackage()     AndroidBuilder createBuilder(AndroidBasePlugin androidBasePlugin) } 

And to print the props of any object:

def filtered = ['class', 'active']  println theObject.properties             .sort{it.key}             .collect{it}             .findAll{!filtered.contains(it.key)}             .join('\n') 
like image 138
CaptRespect Avatar answered Sep 23 '22 10:09

CaptRespect