use of com.android.builder.internal.aapt.AaptPackageConfig in project atlas by alibaba.
the class AtlasBuilder method processAwbResources.
/**
* Deal with awb resources
* @param aaptCommand
* @param enforceUniquePackageName
* @param processOutputHandler
* @param mainSymbolFile
*/
public void processAwbResources(Aapt aapt, AaptPackageConfig.Builder aaptConfigBuilder, File mainSymbolFile, File awbSymbolFile, String pacakgeName) throws IOException, ProcessException {
aaptConfigBuilder.setBuildToolInfo(getTargetInfo().getBuildTools());
aaptConfigBuilder.setAndroidTarget(getTargetInfo().getTarget());
aaptConfigBuilder.setLogger(logger);
logger.info("Aapt output file {}");
AaptPackageConfig aaptConfig = aaptConfigBuilder.build();
try {
aapt.link(aaptConfig).get();
} catch (Exception e) {
throw new ProcessException("Failed to execute aapt", e);
}
File sourceOut = aaptConfig.getSourceOutputDir();
if (sourceOut != null) {
// Figure out what the main symbol file's package is.
String mainPackageName = aaptConfig.getCustomPackageForR();
if (mainPackageName == null) {
mainPackageName = SymbolUtils.getPackageNameFromManifest(aaptConfig.getManifestFile());
}
// Load the main symbol file.
File mainRTxt = new File(aaptConfig.getSymbolOutputDir(), "R.txt");
File mergedSymbolFile = new File(aaptConfig.getSymbolOutputDir(), "R-all.txt");
try {
sLogger.info("awbSymbolFile:" + mainRTxt);
if (null != mainRTxt && mainRTxt.exists()) {
FileUtils.copyFile(mainRTxt, mergedSymbolFile);
} else {
throw new ProcessException(mainRTxt.getAbsolutePath() + "is not exist, maybe no resources in this bundle! ");
}
SymbolTable awbSymbols = build(awbSymbolFile, mainPackageName, mainRTxt, mainSymbolFile, pacakgeName);
if (awbSymbols != null) {
AtlasSymbolIo.write(awbSymbols, mergedSymbolFile);
}
// why do this? youku need use this !
// FileUtils.writeLines(mergedSymbolFile, FileUtils.readLines(mainSymbolFile), true);
} catch (IOException e) {
throw new RuntimeException("Could not load file ", e);
}
SymbolTable mainSymbols = mergedSymbolFile.isFile() ? AtlasSymbolIo.readFromAapt(mergedSymbolFile, mainPackageName) : SymbolTable.builder().tablePackage(mainPackageName).build();
// For each dependency, load its symbol file.
Set<SymbolTable> depSymbolTables = SymbolUtils.loadDependenciesSymbolTables(aaptConfig.getLibrarySymbolTableFiles(), mainPackageName);
boolean finalIds = true;
if (aaptConfig.getVariantType() == VariantType.LIBRARY) {
finalIds = false;
}
SymbolIo.exportToJava(mainSymbols, sourceOut, finalIds);
RGeneration.generateRForLibraries(mainSymbols, depSymbolTables, sourceOut, finalIds);
}
}
Aggregations