I am trying to turn an apk into aab, decompile with apktool, and build with aapt2 and bundletool (all in command line, without gradle).
After decompile, aapt2 compile and link looks good, but when I execute build-bundle with bundletool, I got this error. What went wrong? And How ow can i fix it?
F:\>java -jar "F:\tool\common\bundletool.jar" build-bundle --modules="F:\_workspace\20210714\decompile\base.zip" --output="F:\_workspace\20210714\decompile\base.aab"
[BT:1.7.0] Error: com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag.
java.io.UncheckedIOException: com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag.
at com.android.tools.build.bundletool.model.BundleModule$Builder.addEntry(BundleModule.java:357)
at com.android.tools.build.bundletool.model.BundleModule$Builder.addEntries(BundleModule.java:339)
at com.android.tools.build.bundletool.validation.BundleModulesValidator.toBundleModule(BundleModulesValidator.java:94)
at com.android.tools.build.bundletool.validation.BundleModulesValidator.lambda$validate$0(BundleModulesValidator.java:79)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Collections$2.tryAdvance(Collections.java:4719)
at java.util.Collections$2.forEachRemaining(Collections.java:4727)
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.validation.BundleModulesValidator.validate(BundleModulesValidator.java:80)
at com.android.tools.build.bundletool.commands.BuildBundleCommand.execute(BuildBundleCommand.java:231)
at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:73)
at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:49)
Caused by: com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag.
at com.google.protobuf.InvalidProtocolBufferException.invalidEndTag(InvalidProtocolBufferException.java:106)
at com.google.protobuf.CodedInputStream$StreamDecoder.checkLastTagWas(CodedInputStream.java:2076)
at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:217)
at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:232)
at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:237)
at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:48)
at com.google.protobuf.GeneratedMessageV3.parseWithIOException(GeneratedMessageV3.java:347)
at com.android.aapt.Resources$XmlNode.parseFrom(Resources.java:44493)
at com.android.tools.build.bundletool.model.BundleModule$SpecialModuleEntry$1.addToModule(BundleModule.java:386)
at com.android.tools.build.bundletool.model.BundleModule$Builder.addEntry(BundleModule.java:355)
... 15 more
Seems like it's talking about the protobuf format (not sure if I'm right), but I do add "--proto-format" in my command.
Details of what I did:
compile the resources using aapt2:
"F:\tool\common\aapt2.exe" compile --dir "F:\_workspace\20210714\decompile\res" -v -o "F:\_workspace\20210714\decompile\compiled_resources.zip"
then link:
"F:\tool\common\aapt2.exe" link --proto-format "F:\_workspace\20210714\decompile\compiled_resources.zip" -v -o "F:\_workspace\20210714\decompile\base.apk" -I "F:\tool\common\android.jar" --manifest "F:\_workspace\20210714\decompile\AndroidManifest.xml"
unzip the base.apk, move other files into position (I did it according to bundletool's documentation), than zip again, name base.zip.
then do build-bundle, which has been mentioned in the beginning, and got that error:
"F:\tool\common\bundletool.jar" build-bundle --modules="F:\_workspace\20210714\decompile\base.zip" --output="F:\_workspace\20210714\decompile\base.aab"
The code and resources are decompiled from an apk which works well, dependencies should be good, and recompiling these into apk again can be done successfully. By the way, I use smali.jar to convert smali files into dex for bundletool.
The version of tools I am using:
aapt2.exe 7.0.0-beta05-7396180
bundletool.jar 1.7.0
apktool.jar 2.5.0
smali.jar 2.4.0
So the other day i fix this by myself. It is because i put the wrong manifeat file in place. The file in "base.zip/manifest/AndroidManifest.xml" should be proto-format, which is produce by aapt2 in link process, you can find it inside the apk generate by aapt2.
And yes, decompile an apk and use bundletool to turn it into an aab is possible.