What is the <module>/release/output.json generated by Android Studio

AndroidAndroid StudioApkAndroid Studio-3.0

Android Problem Overview


I recently noticed a new file generated at <module>/release/output.json by Android Studio 3 Canary 1 each time I run Build -> Generate Signed APK..., which has contents that look like following.

Can anyone confirm seeing this behavior as well? Or is it due to some local configuration on my laptop?

And can anyone explain the purpose of this file? Is it safe to add to .gitignore?

[{  "outputType": {    "type": "APK"  },  "apkInfo": {    "type": "MAIN",    "splits": [],
    "versionCode": 32
  },
  "outputFile": {
    "path": "/path/to/the/generated/release/filename.apk"
  },
  "properties": {
    "packageId": "com.example.android",
    "split": ""
  }
}]

Android Solutions


Solution 1 - Android

Android studio 3.0 is responsible for this file. You don't need to worry about the output.json file.

Let me explain this to you:

For older versions, what Android Studio did was generate a signed APK and put it in the "output" folder. Even If you had multiple flavour dimensions for your APK, all of them could be located at the same directory, which was the output folder. From the latest release of Android Studio 3.0 (canary and stable), they have organized this file structure. For every flavour dimension, whenever you sign an APK, it will have a separate folder with a corresponding output.json file in it. This file is actually nothing but a description of the source APK. As you can see, the file you shared here is describing the released APK.

Solution 2 - Android

ouput.json file is kind of a metadata file for your generated APK. This file is generated due to various reasons. I have found some of them, which might not list all of the use cases, but here's the list:

  1. Generated when Generate Signed APK is executed

  2. Generated for AndroidManifest.xml file under

    {module}/build/intermediates/manifest/androidTest/debug/ouput.json
    
  3. It is not generated for Unit tests, but only generated for AndroidTests (which depends on Android framework to be executed)

  4. The file output.json generated for AndroidManifest.xml at above specified location is slightly different from the one generated for APK as you have mentioned.

  5. As you can see the properties described by output.json file is very similar to the properties that we usually specify in our build.gradle file, so it must be used & required for build process to work successfully (or it might be getting generated as a result of successful build and extracting of required properties from build.gradle).

Upon this, we can conclude that it surely depends upon Android framework to be generated & it is related to be describing the details/info about the APK or Manifest file.

  • I have personally tried to Google & find a proper answer to this even on Android Developers website, but it seems nothing is documented about this file in detail.

  • I have checked several projects on GitHub & checked .gitignore file for the same, I couldn't find any of the similar output.json file in any of the projects hosted on GitHub. So it should be a good practice to exclude them in your commits.

  • In short, this file is a descriptive file containing important metadata about project. It must be there for a reason. I would suggest you not to mess with it as we don't know what it may result in.

Solution 3 - Android

For anyone who want to disable this feature, here is my trick.
It simply delete output.json after generation.

applicationVariants.all { variant ->
    variant.assemble.doLast {
        def buildType = variant.buildType.name
        def outputPath = ""

        // If you use separated output path for both condition.
        if (buildType == "debug") {
            outputPath = "${buildDir}/outputs/apk"
        }
        if (buildType == "release") {
            outputPath = "${rootDir}/apk"
        }
        println "outputPath:" + outputPath

        delete "${outputPath}/yourFlavor1/${buildType}/output.json"
        delete "${outputPath}/yourFlavor2/${buildType}/output.json"
        delete "${outputPath}/yourFlavor.../${buildType}/output.json"
    }
}

Solution 4 - Android

In Android Studio 4.0 a new file appears after succesful build (apk or aab): app/release/output-metadata.json. In order not to annoy with it in Git, just add to <project>/.gitignore:

# Metadata created after successful build.
/app/release/output-metadata.json

Solution 5 - Android

In response to the elaborate answer by @wonsuc, you can have gradle remove the file upon a successful build by adding the following code to the android section:

android {
    ...
    applicationVariants.all { variant ->
        variant.assemble.doLast {
            variant.outputs.each { output ->
                delete "${output.outputFile.parent}/output*.json"
            }
        }
    }
}

Solution 6 - Android

With previous versions of Android Studio, I had attempted to automatically name the output apk based on the output of git describe. However, while "Syncing Project with Gradle Files" Android Studio would run the gradle script once and capture the build config, including the output filename, and then assume that every build would continue to use the same name.

So whenever I created a new commit, the actual output filename would change. But Android Studio would either install the old version or fail if it had been cleaned up.

I believe that output.json has been added to allow Android Studio to load everything it needs to know about the last build, even if you have customised your gradle script to change something in an unexpected way.

This change isn't specifically mentioned in the gradle plugin release notes (https://developer.android.com/studio/releases/gradle-plugin.html#3-0-0). Though they did make a bunch of drastic changes for performance reasons. It makes sense to me that they would prefer to run less of your gradle script when syncing. Instead capturing information about the build outputs directly from the build process.

Solution 7 - Android

I add ../../ to the beginning of the outputFileName, and the APK file is put into the output folder

android{
    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            output.outputFileName =   "../../output_name.apk"
        }
    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSahView Question on Stackoverflow
Solution 1 - AndroidWubbalubbadubdubView Answer on Stackoverflow
Solution 2 - AndroidSneh PandyaView Answer on Stackoverflow
Solution 3 - AndroidwonsucView Answer on Stackoverflow
Solution 4 - AndroidCoolMindView Answer on Stackoverflow
Solution 5 - AndroidAbandoned CartView Answer on Stackoverflow
Solution 6 - AndroidJeremy LakemanView Answer on Stackoverflow
Solution 7 - AndroidZengLHView Answer on Stackoverflow