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

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": ""
  }
}]

Solution 1:

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:

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.