use of com.android.build.gradle.internal.aapt.AaptGeneration in project atlas by alibaba.
the class TPatchDiffResAPBuildTask method doAction.
@TaskAction
protected void doAction() throws IOException {
manifestFile = getManifestFile();
aaptOptions = getAaptOptions();
diffResDir = getDiffResDir();
resourceConfigs = getResourceConfigs();
preferredDensity = getPreferredDensity();
SplitList splitList = SplitList.load(splitListInput);
// TODO minifyManifest
File miniManifest = new File(packageOutputFile.getParentFile(), "AndroidManifest.xml");
try {
ManifestFileUtils.createPatchManifest(manifestFile, getBaseManifestFile(), miniManifest);
} catch (DocumentException e) {
throw new GradleException(e.getMessage());
}
String splitFilter = apkData.getFilter(com.android.build.OutputFile.FilterType.DENSITY);
String preferredDensity = splitFilter != null ? splitFilter : // if resConfigs is set, we should not use our preferredDensity.
splitList.getFilters(SplitList.RESOURCE_CONFIGS).isEmpty() ? buildTargetDensity : null;
File assetsFolder = new File(diffResDir, "assets");
File resFolder = new File(diffResDir, "res");
if (!assetsFolder.exists()) {
assetsFolder.mkdirs();
}
if (!resFolder.exists()) {
resFolder.mkdirs();
}
aaptOptions.getAdditionalParameters().add("-A");
aaptOptions.getAdditionalParameters().add(assetsFolder.getAbsolutePath());
AaptGeneration aaptGeneration = AaptGeneration.fromProjectOptions(appVariantContext.getScope().getGlobalScope().getProjectOptions());
Aapt aapt = makeAapt(aaptGeneration);
AaptPackageConfig.Builder config = new AaptPackageConfig.Builder().setManifestFile(miniManifest).setOptions(DslAdaptersKt.convert(aaptOptions)).setResourceDir(resFolder).setLibrarySymbolTableFiles(ImmutableSet.of()).setCustomPackageForR(packageForR).setResourceOutputApk(packageOutputFile).setVariantType(type).setDebuggable(debuggable).setResourceConfigs(splitList.getFilters(SplitList.RESOURCE_CONFIGS)).setSplits(getSplits(splitList)).setPreferredDensity(preferredDensity).setListResourceFiles(aaptGeneration == AaptGeneration.AAPT_V2);
try {
getBuilder().processResources(aapt, config);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ProcessException e) {
e.printStackTrace();
}
}
Aggregations