use of com.android.ide.common.blame.ParsingProcessOutputHandler in project atlas by alibaba.
the class PackageAwbsTask method createAwbPackages.
/**
* 生成so的目录
*/
@TaskAction
void createAwbPackages() throws ExecutionException, InterruptedException {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == androidDependencyTree) {
return;
}
final ProcessOutputHandler outputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new DexParser(), Message.Kind.ERROR, getILogger()), new ToolOutputParser(new DexParser(), getILogger()), getBuilder().getErrorReporter());
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
List<Runnable> runnables = new ArrayList<>();
final AtomicLong dexTotalTime = new AtomicLong(0);
final AtomicLong packageTotalTime = new AtomicLong(0);
final Map<String, Long[]> monitors = new HashMap<String, Long[]>();
long startTime = System.currentTimeMillis();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
runnables.add(new Runnable() {
@Override
public void run() {
try {
long start = System.currentTimeMillis();
//create dex
File dexOutputFile = appVariantContext.getAwbDexOutput(awbBundle.getName());
emptyFolder(dexOutputFile);
// if some of our .jar input files exist, just reset the inputDir to null
AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get(awbBundle.getName());
List<File> inputFiles = new ArrayList<File>();
inputFiles.addAll(awbTransform.getInputFiles());
inputFiles.addAll(awbTransform.getInputLibraries());
if (null != awbTransform.getInputDir()) {
inputFiles.add(awbTransform.getInputDir());
}
AtlasBuildContext.androidBuilder.convertByteCode(inputFiles, dexOutputFile, appVariantContext.getVariantData().getVariantConfiguration().isMultiDexEnabled(), null, androidConfig.getDexOptions(), true, outputHandler);
//create package
long endDex = System.currentTimeMillis();
//PACKAGE APP:
File resourceFile = appVariantOutputContext.getAwbAndroidResourcesMap().get(awbBundle.getName()).getPackageOutputFile();
Set<File> dexFolders = new HashSet<File>();
dexFolders.add(dexOutputFile);
Set<File> jniFolders = Sets.newHashSet();
if (appVariantOutputContext.getAwbJniFolder(awbBundle) != null && appVariantOutputContext.getAwbJniFolder(awbBundle).exists()) {
jniFolders.add(appVariantOutputContext.getAwbJniFolder(awbBundle));
}
Set<File> javaResourcesLocations = Sets.newHashSet();
if (appVariantContext.getAtlasExtension().getTBuildConfig().getMergeAwbJavaRes()) {
javaResourcesLocations.addAll(awbBundle.getLibraryJars());
}
//getBuilder().packageCodeSplitApk();
getBuilder().oldPackageApk(resourceFile.getAbsolutePath(), dexFolders, javaResourcesLocations, jniFolders, null, getAbiFilters(), config.getBuildType().isJniDebuggable(), null, getOutputFile(awbBundle), config.getMinSdkVersion().getApiLevel(), new Predicate<String>() {
@Override
public boolean apply(@Nullable String s) {
return false;
}
});
long endPackage = System.currentTimeMillis();
dexTotalTime.addAndGet(endDex - start);
packageTotalTime.addAndGet(endPackage - endDex);
monitors.put(awbBundle.getName(), new Long[] { endDex - start, endPackage - endDex });
} catch (Throwable e) {
e.printStackTrace();
throw new GradleException("package " + awbBundle.getName() + " failed");
}
}
});
}
executorServicesHelper.execute(runnables);
if (getLogger().isInfoEnabled()) {
getLogger().info(">>>>> packageAwbs >>>>>>>>>>>>");
getLogger().info("totalTime is " + (System.currentTimeMillis() - startTime));
getLogger().info("dexTotalTime is " + dexTotalTime);
getLogger().info("packageTotalTime is " + packageTotalTime);
String format = "[packageawb] bundle:%50s dexTime: %10d packageTime: %10d ";
for (String bundle : monitors.keySet()) {
Long[] value = monitors.get(bundle);
getLogger().info(String.format(format, bundle, value[0], value[1]));
}
getLogger().info(">>>>> packageAwbs >>>>>>>>>>>>");
}
}
use of com.android.ide.common.blame.ParsingProcessOutputHandler in project atlas by alibaba.
the class AwbDexTask method doTaskAction.
private void doTaskAction(@Nullable Collection<File> inputFiles, @Nullable File inputDir, boolean incremental) throws InterruptedException, ProcessException, IOException {
File outFolder = getOutputFolder();
if (!incremental) {
emptyFolder(outFolder);
}
// if some of our .jar input files exist, just reset the inputDir to null
for (File inputFile : inputFiles) {
if (inputFile.exists()) {
inputDir = null;
}
}
if (inputDir != null) {
inputFiles = getProject().files(inputDir).getFiles();
}
ProcessOutputHandler outputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new DexParser(), Message.Kind.ERROR, getILogger()), new ToolOutputParser(new DexParser(), getILogger()), getBuilder().getErrorReporter());
getBuilder().convertByteCode(inputFiles, getOutputFolder(), getMultiDexEnabled(), getMainDexListFile(), getDexOptions(), getOptimize(), outputHandler);
}
use of com.android.ide.common.blame.ParsingProcessOutputHandler 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();
//TODO minifyManifest
File miniManifest = new File(packageOutputFile.getParentFile(), "AndroidManifest.xml");
try {
ManifestFileUtils.minifyManifest(manifestFile, miniManifest);
} catch (DocumentException e) {
throw new GradleException(e.getMessage());
}
File assetsFolder = new File(diffResDir, "assets");
File resFolder = new File(diffResDir, "res");
if (!assetsFolder.exists()) {
assetsFolder.mkdirs();
}
if (!resFolder.exists()) {
resFolder.mkdirs();
}
AaptPackageProcessBuilder aaptPackageCommandBuilder = new AaptPackageProcessBuilder(miniManifest, aaptOptions).setAssetsFolder(assetsFolder).setResFolder(resFolder).setLibraries(libraries).setPackageForR(packageForR).setResPackageOutput(packageOutputFile.getAbsolutePath()).setType(type).setDebuggable(debuggable).setPseudoLocalesEnabled(pseudoLocalesEnabled).setResourceConfigs(resourceConfigs).setSplits(splits).setPreferredDensity(preferredDensity);
@NonNull AndroidBuilder builder = getBuilder();
MergingLog mergingLog = new MergingLog(mergeBlameLogFolder);
ProcessOutputHandler processOutputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new AaptOutputParser(), getILogger()), new MergingLogRewriter(mergingLog, builder.getErrorReporter()));
try {
if (builder instanceof AtlasBuilder) {
((AtlasBuilder) builder).processResources(aaptPackageCommandBuilder, enforceUniquePackageName, processOutputHandler);
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ProcessException e) {
throw new RuntimeException(e);
}
}
Aggregations