question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VersionCodeMissingException - Gradle

See original GitHub issue

Describe 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
NathanRussakcommented, Jan 8, 2019

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!

0reactions
ambesshcommented, Oct 12, 2021

@suryagopal try building .aab from android studio .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: "Version code not found in manifest." - Stack Overflow
For me, Error was in my build.gradle that I was trying to generate VersionCode dynamically. For that I need to add a method...
Read more >
Version your app - Android Developers
Set app version information. To define the version information for your app, set values for the version settings in the Gradle build files:....
Read more >
Manage your Android app's versionCode & versionName with ...
Manage your Android app's versionCode & versionName with Gradle · Don't repeat yourself. · Define individual components of the version number. · Compute...
Read more >
[SOLVED] Error: "Version code not found in manifest." - JTuto
ManifestVersionException$VersionCodeMissingException: Version code not found in manifest.” ... Add the versionCode to your gradle. Something like below…
Read more >
bundletool | line tool to manipulate Android App Bundles - kandi
buildscript { repositories { google() mavenCentral() //add this line jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' // Doesn't ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found