use of com.android.sdklib.build.DuplicateFileException 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;
}
Aggregations