use of org.gradle.api.GradleException in project atlas by alibaba.
the class AtlasBuilder method processResources.
@Override
public void processResources(Aapt aapt, Builder aaptConfigBuilder, boolean enforceUniquePackageName) throws IOException, InterruptedException, ProcessException {
if (aapt instanceof AaptV1) {
try {
getTargetInfo();
AaptOptions aaptOptions = (AaptOptions) FieldUtils.readField(aaptConfigBuilder.build(), "mAaptOptions", true);
ProcessExecutor processExecutor = (ProcessExecutor) FieldUtils.readField(aapt, "mProcessExecutor", true);
ProcessOutputHandler processOutputHandler = (ProcessOutputHandler) FieldUtils.readField(aapt, "mProcessOutputHandler", true);
BuildToolInfo buildToolInfo = (BuildToolInfo) FieldUtils.readField(aapt, "mBuildToolInfo", true);
PngProcessMode processMode = (PngProcessMode) FieldUtils.readField(aapt, "mProcessMode", true);
int cruncherProcesses = aaptOptions.getCruncherProcesses();
aapt = new AtlasAapt(processExecutor, processOutputHandler, buildToolInfo, getLogger(), processMode, cruncherProcesses);
} catch (Throwable e) {
throw new GradleException("aapt exception", e);
}
}
super.processResources(aapt, aaptConfigBuilder, enforceUniquePackageName);
}
use of org.gradle.api.GradleException in project atlas by alibaba.
the class AtlasBuilder method getTargetInfo.
@Override
public TargetInfo getTargetInfo() {
if (!updateAapt && useCustomAapt) {
BuildToolInfo defaultBuildToolInfo = super.getTargetInfo().getBuildTools();
File customAaptFile = getAapt();
try {
Method method = defaultBuildToolInfo.getClass().getDeclaredMethod("add", PathId.class, File.class);
method.setAccessible(true);
method.invoke(defaultBuildToolInfo, PathId.AAPT, customAaptFile);
} catch (Throwable e) {
throw new GradleException(e.getMessage());
}
updateAapt = true;
}
return super.getTargetInfo();
}
use of org.gradle.api.GradleException 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 org.gradle.api.GradleException in project atlas by alibaba.
the class ResolvedDependencyContainer method reslovedDependencies.
/**
* 进行依赖仲裁
*/
public synchronized DependencyTree reslovedDependencies() {
if (inited) {
return dependencyTree;
}
if (!conflictDependencies.isEmpty()) {
for (String str : conflictDependencies) {
logger.error(str);
}
if (null == forceMap) {
throw new GradleException("conflict dependencis");
} else {
AtlasBuildContext.conflictDependencies = conflictDependencies;
}
}
// 仲裁后的依赖关系.结构为父类-子类
Multimap<ModuleVersionIdentifier, ResolvedDependencyInfo> resolvedDependenciesMap = LinkedHashMultimap.create();
Map<ModuleVersionIdentifier, ResolvedDependencyInfo> directDependencies = new HashMap<ModuleVersionIdentifier, ResolvedDependencyInfo>();
for (String key : dependenciesMap.keySet()) {
Collection<ResolvedDependencyInfo> dependencyLevels = dependenciesMap.get(key);
if (dependencyLevels.size() > 0) {
List<ResolvedDependencyInfo> resolvedDependencyInfos = Lists.newArrayList();
resolvedDependencyInfos.addAll(dependencyLevels);
Collections.sort(resolvedDependencyInfos);
ResolvedDependencyInfo resolvedDependencyInfo = resolvedDependencyInfos.get(0);
ResolvedDependencyInfo parent = resolvedDependencyInfo.getParent();
//对于放入resolvedDependenciesMap中的信息不需要加入children
resolvedDependencyInfo.setChildren(Lists.<ResolvedDependencyInfo>newArrayList());
if (null != parent) {
//如果存在的父依赖,就把当前依赖加入到父依赖的子依赖中
resolvedDependenciesMap.put(parent.getModuleVersionIdentifier(), resolvedDependencyInfo);
} else {
//如果没有父依赖,就是一级依赖
directDependencies.put(resolvedDependencyInfo.getModuleVersionIdentifier(), resolvedDependencyInfo);
}
}
}
// 开始构建依赖树
dependencyTree.clear();
for (ModuleVersionIdentifier key : directDependencies.keySet()) {
ResolvedDependencyInfo resolvedDependencyInfo = directDependencies.get(key);
//清空children
resolvedDependencyInfo.setChildren(Lists.<ResolvedDependencyInfo>newArrayList());
addResolvedDependencyInfo(resolvedDependencyInfo, resolvedDependenciesMap);
dependencyTree.addDependency(resolvedDependencyInfo);
}
inited = true;
return dependencyTree;
}
use of org.gradle.api.GradleException in project atlas by alibaba.
the class LogDependenciesTask method generate.
@TaskAction
void generate() {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == androidDependencyTree) {
return;
}
File treeFile = new File(getProject().getBuildDir(), "outputs/dependencyTree-" + getVariantName() + ".json");
File dependenciesFile = new File(getProject().getBuildDir(), "outputs/dependencies.txt");
File versionProperties = new File(getProject().getBuildDir(), "outputs/version.properties");
File buildInfo = new File(getProject().getBuildDir(), "outputs/build.txt");
File atlasConfig = new File(getProject().getBuildDir(), "outputs/atlasConfig.json");
appBuildInfo.setDependencyTreeFile(treeFile);
appBuildInfo.setDependenciesFile(dependenciesFile);
appBuildInfo.setVersionPropertiesFile(versionProperties);
appBuildInfo.setBuildInfoFile(buildInfo);
treeFile.delete();
dependenciesFile.delete();
versionProperties.delete();
buildInfo.delete();
treeFile.getParentFile().mkdirs();
try {
DependencyJson dependencyJson = androidDependencyTree.getDependencyJson();
Collections.sort(dependencyJson.getMainDex());
FileUtils.write(treeFile, JSON.toJSONString(dependencyJson, true));
//add to ap
appBuildInfo.getOtherFilesMap().put("awo/dependencyTree.json", treeFile);
} catch (IOException e) {
e.printStackTrace();
}
try {
FileUtils.writeStringToFile(dependenciesFile, JSON.toJSONString(androidDependencyTree.getDependencyJson()));
} catch (IOException e) {
e.printStackTrace();
}
try {
FileUtils.writeLines(versionProperties, getSortVersionList(androidDependencyTree));
} catch (IOException e) {
e.printStackTrace();
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("gradleVersion:").append(getProject().getGradle().getGradleVersion()).append("\r\n");
stringBuilder.append("mtlVersion:").append(Version.ANDROID_GRADLE_PLUGIN_VERSION).append("\r\n");
stringBuilder.append("androidVersion:").append(PathUtil.getJarFile(AndroidBuilder.class)).append("\r\n");
try {
FileUtils.writeStringToFile(buildInfo, stringBuilder.toString());
} catch (IOException e) {
e.printStackTrace();
}
try {
FileUtils.write(atlasConfig, JSON.toJSONString(new AtlasExtensionOutput(appVariantContext.getAtlasExtension(), getVariantName()), true));
} catch (IOException e) {
e.printStackTrace();
}
if (null != AtlasBuildContext.conflictDependencies && !AtlasBuildContext.conflictDependencies.isEmpty()) {
try {
FileUtils.writeLines(new File(getProject().getBuildDir(), "outputs/warning-dependencyConflict.properties"), AtlasBuildContext.conflictDependencies);
} catch (IOException e) {
e.printStackTrace();
}
if (appVariantContext.getAtlasExtension().getTBuildConfig().isAbortIfDependencyConflict()) {
throw new GradleException("依赖冲突,具体见warning-dependencyConflict.properties");
}
}
}
Aggregations