Search in sources :

Example 1 with SealedApkException

use of com.android.sdklib.build.SealedApkException in project buck by facebook.

the class ApkBuilderStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException {
    PrintStream output = null;
    if (context.getVerbosity().shouldUseVerbosityFlagIfAvailable()) {
        output = context.getStdOut();
    }
    try {
        PrivateKeyAndCertificate privateKeyAndCertificate = createKeystoreProperties();
        ApkBuilder builder = new ApkBuilder(filesystem.getPathForRelativePath(pathToOutputApkFile).toFile(), filesystem.getPathForRelativePath(resourceApk).toFile(), filesystem.getPathForRelativePath(dexFile).toFile(), privateKeyAndCertificate.privateKey, privateKeyAndCertificate.certificate, output);
        builder.setDebugMode(debugMode);
        for (Path nativeLibraryDirectory : nativeLibraryDirectories) {
            builder.addNativeLibraries(filesystem.getPathForRelativePath(nativeLibraryDirectory).toFile());
        }
        for (Path assetDirectory : assetDirectories) {
            builder.addSourceFolder(filesystem.getPathForRelativePath(assetDirectory).toFile());
        }
        for (Path zipFile : zipFiles) {
            // TODO(natthu): Skipping silently is bad. These should really be assertions.
            if (filesystem.exists(zipFile) && filesystem.isFile(zipFile)) {
                builder.addZipFile(filesystem.getPathForRelativePath(zipFile).toFile());
            }
        }
        for (Path jarFileThatMayContainResources : jarFilesThatMayContainResources) {
            Path jarFile = filesystem.getPathForRelativePath(jarFileThatMayContainResources);
            builder.addResourcesFromJar(jarFile.toFile());
        }
        // Build the APK
        builder.sealApk();
    } catch (ApkCreationException | IOException | KeyStoreException | NoSuchAlgorithmException | SealedApkException | UnrecoverableKeyException e) {
        context.logError(e, "Error when creating APK at: %s.", pathToOutputApkFile);
        Throwables.throwIfInstanceOf(e, IOException.class);
        return StepExecutionResult.ERROR;
    } catch (DuplicateFileException e) {
        throw new HumanReadableException(String.format("Found duplicate file for APK: %1$s\nOrigin 1: %2$s\nOrigin 2: %3$s", e.getArchivePath(), e.getFile1(), e.getFile2()));
    }
    return StepExecutionResult.SUCCESS;
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) ApkCreationException(com.android.sdklib.build.ApkCreationException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ApkBuilder(com.android.sdklib.build.ApkBuilder) UnrecoverableKeyException(java.security.UnrecoverableKeyException) DuplicateFileException(com.android.sdklib.build.DuplicateFileException) HumanReadableException(com.facebook.buck.util.HumanReadableException) SealedApkException(com.android.sdklib.build.SealedApkException)

Aggregations

ApkBuilder (com.android.sdklib.build.ApkBuilder)1 ApkCreationException (com.android.sdklib.build.ApkCreationException)1 DuplicateFileException (com.android.sdklib.build.DuplicateFileException)1 SealedApkException (com.android.sdklib.build.SealedApkException)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Path (java.nio.file.Path)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1