我想反编译一个现有的Android应用程序,修改后重新编译并签名,但我无法在Android 11上安装.我在Emulator上收到了这样的错误消息:

错误代码:'—124',消息='—124:在安装过程中解析失败PackageLI:目标R+(版本30及以上)需要将已安装APK的资源. arsc存储为未压缩的并在4字节边界上对齐'

我使用的方法:

Manual Process:
Step 1: Generate Keystore (only once)
You need to generate a keystore once and use it to sign your unsigned apk. Use the keytool provided by the JDK found in %JAVA_HOME%/bin/

keytool -genkey -v -keystore my.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias app
Step 2 or 4: Zipalign
zipalign which is a tool provided by the Android SDK found in e.g. %ANDROID_HOME%/sdk/build-tools/24.0.2/ is a mandatory optimization step if you want to upload the apk to the Play Store.

zipalign -p 4 my.apk my-aligned.apk
Note: when using the old jarsigner you need to zipalign AFTER signing. When using the new apksigner method you do it BEFORE signing (confusing, I know). Invoking zipalign before apksigner works fine because apksigner preserves APK alignment and compression (unlike jarsigner).

You can verify the alignment with

zipalign -c 4 my-aligned.apk
Step 3: Sign & Verify
Using build-tools 24.0.3 and newer
Android 7.0 introduces APK Signature Scheme v2, a new app-signing scheme that offers faster app install times and more protection against unauthorized alterations to APK files (See here and here for more details). Therefore, Google implemented their own apk signer called apksigner (duh!) The script file can be found in %ANDROID_HOME%/sdk/build-tools/24.0.3/ (the .jar is in the /lib subfolder). Use it like this

apksigner sign --ks-key-alias alias_name --ks my.keystore my-app.apk
and can be verified with

apksigner verify my-app.apk
The official documentation can be found here.

Using build-tools 24.0.2 and older
Use jarsigner which, like the keytool, comes with the JDK distribution found in %JAVA_HOME%/bin/ and use it like so:

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my.keystore my-app.apk my_alias_name
and can be verified with

jarsigner -verify -verbose my_application.apk

我应该用什么工具来解决这个问题呢?当我读到这篇由Android 11引起的文章时.

推荐答案

解压缩的资源.arSC

错误消息描述了您必须执行的操作:

目标R+(版本30及以上)需要将已安装的APK的资源. arsc以未压缩的方式存储,并在4字节边界上对齐.

APK文件是ZIP文件,在ZIP文件中,每个条目都可以有不同的压缩算法.在算法根本不压缩,它只是存储文件内容—你可以看到当打开ZIP/APK文件在7ZIP.有一列Method,对于未压缩存储的文件,您将找到条目Store.

在反编译/重新编译apktool时,考虑存储有压缩和不压缩的文件.重建的APK将具有与源APK文件相同的配置.

此错误表示您编辑了一个旧的APK,该APK压缩了resources.arsc,但编辑后需要有未压缩的资源. 您可以在构建重新编译的APK之前编辑apktool.yml来修改此内容.在这个文件中,你会发现一个名为resourcesAreCompressed:的条目.确保它设置为false:

resourcesAreCompressed: false  

在构建、对齐、使用apktool签署APK后,应该绕过这个错误.

然后对齐APK文件:

zipalign 4 my.apk my-aligned.apk

然后签上

apksigner sign --ks-key-alias alias_name --ks my.keystore my-aligned.apk

jarsigner

请不要再使用jarsinger(不是用于签名和验证),尤其是在apksinger之后.jarsiger已经过时,只能创建最近的Android版本不再接受的APKv1签名.apksigner在一个命令中创建v1 v2和可选的v3签名.

Android相关问答推荐

如何将结果从viewModelScope传递到活动

即使安装了Chrome和YouTube,Android对action_view a YouTube URL的意图也是空的

如何禁用Android 34+版的TileService,但保留以前的版本?

在不增加父行宽度的情况下添加延迟行或可滚动行

如何从Android 12的来电中获取电话号码?

Android可绘制边框删除底线

Android手柄注射周期错误,多个模块引用一个核心模块

在Delphi中使用OpenCV for Android在使用JLIST时抛出错误

使用 Gadle kotlin 为多模块 Android 代码库设置 jacoco

ArrayList 上的 Android intent.getParcelableArrayListExtra 引发 Nullpointer 异常

列语义在列中的第一个元素之后读取

延时kotlin中时分秒的使用方法

用作输入参数的 Lambda 函数导致重组

AirDroid Business 如何能够从屏幕截图中排除覆盖?

从活动共享视图模型以使用 hilt 组合函数

Jetpack Compose TextField 在输入新字符时不更新

如何在jetpack compose中创建水印文字效果

Kotlin 调用带参数的函数 Any is xxx ||任何 yyy 都不起作用

我的 react native 项目的发布签名 apk 没有在设备中打开,而且它创建的尺寸非常小

在 Android 10 (API 29) 中隐藏状态栏并在应用程序中使用其空间