use of org.gradle.api.GradleException 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);
}
}
use of org.gradle.api.GradleException in project atlas by alibaba.
the class AwbProguradHook method hookProguardTask.
/**
* hook混淆的任务,加入awb的混淆配置
*
* @param appVariantContext
*/
public void hookProguardTask(final AppVariantContext appVariantContext) {
final VariantScope variantScope = appVariantContext.getScope();
List<TransformTask> proguaradTransformTasks = getTransformTaskByTransformType(appVariantContext, ProGuardTransform.class);
for (TransformTask proguaradTransformTask : proguaradTransformTasks) {
final ProGuardTransform proGuardTransform = (ProGuardTransform) proguaradTransformTask.getTransform();
if (null != proGuardTransform) {
proguaradTransformTask.doFirst(new Action<Task>() {
@Override
public void execute(Task task) {
GlobalScope globalScope = variantScope.getGlobalScope();
File proguardOut = new File(Joiner.on(File.separatorChar).join(String.valueOf(globalScope.getBuildDir()), FD_OUTPUTS, "mapping", variantScope.getVariantConfiguration().getDirName()));
//为了方便排查,先把configuration打印到目录
proGuardTransform.printconfiguration(new File(proguardOut, "tmp_config.cfg"));
final File outConfigFile = new File(proguardOut, "awb_config.cfg");
//增加awb的配置
AndroidDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantScope.getVariantConfiguration().getFullName());
if (null == dependencyTree) {
throw new StopExecutionException("DependencyTree cannot be null!");
}
if (dependencyTree.getAwbBundles().size() > 0) {
BaseVariantOutputData vod = appVariantContext.getVariantData().getOutputs().get(0);
AppVariantOutputContext appVariantOutputContext = getAppVariantOutputContext(appVariantContext, vod);
File awbObfuscatedDir = new File(globalScope.getIntermediatesDir(), "/classes-proguard/" + variantScope.getVariantConfiguration().getDirName());
AwbProguardConfiguration awbProguardConfiguration = new AwbProguardConfiguration(appVariantOutputContext.getAwbTransformMap().values(), awbObfuscatedDir, appVariantOutputContext);
try {
awbProguardConfiguration.printConfigFile(outConfigFile);
} catch (IOException e) {
throw new GradleException("", e);
}
proGuardTransform.setConfigurationFiles(new Supplier<Collection<File>>() {
@Override
public Collection<File> get() {
Set<File> proguardFiles = new HashSet<File>();
((HashSet<File>) proguardFiles).add(outConfigFile);
return proguardFiles;
}
});
}
File mappingFile = null;
if (null != appVariantContext.apContext.getApExploredFolder() && appVariantContext.apContext.getApExploredFolder().exists()) {
mappingFile = new File(appVariantContext.apContext.getApExploredFolder(), "mapping.txt");
} else {
mappingFile = new File(appVariantContext.getScope().getGlobalScope().getProject().getProjectDir(), "mapping.txt");
}
if (null != mappingFile && mappingFile.exists()) {
proGuardTransform.applyTestedMapping(mappingFile);
}
}
});
}
}
}
use of org.gradle.api.GradleException in project atlas by alibaba.
the class DiffBundleInfoTask method getArtifactBundleInfo.
private Set<ArtifactBundleInfo> getArtifactBundleInfo(DependencyDiff dependencyDiff, File mainfestFile, File apDir) throws IOException, DocumentException {
Set<ArtifactBundleInfo> artifactBundleInfos = new HashSet<ArtifactBundleInfo>();
if (null == apDir) {
throw new GradleException("No Ap dependency found!");
}
File apManifest = new File(apDir, "AndroidManifest.xml");
String apVersion = null;
try {
apVersion = ManifestFileUtils.getVersionName(apManifest);
} catch (Exception e) {
throw new GradleException(e.getMessage(), e);
}
// 1. 首先添加主bundle
ArtifactBundleInfo mainBundleInfo = getMainArtifactBundInfo(mainfestFile);
mainBundleInfo.setBaseVersion(apVersion);
mainBundleInfo.setMainBundle(true);
mainBundleInfo.setVersion(appVariantOutputContext.getVariantContext().getVariantConfiguration().getVersionName());
if (dependencyDiff.getMainDexDiffs().size() > 0) {
mainBundleInfo.setDiffType(DiffType.MODIFY);
} else {
mainBundleInfo.setDiffType(DiffType.NONE);
}
artifactBundleInfos.add(mainBundleInfo);
// 2. 添加各自的bundle
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantOutputContext.getVariantContext().getVariantConfiguration().getFullName());
for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
BundleInfo bundleInfo = awbBundle.bundleInfo;
ArtifactBundleInfo awbBundleInfo = new ArtifactBundleInfo();
awbBundleInfo.setMainBundle(false);
awbBundleInfo.setDependency(bundleInfo.getDependency());
awbBundleInfo.setPkgName(bundleInfo.getPkgName());
awbBundleInfo.setApplicationName(bundleInfo.getApplicationName());
awbBundleInfo.setArtifactId(awbBundle.getResolvedCoordinates().getArtifactId());
awbBundleInfo.setName(bundleInfo.getName());
String version = bundleInfo.getVersion();
if (version.indexOf("@") > 0) {
String[] arr = version.split("@");
version = arr[arr.length - 1];
}
awbBundleInfo.setVersion(version);
String libBundleName = getBundleName(awbBundle);
if (dependencyDiff.getAwbDiffs().contains(libBundleName)) {
if (dependencyDiff.getNewAwbs().contains(libBundleName)) {
awbBundleInfo.setDiffType(DiffType.ADD);
} else {
awbBundleInfo.setDiffType(DiffType.MODIFY);
}
} else {
awbBundleInfo.setDiffType(DiffType.NONE);
}
artifactBundleInfos.add(awbBundleInfo);
}
return artifactBundleInfos;
}
use of org.gradle.api.GradleException in project atlas by alibaba.
the class DiffBundleInfoTask method generate.
/**
* 生成这个文件
*/
@TaskAction
public void generate() throws IOException {
dependencyDiff = getDependencyDiff();
//如果是patch的话,得到diff的操作
if (null == dependencyDiff) {
return;
}
try {
appVariantOutputContext.artifactBundleInfos = getArtifactBundleInfo(getDependencyDiff(), getManifestFile(), getApDir());
FileUtils.writeStringToFile(new File(getOutJsonFile(), "dependencyDiff.json"), JSON.toJSONString(dependencyDiff, true));
} catch (Exception e) {
throw new GradleException(e.getMessage());
}
}
Aggregations