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();
}
}
}
Aggregations