简体   繁体   中英

Android Studio doesn't execute build.gradle

If I add println("hello world!") to the build.gradle (the one in the root directory) in android studio, and execute gradlew from the command-line, I get "hello world!". However, clicking the green arrow in the IDE does not result in this being printed. Also, if I do something like generate a text file, executing gradlew will also generate the text file.

I'm trying to understand what magic the IDE is doing. Which gradle tasks get executed when I click on the green button? How do I configure this? What gets printed out to the IDE's console?

When being run in Android Studio, gradle's stdout where you can find your print statement is the "Gradle Console". Hover over the square in the bottom left of the Android Studio window and you'll see lots of options to select things like Console, Maven, Event Log, etc. Select Gradle Console and you should see the output that you get when running from the command line.

If you still don't see your statement being logged, chances are something isn't configured correctly inside your Android Studio project. Try synching your project with the gradle build file by going the top menu bar and (on a mac) Tools > Android > Sync Project with Gradle Files.

If there are no errors in this process you should be able to see the output in the Gradle Console.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM