Anti-AIClone

Log date · Mon

Does an Android APK need signing after transformation?

Published on · Updated

Yes. Finish transformation and alignment before signing, verify the final APK, and test updates through the intended channel.

The answer: sign after changes and check identity

Yes. Sign an APK after its contents change, and check that the identity on the final distributed package is compatible with the existing update path. In our JAR comparison with two throwaway keys, the original verified; changing one signed entry made verification fail with exit code 1. A rebuilt archive signed with the second key verified, but had a different signer.

These are separate checks. A valid signature establishes a match between signed content and signature; it does not by itself establish that an existing installation can be updated. Android requires APKs to be signed before installation or update. [1]

Questions and findings
QuestionFinding
Change content after signing?The sample entry failed its digest check; exit 1.
Sign again with another key?The new archive verified, with Second instead of First as signer.
Will a real update work?Test the delivery channel and devices; verification alone is insufficient.

The experiment: sign, modify, sign again

On macOS we used OpenJDK 17.0.19 jar, keytool and jarsigner to create an archive containing config.txt and two throwaway 2048-bit RSA keys. The experiment runs on a JAR, not an APK; this environment has no Android SDK apksigner and we did not install on a device. The APK commands below are unexecuted examples from the documentation.

After signing with the first key, jarsigner verified the entry and displayed the signer. The certificate was self-signed; the tool also warned that the certificate chain was untrusted and the signature had no timestamp. “jar verified” is not an endorsement of certificate trust. Oracle says -strict treats severe warnings as errors. [4]

Verification excerpt for the first archive.
- Signed by "CN=Demo First"
    Digest algorithm: SHA-256
    Signature algorithm: SHA256withRSA, 2048-bit key

jar verified.

We copied the signed archive and changed config.txt from 17 to 20 bytes. The verifier reported a SHA-256 digest error for that entry. The exit code below comes from the command itself.

Complete result after the modification.
== modify one signed entry ==
jarsigner: java.lang.SecurityException: SHA-256 digest error for config.txt
modified verification exit: 1

We then built a fresh archive from the changed content and signed it with the second key. It verified and reported CN=Demo Second; keytool also showed different SHA-256 certificate fingerprints. Repeating the experiment generates new keys and fingerprints, as intended.

Verification excerpt for the second archive.
- Signed by "CN=Demo Second"
    Digest algorithm: SHA-256
    Signature algorithm: SHA256withRSA, 2048-bit key

jar verified.

Do not use the sample password for a production key or put production credentials in shared command logs.

How the JAR comparison maps to APK signing

The JAR experiment illustrates the relationship between a signature and signed content. APK v1 uses a JAR-based scheme, while APK v2 uses a different structure: its signing block sits before the ZIP central directory and protects several parts of the APK. [2][3] A jarsigner result therefore does not verify the actual APK signing schemes used by a release.

Android’s apksigner documentation explicitly says that changes after signing invalidate the APK signature, and that zipalign must run before signing. [2] Put build, code transformation, resource processing and alignment before the final signature; verify the same file intended for distribution. Any subsequent processing should trigger signing and verification again.

Record signature verification and identity checks separately. Keep the certificate fingerprint, build identifier and channel, rather than just a “pass” label. Compare certificates serving the same role and account for any approved signing rotation. A displayed certificate name alone is not a complete continuity check.

Play upload and distribution keys

Play App Signing has two distinct roles: the developer holds the upload key, Google checks uploads against the upload certificate, and Google signs APKs delivered to devices with the app signing key. [1] A successful AAB upload or a matching upload certificate is not the same check as inspecting the signing identity of the APK delivered to a device.

If the upload key is lost or compromised, the documentation provides an upload-key reset process while Play retains the app signing key. An app signing key upgrade is a separate operation: assess device versions and distribution channels using the official process. [1] Arbitrarily switching keys as we did in the sample is not a release rotation plan, and channels should not be assumed to share an identity automatically.

For a self-distributed APK, establish who signs it, where the controlled key is held and which certificate signed the previous release. If stores use different signing identities, maintain separate baselines and update tests; success in one channel does not establish success in another.

Recommendations by release case

The following are release-process recommendations, not device behavior measured in the JAR experiment. Identify the final artifact and signing owner before choosing where to verify.

Recommendations by release case
CaseRecommendation
Transformed self-distributed APKFinish transformation and alignment, sign in the controlled release process, then verify and compare the release certificate.
Play App BundleUse the correct upload identity; separately check the app signing certificate on Play-delivered APKs.
Planned signing-key changeFollow the channel’s rotation process and assess older-device compatibility before release.
Artifact returned by a processorSpecify APK or AAB, signing responsibility and remaining changes; keep keys in a controlled environment.

During acceptance, check the package name and version code too: a correct signature does not establish that the candidate is the intended build. Retain provenance for the old and candidate versions so testers can reproduce the actual update sequence. If the channel generates multiple APKs, inspect the artifact actually delivered for each representative device configuration.

At handoff, record the input version, output file, processing steps and signing point. If verification fails, the team can first locate writes after signing instead of blindly replacing a key. In automation, make post-signing verification a release gate and retain the result for the file actually delivered.

Check your APK and update path

After installing Android SDK Build Tools, run this read-only check on the final APK. Substitute your own path; --print-certs displays signing certificate digests. Check both the expected certificate and the verification result, including the supported minimum platform configuration. [2]

Not executed: inspect the final APK with Android SDK tools.
apksigner verify --verbose --print-certs path/to/release.apk

When signing yourself, finish changes and alignment first, then sign in a controlled environment with the correct key. This is the documented command form. Signing overwrites the input by default, so retain the unsigned build or use --out for a new file; enter passwords securely when prompted. [2]

Not executed: sign and verify; replace paths and use your controlled key.
apksigner sign --ks path/to/release.jks --out release-signed.apk path/to/aligned.apk
apksigner verify --verbose --print-certs release-signed.apk

Finally install the existing production version from the intended channel on test devices, then update to the candidate through that same channel. Check in-place installation, retained data, permissions and critical flows across supported platform versions and any planned signing rotation. Record the channel, old and new versions, certificates and results. Stop the release and investigate if an update is incompatible.

Your checklist

  • Identify the artifact, channel and signing owner.
  • Finish transformation and alignment before final signing.
  • Verify the final APK and compare its channel-specific certificate fingerprint.
  • Distinguish the Play upload key from the app signing key.
  • Test an in-place update from the existing release and check retained data.

Primary sources

All sources and reproduction status ↗