简体   繁体   中英

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).

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 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

# 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:

<?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

!!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. So, apktool finds the versionCode and then strips it from the AndroidManifest.xml and puts it in a yml file. How do I ensure that apktool leaves the versionCode in 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

I have found a solution to my own problem. I can provide -m flag to decompile code like this:

apktool d -m input.apk 

This flag will ensure to match original file and avoid stripping versionCode and versionName from AndroidManifest.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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