public static class ApkSigner.Builder
extends java.lang.Object
ApkSigner instances.
The builder requires the following information to construct a working ApkSigner:
ApkSignerEngine -- provided in the constructor,
setInputApk variants,
setOutputApk
variants.
| Constructor and Description |
|---|
Builder(ApkSignerEngine signerEngine)
Constructs a new
Builder for an ApkSigner which signs using the provided
signing engine. |
Builder(java.util.List<ApkSigner.SignerConfig> signerConfigs)
Constructs a new
Builder for an ApkSigner which signs using the provided
signer configurations. |
| Modifier and Type | Method and Description |
|---|---|
ApkSigner |
build()
Returns a new
ApkSigner instance initialized according to the configuration of
this builder. |
ApkSigner.Builder |
setCreatedBy(java.lang.String createdBy)
Sets the value of the
Created-By field in JAR signature files. |
ApkSigner.Builder |
setDebuggableApkPermitted(boolean permitted)
Sets whether the APK should be signed even if it is marked as debuggable (
android:debuggable="true" in its AndroidManifest.xml). |
ApkSigner.Builder |
setInputApk(DataSource inputApk)
Sets the APK to be signed.
|
ApkSigner.Builder |
setInputApk(java.io.File inputApk)
Sets the APK to be signed.
|
ApkSigner.Builder |
setMinSdkVersion(int minSdkVersion)
Sets the minimum Android platform version (API Level) on which APK signatures produced by
the signer being built must verify.
|
ApkSigner.Builder |
setOtherSignersSignaturesPreserved(boolean preserved)
Sets whether signatures produced by signers other than the ones configured in this engine
should be copied from the input APK to the output APK.
|
ApkSigner.Builder |
setOutputApk(DataSink outputApkOut,
DataSource outputApkIn)
Sets the sink which will receive the output (signed) APK.
|
ApkSigner.Builder |
setOutputApk(java.io.File outputApk)
Sets the location of the output (signed) APK.
|
ApkSigner.Builder |
setOutputApk(ReadableDataSink outputApk)
Sets the readable data sink which will receive the output (signed) APK.
|
ApkSigner.Builder |
setSigningCertificateLineage(SigningCertificateLineage signingCertificateLineage)
Sets the
SigningCertificateLineage to use with the v3 signature scheme. |
ApkSigner.Builder |
setSourceStampSignerConfig(ApkSigner.SignerConfig sourceStampSignerConfig)
Sets the signing configuration of the source stamp to be embedded in the APK.
|
ApkSigner.Builder |
setV1SigningEnabled(boolean enabled)
Sets whether the APK should be signed using JAR signing (aka v1 signature scheme).
|
ApkSigner.Builder |
setV2SigningEnabled(boolean enabled)
Sets whether the APK should be signed using APK Signature Scheme v2 (aka v2 signature
scheme).
|
ApkSigner.Builder |
setV3SigningEnabled(boolean enabled)
Sets whether the APK should be signed using APK Signature Scheme v3 (aka v3 signature
scheme).
|
ApkSigner.Builder |
setV4ErrorReportingEnabled(boolean enabled)
Sets whether errors during v4 signing should be reported and halt the signing process.
|
ApkSigner.Builder |
setV4SignatureOutputFile(java.io.File v4SignatureOutputFile)
Sets the location of the V4 output file.
|
ApkSigner.Builder |
setV4SigningEnabled(boolean enabled)
Sets whether the APK should be signed using APK Signature Scheme v4.
|
public Builder(java.util.List<ApkSigner.SignerConfig> signerConfigs)
Builder for an ApkSigner which signs using the provided
signer configurations. The resulting signer may be further customized through this
builder's setters, such as setMinSdkVersion(int), setV1SigningEnabled(boolean), setV2SigningEnabled(boolean), setOtherSignersSignaturesPreserved(boolean), setCreatedBy(String).
#Builder(ApkSignerEngine) is an alternative for advanced use cases where more
control over low-level details of signing is desired.
public Builder(ApkSignerEngine signerEngine)
Builder for an ApkSigner which signs using the provided
signing engine. This is meant for advanced use cases where more control is needed over
the lower-level details of signing. For typical use cases, #Builder(List) is more
appropriate.public ApkSigner.Builder setSourceStampSignerConfig(ApkSigner.SignerConfig sourceStampSignerConfig)
public ApkSigner.Builder setInputApk(java.io.File inputApk)
setInputApk(DataSource)public ApkSigner.Builder setInputApk(DataSource inputApk)
setInputApk(File)public ApkSigner.Builder setOutputApk(java.io.File outputApk)
ApkSigner will create this file if
it doesn't exist.public ApkSigner.Builder setOutputApk(ReadableDataSink outputApk)
DataSource interface of
the sink.
This variant of setOutputApk is useful for avoiding writing the output APK to
a file. For example, an in-memory data sink, such as DataSinks.newInMemoryDataSink(), could be used instead of a file.
public ApkSigner.Builder setOutputApk(DataSink outputApkOut, DataSource outputApkIn)
outputApkOut sink must be visible through the outputApkIn data source.
This is an advanced variant of setOutputApk(ReadableDataSink), enabling the
sink and the source to be different objects.
setOutputApk(ReadableDataSink),
setOutputApk(File)public ApkSigner.Builder setV4SignatureOutputFile(java.io.File v4SignatureOutputFile)
ApkSigner will create this file if it
doesn't exist.public ApkSigner.Builder setMinSdkVersion(int minSdkVersion)
android:minSdkVersion
attribute of the APK's AndroidManifest.xml.
Note: This method may result in APK signatures which don't verify on some Android platform versions supported by the APK.
Note: This method may only be invoked when this builder is not initialized
with an ApkSignerEngine.
java.lang.IllegalStateException - if this builder was initialized with an ApkSignerEnginepublic ApkSigner.Builder setV1SigningEnabled(boolean enabled)
By default, whether APK is signed using JAR signing is determined by ApkSigner, based on the platform versions supported by the APK or specified using setMinSdkVersion(int). Disabling JAR signing will result in APK signatures which don't
verify on Android Marshmallow (Android 6.0, API Level 23) and lower.
Note: This method may only be invoked when this builder is not initialized
with an ApkSignerEngine.
enabled - true to require the APK to be signed using JAR signing, false to require the APK to not be signed using JAR signing.java.lang.IllegalStateException - if this builder was initialized with an ApkSignerEnginepublic ApkSigner.Builder setV2SigningEnabled(boolean enabled)
By default, whether APK is signed using APK Signature Scheme v2 is determined by
ApkSigner based on the platform versions supported by the APK or specified using
setMinSdkVersion(int).
Note: This method may only be invoked when this builder is not initialized
with an ApkSignerEngine.
enabled - true to require the APK to be signed using APK Signature Scheme
v2, false to require the APK to not be signed using APK Signature Scheme v2.java.lang.IllegalStateException - if this builder was initialized with an ApkSignerEnginepublic ApkSigner.Builder setV3SigningEnabled(boolean enabled)
By default, whether APK is signed using APK Signature Scheme v3 is determined by
ApkSigner based on the platform versions supported by the APK or specified using
setMinSdkVersion(int).
Note: This method may only be invoked when this builder is not initialized
with an ApkSignerEngine.
Note: APK Signature Scheme v3 only supports a single signing certificate, but may take multiple signers mapping to different targeted platform versions.
enabled - true to require the APK to be signed using APK Signature Scheme
v3, false to require the APK to not be signed using APK Signature Scheme v3.java.lang.IllegalStateException - if this builder was initialized with an ApkSignerEnginepublic ApkSigner.Builder setV4SigningEnabled(boolean enabled)
V4 signing requires that the APK be v2 or v3 signed.
enabled - true to require the APK to be signed using APK Signature Scheme v2
or v3 and generate an v4 signature filepublic ApkSigner.Builder setV4ErrorReportingEnabled(boolean enabled)
Error reporting for v4 signing is disabled by default, but will be enabled if the
caller invokes setV4SigningEnabled(boolean) with a value of true. This method is useful
for tools that enable v4 signing by default but don't want to fail the signing process if
the user did not explicitly request the v4 signing.
enabled - false to prevent errors encountered during the V4 signing from
halting the signing processpublic ApkSigner.Builder setDebuggableApkPermitted(boolean permitted)
android:debuggable="true" in its AndroidManifest.xml). For backward
compatibility reasons, the default value of this setting is true.
It is dangerous to sign debuggable APKs with production/release keys because Android platform loosens security checks for such APKs. For example, arbitrary unauthorized code may be executed in the context of such an app by anybody with ADB shell access.
Note: This method may only be invoked when this builder is not initialized
with an ApkSignerEngine.
public ApkSigner.Builder setOtherSignersSignaturesPreserved(boolean preserved)
By default, signatures of other signers are omitted from the output APK.
Note: This method may only be invoked when this builder is not initialized
with an ApkSignerEngine.
java.lang.IllegalStateException - if this builder was initialized with an ApkSignerEnginepublic ApkSigner.Builder setCreatedBy(java.lang.String createdBy)
Created-By field in JAR signature files.
Note: This method may only be invoked when this builder is not initialized
with an ApkSignerEngine.
java.lang.IllegalStateException - if this builder was initialized with an ApkSignerEnginepublic ApkSigner.Builder setSigningCertificateLineage(SigningCertificateLineage signingCertificateLineage)
SigningCertificateLineage to use with the v3 signature scheme. This
structure provides proof of signing certificate rotation linking ApkSigner.SignerConfig
objects to previous ones.public ApkSigner build()
ApkSigner instance initialized according to the configuration of
this builder.