Hongkun Wang
Hongkun Wang

Reputation: 877

An easy way to print a variable in Android Studio's build.gradle?

I'm trying to print out a variable (example:${project.projectDir}) when I sync my Android Studio project with build.gradle, because I need to see the variable's value to make my task definition working properly.

I searched stack overflow and then followed others' suggestion, I tried follows:

project.logger.debug("@@@@@@@@@ ${project.projectDir}")
System.out.println("@@@@@@@@@ ${project.projectDir}")
println "@@@@@@@@@ ${project.projectDir}"

But none of above working, the "Sync" pane at the bottom does not show anything. Since Android studio does not provide "debugging gradle" function. So what is the easy way to know a variable value defined/pre-defined in build.gradle?

Upvotes: 3

Views: 4832

Answers (1)

Karthikeyan
Karthikeyan

Reputation: 296

  1. Create task inside project/module level build.gradle file, then add this code

    task sample { project.logger.lifecycle('my info message') }
    
  2. to build ./gradlew sample(Mac)

  3. It will print inside android studio terminal.

Output:

outpput

Upvotes: 5

Related Questions