use of com.android.build.gradle.tasks.AndroidZip in project atlas by alibaba.
the class AwbGenerator method generateAwbArtifict.
/**
* Create a basic AWB task
*/
public void generateAwbArtifict(final Zip bundleTask, LibVariantContext libVariantOutputData) {
Project project = bundleTask.getProject();
bundleTask.setExtension("awb");
if (bundleTask instanceof AndroidZip) {
String fileName = FilenameUtils.getBaseName(bundleTask.getArchiveName()) + ".awb";
((AndroidZip) bundleTask).setArchiveNameSupplier(() -> fileName);
}
bundleTask.setDestinationDir(new File(bundleTask.getDestinationDir().getParentFile(), "awb"));
File destDir = libVariantOutputData.getScope().getBaseBundleDir();
bundleTask.doFirst(task -> {
File bundleBaseInfoFile = project.file("bundleBaseInfoFile.json");
File customBundleIdFile = project.file("customPackageID.txt");
if (bundleBaseInfoFile.exists()) {
project.getLogger().warn("copy " + bundleBaseInfoFile.getAbsolutePath() + " to awb");
try {
FileUtils.copyFileToDirectory(bundleBaseInfoFile, destDir);
} catch (IOException e) {
throw new GradleException(e.getMessage(), e);
}
}
if (customBundleIdFile.exists()) {
try {
FileUtils.copyFileToDirectory(customBundleIdFile, destDir);
} catch (IOException e) {
throw new GradleException(e.getMessage(), e);
}
}
});
bundleTask.doLast(task -> {
File outputFile = new File(bundleTask.getDestinationDir(), bundleTask.getArchiveName());
if (!outputFile.exists()) {
return;
}
// Regenerating aar
if (atlasExtension.getBundleConfig().isAwbBundle()) {
try {
FileUtils.copyFile(outputFile, new File(new File(bundleTask.getDestinationDir().getParentFile(), "aar"), FilenameUtils.getBaseName(bundleTask.getArchiveName()) + ".aar"));
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
Aggregations