public static class ApkSigner.Builder extends 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(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(String createdBy)
Sets the value of the
Created-By field in JAR signature files. |
ApkSigner.Builder |
setInputApk(DataSource inputApk)
Sets the APK to be signed.
|
ApkSigner.Builder |
setInputApk(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(File outputApk)
Sets the location of the output (signed) 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).
|
public Builder(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 setInputApk(File inputApk)
setInputApk(DataSource)
public ApkSigner.Builder setInputApk(DataSource inputApk)
setInputApk(File)
public ApkSigner.Builder setOutputApk(File outputApk)
ApkSigner
will create this file if
it doesn't exist.setOutputApk(DataSink, DataSource)
public ApkSigner.Builder setOutputApk(DataSink outputApkOut, DataSource outputApkIn)
outputApkOut
sink must be visible through the outputApkIn
data source.setOutputApk(File)
public ApkSigner.Builder setMinSdkVersion(int minSdkVersion)
android:minSdkVersion
attribute of the APK's AndroidManifest.xml
. For example, the default behavior
refuses to handle APKs whose AndroidManifest.xml
specifies minSdkVersion
as a codename (e.g., "N") rather than an integer.
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
.
IllegalStateException
- if this builder was initialized with an
ApkSignerEngine
public 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.IllegalStateException
- if this builder was initialized with an
ApkSignerEngine
public 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.IllegalStateException
- if this builder was 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
.
IllegalStateException
- if this builder was initialized with an
ApkSignerEngine
public ApkSigner.Builder setCreatedBy(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
.
IllegalStateException
- if this builder was initialized with an
ApkSignerEngine
public ApkSigner build()
ApkSigner
instance initialized according to the configuration of
this builder.Copyright © 2016. All rights reserved.