我正试图将apk转换为aab,使用apktool进行反编译,并使用aapt2和bundletool进行构建(全部在命令行中,没有gradle(。
反编译后,aapt2编译和链接看起来不错,但当我使用bundletool执行构建捆绑包时,我出现了这个错误。出了什么问题?我该怎么修?
# 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
然后,我从一个文件夹中生成一个zip(base.zip(,该文件夹的结构与这里描述的相同: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
日志:
[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)
...
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>
apktool.yml文件的版本代码为
!!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
原始的AndroidManifest.xml文件也有标记。因此,apktool找到versionCode,然后将其从AndroidManifest.xml中剥离,并将其放入yml文件中。如何确保apktool将versionCode留在AndroidManifest.xml中?
如有任何帮助,我们将不胜感激。
我使用的版本是:aapt2-7.2.0-alpha07-7984345-linux.jar,bundletool-all-1.8.2.jar,构建工具29.0.2,平台版本29,javac 1.8.0_312,apktool_2.6.0.jar
我找到了自己问题的解决方案。我可以提供-m
标志来反编译这样的代码:
apktool d -m input.apk
此标志将确保与原始文件匹配,并避免从AndroidManifest.xml 中剥离versionCode和versionName