bundletool icon indicating copy to clipboard operation
bundletool copied to clipboard

Error: Version must match the format '<major>.<minor>.<revision>[-<qualifier>]', but found '0.0.0/'

Open littledog623 opened this issue 2 years ago • 2 comments
trafficstars

Version of bundle: 1.15.0

[BT:1.15.0] Error: Version must match the format '..[-]', but found '0.0.0/'. java.lang.IllegalArgumentException: Version must match the format '..[-]', but found '0.0.0/'. at com.google.common.base.Preconditions.checkArgument(Preconditions.java:220) at com.android.tools.build.bundletool.model.version.Version.of(Version.java:67) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566) at com.android.tools.build.bundletool.archive.ArchivedResourcesHelper.findArchivedClassesDexPath(ArchivedResourcesHelper.java:105) at com.android.tools.build.bundletool.transparency.CodeTransparencyFactory.createArchivedCodeRelatedFile(CodeTransparencyFactory.java:72) at com.android.tools.build.bundletool.transparency.CodeTransparencyFactory.createCodeTransparencyMetadata(CodeTransparencyFactory.java:56) at com.android.tools.build.bundletool.commands.AddTransparencyCommand.executeGenerateCodeTransparencyFileMode(AddTransparencyCommand.java:341) at com.android.tools.build.bundletool.commands.AddTransparencyCommand.execute(AddTransparencyCommand.java:282) at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:138) at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:55)

Repro steps: I cannot repro this locally, but I am able to repro this on Azure Devops pipeline. I suspect that this is caused by some weird behavior of the Windows pipeline agent that I am using. The path to /com/android/tools/build/bundletool/archive/dex/0_0_0 contains a trailing slash somehow on some operating systems, so eventually the version is parse as "0.0.0/" instead of "0.0.0". Can we add some extra logic to remove the slash from the path to the dex resource files?

Bundletool command that I used: java -jar bundletool-1.15.0-all.jar add-transparency --mode=generate_code_transparency_file --bundle=app-release.aab --output=code_transparency_file.jwt --transparency-key-certificate=certificate.p7b

Apologize for providing less details on the command and dependent files.

I've got an example Pull Request to resolve this issue: #332

littledog623 avatar May 23 '23 08:05 littledog623

My team also encounter similar issues on trailing slash. We're using Windows virtual machine deployed on Azure.

One obvious solution is to extract the trailing slash in Version class. Or we can add one more step like .map(path -> path.replaceAll("/\z", "")), or change the pattern to + "/?$"

Another possible reason is that I noticed we use $ in VERSION_REGEXP to mark the end of regex, however, in Java's regular expression engine, the $ character has a slightly different meaning. It matches the end of a line, which is technically the position right before a newline character at the end of the string. This means that if your string has a trailing newline, $ will match the position right before that newline, not the very end of the string.

First way resolved my issue, and I plan to testify the second solution as well.

lifesaver0129 avatar May 23 '23 12:05 lifesaver0129

Thank you for the PR I'm fine to merge it but as I see it is still in draft. Did it solve your problem or not?

ymakhno avatar Aug 09 '23 22:08 ymakhno