Search in sources :

Example 1 with AndroidZip

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();
            }
        }
    });
}
Also used : Project(org.gradle.api.Project) GradleException(org.gradle.api.GradleException) AndroidZip(com.android.build.gradle.tasks.AndroidZip) IOException(java.io.IOException) File(java.io.File)

Aggregations

AndroidZip (com.android.build.gradle.tasks.AndroidZip)1 File (java.io.File)1 IOException (java.io.IOException)1 GradleException (org.gradle.api.GradleException)1 Project (org.gradle.api.Project)1