VersionCodeMissingException - Gradle
See original GitHub issueDescribe the bug
I’m not sure if this problem originates when Android Studio generates a .aab
or when bundletool attempts to generate a .apks
but I figured this was the best place to ask.
I’m currently exploring adding app bundle support to an application that I maintain but whenever I attempt to generate a .apks
via bundletool I get the following error:
com.android.tools.build.bundletool.exceptions.manifest.ManifestVersionException$VersionCodeMissingException: Version code not found in manifest.
at com.android.tools.build.bundletool.model.AndroidManifest.lambda$getVersionCode$15(AndroidManifest.java:288)
at java.base/java.util.Optional.orElseThrow(Optional.java:397)
at com.android.tools.build.bundletool.model.AndroidManifest.getVersionCode(AndroidManifest.java:288)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.Collections$2.tryAdvance(Collections.java:4727)
at java.base/java.util.Collections$2.forEachRemaining(Collections.java:4735)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
at com.android.tools.build.bundletool.validation.AndroidManifestValidator.validateSameVersionCode(AndroidManifestValidator.java:58)
at com.android.tools.build.bundletool.validation.AndroidManifestValidator.validateAllModules(AndroidManifestValidator.java:47)
at com.android.tools.build.bundletool.validation.ValidatorRunner.validateBundleModulesUsingSubValidator(ValidatorRunner.java:75)
at com.android.tools.build.bundletool.validation.ValidatorRunner.validateBundleUsingSubValidator(ValidatorRunner.java:69)
at com.android.tools.build.bundletool.validation.ValidatorRunner.lambda$validateBundle$3(ValidatorRunner.java:58)
at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:406)
at com.android.tools.build.bundletool.validation.ValidatorRunner.validateBundle(ValidatorRunner.java:58)
at com.android.tools.build.bundletool.validation.AppBundleValidator.validate(AppBundleValidator.java:73)
at com.android.tools.build.bundletool.commands.BuildApksManager.execute(BuildApksManager.java:97)
at com.android.tools.build.bundletool.io.TempFiles.withTempDirectoryReturning(TempFiles.java:52)
at com.android.tools.build.bundletool.commands.BuildApksCommand.execute(BuildApksCommand.java:439)
at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:77)
at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:47)
This is not a new project. It has been used to generate and publish traditional APKs for many years now. The version code is currently defined in the build.gradle
file like so…
android {
...
defaultConfig {
versionCode VERSION_CODE_HERE
versionName VERSION_NAME_HERE
...
}
...
}
The only way I’ve been able to get around this exception is to add version info to the project’s manifest like so…
<?xml version="1.0" encoding="UTF-8"?>
<manifest package="com.example.package"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:versionCode="VERSION_CODE_HERE"
android:versionName="VERSION_NAME_HERE">
...
</manifest>
It feels weird to have to reintroduce version info into the project’s manifest. Is this behavior intentional or is this the result of a bug somewhere in the build process or my project setup? Any help would be greatly appreciated!
A few additional details:
.aab
generated by Android Studio 3.2.1 Build #AI-181.5540.7.32.5056338- Bundletool command used when attempting to generate
.apks
:bundletool build-apks --bundle=./bundle.aab --output=./output.apks
(additional key signing params used but omitted here)
Bundletool version(s) affected Version: 0.7.2
Stacktrace Provided in above description.
To Reproduce Provided in above description.
Expected behavior bundletool should generate a .apks from the project’s .aab.
Known workaround Provided in above description.
Environment: OS: MacOS
Additional context N/A
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (2 by maintainers)
I figured I’d comment here one last time just in case anyone comes across a similar problem.
Turns out there was no bug in bundletool or the gradle plugin. Our app’s build.gradle file is configured to rely on Jenkins to provide its versionCode value. If that is not available (eg: when making local dev builds) it would fall back to a default versionCode value of 0. Apparently, when generating builds with a versionCode of 0, the versionCode is completely stripped and omitted from the build output’s manifest. This behavior can be observed both when building a traditional
.apk
and when generating the new.aab
.By changing the default to 1 it ensured that versionCode was included in all build output and bundletool was always able to successfully produce
.apks
files.Thanks again for weighing in on this and helping me out @plecesne!
@suryagopal try building .aab from android studio .