Can't get stdout from gradle

hi there, we use gradle to build our android projects and have recently upgraded from android NDK r21e to r23c and are seeing problems with gradle not outputting STDOUT compared to the older gradle/NDK versions

i’ve upgraded our gradle to 7.4 and the plugin to 7.3 per the documentation here Install and configure the NDK and CMake  |  Android Studio  |  Android Developers and the projects build with no issues, but previously with android ndk r21e and gradle 5.1.1 we were receiving a ton of STDOUT from gradle about how our project is being built which is very important that no longer appears after upgrading,
one curious thing i’ve noticed is that if i force a error during build i get the STDOUT, but only if i force an error, which is not ideal. so how can i get all the stdout from gradle? i’ve tried several things, none of which seem to work, which are listed below that i can remember:

  1. create a custom build that builds successfully but still doesn’t have all the proper STDOUT - i added some code into our build.gradle file
task customBuildWithDebug {
    doLast {
       
        // Run the build with debug information
        exec {
            commandLine 'bash', 'gradlew', ,'--debug', '--no-daemon', '-Dorg.gradle.jvmargs=-Xmx256m'
        }
    }
}

the above will build successfully when called with bash gradlew customBuildWithDebug, but is missing a lot of important STDOUT we use to verify it built correctly

  1. use a custom logger in an attempt to log everything - made a new file customerLogger.init.gradle
useLogger(new CustomEventLogger())

@SuppressWarnings("deprecation")
class CustomEventLogger extends BuildAdapter implements TaskExecutionListener {

    void beforeExecute(Task task) {
        println "[$task.name]"
    }

    void afterExecute(Task task, TaskState state) {
        println()
    }
    
    void buildFinished(BuildResult result) {
        println 'build completed'
        if (result.failure != null) {
            result.failure.printStackTrace()
        }
    }
}

the above also builds successfully, but doesn’t contain the STDOUT we need.

  1. using Logging i added a logger to our build.gradle file
logging.captureStandardOutput LogLevel.INFO

again, a successful build, but missing the STDOUT that lets us know the other pieces built correctly. i’m fairly certain this is being built correctly and just not outputting STDOUT as we have tests that then call on this successful build for additional output that is present that couldn’t be possible unless those pieces built correctly.

is there a workaround for this or something i’m overlooking? any help would be appreciated

If you tell it to log the stdout to info, did you enable info logging by using --info or -i?
The default level is QUIET, so if you want it without --info you probably should configure it to be sent to QUIET instead of INFO.

thanks for the reply, i did try --info and can see additional information in our logs that shows it’s working, but it’s still not outputting the information, stdout, or sub-processes that i need. gradle builds our project that also integrates our product at build time that runs a bunch of sub-processes, is there something specific in gradle to allow it to also show sub-processes that are executing during build time? --debug also doesn’t seem to show these sub-processes, just more gradle only information

some additional information that might be helpful -

if we downgrade to the old ndk r21e that uses gradle 5.1.1 with plugin 3.4.0 and java 8 we can see this output, but once we upgrade to ndk 23/gradle 7.4/plugin 7.3/java 11(could be mixing up the plugin and gradle version here) we no longer see this information but the build still succeeds, so it definitely seems to be something to do with the upgrade, just not sure what :thinking:

wanted to close the loop on this in case anyone else runs into this. our solution was to create a new file gradle.properties and add a single line in this file:

android.native.buildOutput=verbose

we upgraded from gradle plugin 3.4 to 7.3 and turns out in this giant leap there was changes in the plugin in version 4.2 that reduced “build clutter output”. the documentation is here Android Studio  |  Android Developers

after adding this file and the line above we can now see the additional build information we were seeing in gradle plugin 3.4.0 and previously missing without this line after doing our upgrade, hopefully it might help someone else :slight_smile:

1 Like