@Test public void testWeirdZipCompressionMethod() throws Exception { List<ApkSigner.SignerConfig> signers = Collections.singletonList( getDefaultSignerConfigFromResources(FIRST_RSA_2048_SIGNER_RESOURCE_NAME)); sign("weird-compression-method.apk", new ApkSigner.Builder(signers)); }
public void sign() throws IOException, ApkFormatException, NoSuchAlgorithmException, InvalidKeyException, SignatureException, IllegalStateException { Closeable in = null; DataSource inputApk; try { if (mInputApkDataSource != null) { inputApk = mInputApkDataSource; } else if (mInputApkFile != null) { RandomAccessFile inputFile = new RandomAccessFile(mInputApkFile, "r"); in = inputFile; inputApk = DataSources.asDataSource(inputFile); } else { throw new IllegalStateException("Input APK not specified"); } Closeable out = null; try { DataSink outputApkOut; DataSource outputApkIn; if (mOutputApkDataSink != null) { outputApkOut = mOutputApkDataSink; outputApkIn = mOutputApkDataSource; } else if (mOutputApkFile != null) { RandomAccessFile outputFile = new RandomAccessFile(mOutputApkFile, "rw"); out = outputFile; outputFile.setLength(0); outputApkOut = DataSinks.asDataSink(outputFile); outputApkIn = DataSources.asDataSource(outputFile); } else { throw new IllegalStateException("Output APK not specified"); } sign(inputApk, outputApkOut, outputApkIn); } finally { if (out != null) { out.close(); } } } finally { if (in != null) { in.close(); } } }
ApkSigner { public void sign() throws IOException, ApkFormatException, NoSuchAlgorithmException, InvalidKeyException, SignatureException, IllegalStateException { Closeable in = null; DataSource inputApk; try { if (mInputApkDataSource != null) { inputApk = mInputApkDataSource; } else if (mInputApkFile != null) { RandomAccessFile inputFile = new RandomAccessFile(mInputApkFile, "r"); in = inputFile; inputApk = DataSources.asDataSource(inputFile); } else { throw new IllegalStateException("Input APK not specified"); } Closeable out = null; try { DataSink outputApkOut; DataSource outputApkIn; if (mOutputApkDataSink != null) { outputApkOut = mOutputApkDataSink; outputApkIn = mOutputApkDataSource; } else if (mOutputApkFile != null) { RandomAccessFile outputFile = new RandomAccessFile(mOutputApkFile, "rw"); out = outputFile; outputFile.setLength(0); outputApkOut = DataSinks.asDataSink(outputFile); outputApkIn = DataSources.asDataSource(outputFile); } else { throw new IllegalStateException("Output APK not specified"); } sign(inputApk, outputApkOut, outputApkIn); } finally { if (out != null) { out.close(); } } } finally { if (in != null) { in.close(); } } } }
ApkSigner { public void sign() throws IOException, ApkFormatException, NoSuchAlgorithmException, InvalidKeyException, SignatureException, IllegalStateException { Closeable in = null; DataSource inputApk; try { if (mInputApkDataSource != null) { inputApk = mInputApkDataSource; } else if (mInputApkFile != null) { RandomAccessFile inputFile = new RandomAccessFile(mInputApkFile, "r"); in = inputFile; inputApk = DataSources.asDataSource(inputFile); } else { throw new IllegalStateException("Input APK not specified"); } Closeable out = null; try { DataSink outputApkOut; DataSource outputApkIn; if (mOutputApkDataSink != null) { outputApkOut = mOutputApkDataSink; outputApkIn = mOutputApkDataSource; } else if (mOutputApkFile != null) { RandomAccessFile outputFile = new RandomAccessFile(mOutputApkFile, "rw"); out = outputFile; outputFile.setLength(0); outputApkOut = DataSinks.asDataSink(outputFile); outputApkIn = DataSources.asDataSource(outputFile); } else { throw new IllegalStateException("Output APK not specified"); } sign(inputApk, outputApkOut, outputApkIn); } finally { if (out != null) { out.close(); } } } finally { if (in != null) { in.close(); } } } private  ApkSigner(
            List<SignerConfig> signerConfigs,
            Integer minSdkVersion,
            boolean v1SigningEnabled,
            boolean v2SigningEnabled,
            boolean v3SigningEnabled,
            boolean debuggableApkPermitted,
            boolean otherSignersSignaturesPreserved,
            String createdBy,
            ApkSignerEngine signerEngine,
            File inputApkFile,
            DataSource inputApkDataSource,
            File outputApkFile,
            DataSink outputApkDataSink,
            DataSource outputApkDataSource,
            SigningCertificateLineage signingCertificateLineage); }
ApkSigner { public void sign() throws IOException, ApkFormatException, NoSuchAlgorithmException, InvalidKeyException, SignatureException, IllegalStateException { Closeable in = null; DataSource inputApk; try { if (mInputApkDataSource != null) { inputApk = mInputApkDataSource; } else if (mInputApkFile != null) { RandomAccessFile inputFile = new RandomAccessFile(mInputApkFile, "r"); in = inputFile; inputApk = DataSources.asDataSource(inputFile); } else { throw new IllegalStateException("Input APK not specified"); } Closeable out = null; try { DataSink outputApkOut; DataSource outputApkIn; if (mOutputApkDataSink != null) { outputApkOut = mOutputApkDataSink; outputApkIn = mOutputApkDataSource; } else if (mOutputApkFile != null) { RandomAccessFile outputFile = new RandomAccessFile(mOutputApkFile, "rw"); out = outputFile; outputFile.setLength(0); outputApkOut = DataSinks.asDataSink(outputFile); outputApkIn = DataSources.asDataSource(outputFile); } else { throw new IllegalStateException("Output APK not specified"); } sign(inputApk, outputApkOut, outputApkIn); } finally { if (out != null) { out.close(); } } } finally { if (in != null) { in.close(); } } } private  ApkSigner(
            List<SignerConfig> signerConfigs,
            Integer minSdkVersion,
            boolean v1SigningEnabled,
            boolean v2SigningEnabled,
            boolean v3SigningEnabled,
            boolean debuggableApkPermitted,
            boolean otherSignersSignaturesPreserved,
            String createdBy,
            ApkSignerEngine signerEngine,
            File inputApkFile,
            DataSource inputApkDataSource,
            File outputApkFile,
            DataSink outputApkDataSink,
            DataSource outputApkDataSource,
            SigningCertificateLineage signingCertificateLineage); void sign(); }
ApkSigner { public void sign() throws IOException, ApkFormatException, NoSuchAlgorithmException, InvalidKeyException, SignatureException, IllegalStateException { Closeable in = null; DataSource inputApk; try { if (mInputApkDataSource != null) { inputApk = mInputApkDataSource; } else if (mInputApkFile != null) { RandomAccessFile inputFile = new RandomAccessFile(mInputApkFile, "r"); in = inputFile; inputApk = DataSources.asDataSource(inputFile); } else { throw new IllegalStateException("Input APK not specified"); } Closeable out = null; try { DataSink outputApkOut; DataSource outputApkIn; if (mOutputApkDataSink != null) { outputApkOut = mOutputApkDataSink; outputApkIn = mOutputApkDataSource; } else if (mOutputApkFile != null) { RandomAccessFile outputFile = new RandomAccessFile(mOutputApkFile, "rw"); out = outputFile; outputFile.setLength(0); outputApkOut = DataSinks.asDataSink(outputFile); outputApkIn = DataSources.asDataSource(outputFile); } else { throw new IllegalStateException("Output APK not specified"); } sign(inputApk, outputApkOut, outputApkIn); } finally { if (out != null) { out.close(); } } } finally { if (in != null) { in.close(); } } } private  ApkSigner(
            List<SignerConfig> signerConfigs,
            Integer minSdkVersion,
            boolean v1SigningEnabled,
            boolean v2SigningEnabled,
            boolean v3SigningEnabled,
            boolean debuggableApkPermitted,
            boolean otherSignersSignaturesPreserved,
            String createdBy,
            ApkSignerEngine signerEngine,
            File inputApkFile,
            DataSource inputApkDataSource,
            File outputApkFile,
            DataSink outputApkDataSink,
            DataSource outputApkDataSource,
            SigningCertificateLineage signingCertificateLineage); void sign();  }