Search in sources :

Example 1 with FN_RES_BASE

use of com.android.SdkConstants.FN_RES_BASE in project atlas by alibaba.

the class FirstApkAction method execute.

@Override
public void execute(Task task) {
    assert task instanceof PackageApplication;
    PackageApplication packageApplication = (PackageApplication) task;
    if (packageApplication.getName().startsWith("packageInstantRunResources")) {
        return;
    }
    File bundleInfoFile = new File(appVariantOutputContext.getScope().getGlobalScope().getOutputsDir(), "bundleInfo-" + appVariantOutputContext.getVariantContext().getVariantConfiguration().getVersionName() + ".json");
    File nativeInfoFile = new File(appVariantOutputContext.getScope().getGlobalScope().getOutputsDir(), "nativeInfo-" + appVariantOutputContext.getVariantContext().getVariantConfiguration().getVersionName() + ".json");
    File resOutBaseNameFile = new File(packageApplication.getResourceFiles().getSingleFile(), FN_RES_BASE + RES_QUALIFIER_SEP + appVariantOutputContext.getVariantContext().getVariantName() + SdkConstants.DOT_RES);
    File[] dexs = null;
    if (packageApplication.getDexFolders().getFiles().size() == 0) {
        dexs = appVariantOutputContext.getDexMergeFolder().listFiles(pathname -> pathname.getName().equals("classes.dex"));
        ReflectUtils.updateField(packageApplication, "dexFolders", appVariantOutputContext.getVariantContext().getProject().files(appVariantOutputContext.getDexMergeFolder()));
    } else {
        dexs = packageApplication.getDexFolders().getSingleFile().listFiles(pathname -> pathname.getName().equals("classes.dex"));
    }
    if (dexs != null && dexs.length == 1) {
        File androidManifest = null;
        if (appVariantOutputContext.getApkData().getFilterName() == null) {
            androidManifest = com.android.utils.FileUtils.join(appVariantOutputContext.getScope().getOutput(TaskOutputHolder.TaskOutputType.MERGED_MANIFESTS).getSingleFile(), "AndroidManifest.xml");
        } else {
            androidManifest = com.android.utils.FileUtils.join(appVariantOutputContext.getScope().getOutput(TaskOutputHolder.TaskOutputType.MERGED_MANIFESTS).getSingleFile(), appVariantOutputContext.getApkData().getDirName(), "AndroidManifest.xml");
        }
        File file = AtlasBuildContext.atlasApkProcessor.securitySignApk(dexs[0], androidManifest, appVariantOutputContext.getVariantContext().getBuildType(), false);
        if (file != null && file.exists()) {
            try {
                BetterZip.addFile(resOutBaseNameFile, "res/drawable/".concat(file.getName()), file);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    if (bundleInfoFile.exists()) {
        try {
            BetterZip.addFile(resOutBaseNameFile, "assets/".concat(bundleInfoFile.getName()), bundleInfoFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    if (nativeInfoFile.exists()) {
        try {
            BetterZip.addFile(resOutBaseNameFile, "assets/".concat(nativeInfoFile.getName()), nativeInfoFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : ReflectUtils(com.taobao.android.builder.tools.ReflectUtils) PackageApplication(com.android.build.gradle.tasks.PackageApplication) Action(org.gradle.api.Action) SdkConstants(com.android.SdkConstants) FN_RES_BASE(com.android.SdkConstants.FN_RES_BASE) BetterZip(com.taobao.android.builder.tools.zip.BetterZip) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) File(java.io.File) Task(org.gradle.api.Task) AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext) AtlasBuildContext(com.taobao.android.builder.AtlasBuildContext) TaskOutputHolder(com.android.build.gradle.internal.scope.TaskOutputHolder) RES_QUALIFIER_SEP(com.android.SdkConstants.RES_QUALIFIER_SEP) IOException(java.io.IOException) PackageApplication(com.android.build.gradle.tasks.PackageApplication) File(java.io.File)

Aggregations

SdkConstants (com.android.SdkConstants)1 FN_RES_BASE (com.android.SdkConstants.FN_RES_BASE)1 RES_QUALIFIER_SEP (com.android.SdkConstants.RES_QUALIFIER_SEP)1 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)1 TaskOutputHolder (com.android.build.gradle.internal.scope.TaskOutputHolder)1 PackageApplication (com.android.build.gradle.tasks.PackageApplication)1 AtlasBuildContext (com.taobao.android.builder.AtlasBuildContext)1 ReflectUtils (com.taobao.android.builder.tools.ReflectUtils)1 BetterZip (com.taobao.android.builder.tools.zip.BetterZip)1 File (java.io.File)1 IOException (java.io.IOException)1 FileUtils (org.apache.commons.io.FileUtils)1 Action (org.gradle.api.Action)1 Task (org.gradle.api.Task)1