简体   繁体   English

bundletool build-bundle 错误:[BT:1.8.2] 错误:在清单中找不到版本代码

[英]bundletool build-bundle error: [BT:1.8.2] Error: Version code not found in manifest

I am trying to turn an apk into aab, decompile with apktool, and build with aapt2 and bundletool (all in command line, without gradle).我正在尝试将 apk 转换为 aab,使用 apktool 反编译,并使用 aapt2 和 bundletool 构建(全部在命令行中,没有 gradle)。

After decompile, aapt2 compile and link looks good, but when I execute build-bundle with bundletool, I got this error.反编译后,aapt2 编译和链接看起来不错,但是当我用 bundletool 执行 build-bundle 时,我得到了这个错误。 What went wrong?什么地方出了错? And How can i fix it?我该如何解决?

# 1. Decompile apk and copy res[folder] and Androidmanifest.xml into $HOME/apk2aa/temp_dir
apktool d input.apk

# 2. “Compile” all resources using aapt2
aapt2 compile  --dir input/res -o "${APPROOT}/temp_dir/compiled_resources"

# 3. “Link” the resources into a temporary APK, generating the R.java file along the way and converting the resources into protobuf format:
aapt2 link --proto-format -o temporary.apk -I "${SDK}/platforms/android-29/android.jar" --manifest input/AndroidManifest.xml -R compiled_resources/*.flat  --auto-add-overlay --java gen

I then generate a zip (base.zip) from a folder with the same structure as described here: https://developer.android.com/studio/build/building-cmdline#package_pre-compiled_code_and_resources然后,我从具有与此处描述的相同结构的文件夹生成 zip (base.zip): https://developer.android.com/studio/build/building-and_cmdline

# 4. Use bundletool build-bundle command to create aab
java -jar "${APPROOT}/bundletool.jar" build-bundle --modules=base.zip --output=output.aab

Log:日志:

[BT:1.8.2] Error: Version code not found in manifest.
com.android.tools.build.bundletool.model.exceptions.InvalidVersionCodeException: Version code not found in manifest.
        at com.android.tools.build.bundletool.model.exceptions.InvalidVersionCodeException.createMissingVersionCodeException(InvalidVersionCodeException.java:29)
...

The AndroidManifest.xml produced by apktool is missing android:versionCode tag as it can be seen here:由 apktool 生成的 AndroidManifest.xml 缺少 android:versionCode 标签,如下所示:

<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" android:compileSdkVersion="30" android:compileSdkVersionCodename="11" package="com.hairlight.mediapipe.apps.hairsegmentationgpu" platformBuildVersionCode="30" platformBuildVersionName="11">
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-feature android:name="android.hardware.camera"/>
    <application android:allowBackup="true" android:appComponentFactory="androidx.core.app.CoreComponentFactory" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
        <activity android:exported="true" android:name="com.hairlight.mediapipe.apps.basic.MainActivity" android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

The apktool.yml file has the versionCode apktool.yml 文件具有 versionCode

!!brut.androlib.meta.MetaInfo
apkFileName: input.apk
compressionType: false
doNotCompress:
- resources.arsc
- png
- assets/empty_asset_generated_by_bazel~
isFrameworkApk: false
packageInfo:
  forcedPackageId: '127'
  renameManifestPackage: null
sdkInfo:
  minSdkVersion: '21'
  targetSdkVersion: '30'
sharedLibrary: false
sparseResources: false
unknownFiles: {}
usesFramework:
  ids:
  - 1
  tag: null
version: 2.6.0
versionInfo:
  versionCode: '8'
  versionName: 1.0.0

The original AndroidManifest.xml file has the tag as well.原始的 AndroidManifest.xml 文件也有标签。 So, apktool finds the versionCode and then strips it from the AndroidManifest.xml and puts it in a yml file.因此,apktool 找到 versionCode,然后将其从 AndroidManifest.xml 中剥离,并将其放入 yml 文件中。 How do I ensure that apktool leaves the versionCode in AndroidManifest.xml?如何确保 apktool 将 versionCode 保留在 AndroidManifest.xml 中?

Any help would be appreciated.任何帮助,将不胜感激。

Versions I used are: aapt2-7.2.0-alpha07-7984345-linux.jar, bundletool-all-1.8.2.jar, build-tools 29.0.2, platform version 29, javac 1.8.0_312, apktool_2.6.0.jar Versions I used are: aapt2-7.2.0-alpha07-7984345-linux.jar, bundletool-all-1.8.2.jar, build-tools 29.0.2, platform version 29, javac 1.8.0_312, apktool_2.6.0.jar

I have found a solution to my own problem.我找到了解决我自己问题的方法。 I can provide -m flag to decompile code like this:我可以提供-m标志来反编译这样的代码:

apktool d -m input.apk 

This flag will ensure to match original file and avoid stripping versionCode and versionName from AndroidManifest.xml此标志将确保匹配原始文件并避免从 AndroidManifest.xml 中剥离 versionCode 和 versionName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM