use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.
the class PrepareMainDexJarsTask method doFullTaskAction.
@TaskAction
public void doFullTaskAction() {
AndroidDependencyTree libDependencyTree = AtlasBuildContext.libDependencyTrees.get(this.getVariantName());
if (null == libDependencyTree) {
throw new GradleException("The libDependencyTree is null!");
}
List<File> jarList = new AwoDependency(libVariantContext).getDependencyJar(libDependencyTree);
libVariantContext.setJarDexList(jarList);
}
use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.
the class PrepareAaptTask method doExecute.
//MergeResources mergeResources;
@TaskAction
public void doExecute() {
AaptOptions aaptOptions = processAndroidResources.getAaptOptions();
if (null == aaptOptions) {
aaptOptions = new AaptOptions();
}
if (null == aaptOptions.getAdditionalParameters()) {
aaptOptions.setAdditionalParameters(new ArrayList<String>());
}
if (!appVariantContext.getAtlasExtension().getTBuildConfig().getAaptConstantId()) {
aaptOptions.getAdditionalParameters().add("--non-constant-id");
}
processAndroidResources.setAndroidBuilder(getBuilder());
processAndroidResources.setAaptOptions(aaptOptions);
ApContext apContext = appVariantContext.apContext;
if (null != apContext && apContext.getBaseApk().exists()) {
File baseApk = appVariantContext.apContext.getBaseApk();
//需要增加-b参数
if (!aaptOptions.getAdditionalParameters().contains("-B")) {
aaptOptions.getAdditionalParameters().add("-B");
aaptOptions.getAdditionalParameters().add(baseApk.getAbsolutePath());
}
//AndroidManifest文件不能有修改OR在patch的时候忽略,目前选择在patch的时候忽略
}
//TODO update merge resource
//mergeResources.setAndroidBuilder(AtlasBuildContext.androidBuilder);
}
use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.
the class PrepareSoLibTask method generate.
/**
* 生成so的目录
*/
@TaskAction
void generate() {
List<File> scanDirs = new ArrayList<File>();
//先生成主bundle的jnifolder目录
if (!getMainBundleOutputFolder().exists()) {
getMainBundleOutputFolder().mkdirs();
}
for (File jniFolder : getJniFolders()) {
if (jniFolder.exists() && jniFolder.isDirectory()) {
NativeSoUtils.copyLocalNativeLibraries(jniFolder, getMainBundleOutputFolder(), getSupportAbis(), getRemoveSoFiles(), getILogger());
}
}
scanDirs.add(getMainBundleOutputFolder());
//增加主bundle依赖的solib的so
for (SoLibrary mainSoLib : getMainDexSoLibraries()) {
File explodeFolder = mainSoLib.getFolder();
if (explodeFolder.exists() && explodeFolder.isDirectory()) {
NativeSoUtils.copyLocalNativeLibraries(explodeFolder, getMainBundleOutputFolder(), getSupportAbis(), getRemoveSoFiles(), getILogger());
}
}
//处理awb bundle的so
for (AwbBundle awbLib : getAwbLibs()) {
File awbOutputFolder = new File(appVariantOutputContext.getAwbJniFolder(awbLib), "lib");
awbOutputFolder.mkdirs();
scanDirs.add(awbOutputFolder);
File awbJniFolder = awbLib.getJniFolder();
if (awbJniFolder.exists() && awbJniFolder.isDirectory()) {
NativeSoUtils.copyLocalNativeLibraries(awbJniFolder, awbOutputFolder, getSupportAbis(), getRemoveSoFiles(), getILogger());
}
//为了兼容之前老的aar,awb格式
File libJniFolder = new File(awbLib.getFolder(), "libs");
if (libJniFolder.exists() && libJniFolder.isDirectory()) {
NativeSoUtils.copyLocalNativeLibraries(libJniFolder, awbOutputFolder, getSupportAbis(), getRemoveSoFiles(), getILogger());
}
List<? extends AndroidLibrary> deps = awbLib.getLibraryDependencies();
for (AndroidLibrary dep : deps) {
File depJniFolder = dep.getJniFolder();
if (depJniFolder.exists() && depJniFolder.isDirectory()) {
NativeSoUtils.copyLocalNativeLibraries(depJniFolder, awbOutputFolder, getSupportAbis(), getRemoveSoFiles(), getILogger());
}
//为了兼容之前老的aar,awb格式
File depLibsFolder = new File(dep.getFolder(), "libs");
if (depLibsFolder.exists() && depLibsFolder.isDirectory()) {
NativeSoUtils.copyLocalNativeLibraries(depLibsFolder, awbOutputFolder, getSupportAbis(), getRemoveSoFiles(), getILogger());
}
}
List<SoLibrary> solibs = awbLib.getSoLibraries();
if (null != solibs) {
for (SoLibrary solib : solibs) {
File explodeFolder = solib.getFolder();
if (explodeFolder.exists() && explodeFolder.isDirectory()) {
NativeSoUtils.copyLocalNativeLibraries(explodeFolder, awbOutputFolder, getSupportAbis(), getRemoveSoFiles(), getILogger());
}
}
}
}
//判断是否有重复的so文件
// 进行重复文件的查询
Map<String, Multimap<String, File>> soMaps = NativeSoUtils.getAbiSoFiles(getSupportAbis(), getRemoveSoFiles(), scanDirs);
boolean hasDup = false;
for (Map.Entry<String, Multimap<String, File>> entry : soMaps.entrySet()) {
String abi = entry.getKey();
Multimap<String, File> soFiles = soMaps.get(abi);
for (String soKey : soFiles.keys()) {
if (soFiles.get(soKey).size() > 1) {
getILogger().warning("[SO Duplicate][" + abi + "]:" + StringUtils.join(soFiles.get(soKey), ","));
hasDup = true;
} else {
getILogger().verbose("[SO][" + abi + "]:" + StringUtils.join(soFiles.get(soKey), ","));
}
}
}
// if (hasDup && getFailOnDuplicateSo()) {
// throw new RuntimeException("SO file has duplicate files!See detail info!");
// }
}
use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.
the class PrepareAPTask method generate.
/**
* 生成so的目录
*/
@TaskAction
void generate() {
Project project = getProject();
File apBaseFile = null;
if (null != apContext.getApFile() && apContext.getApFile().exists()) {
apBaseFile = apContext.getApFile();
} else if (StringUtils.isNotBlank(apContext.getApDependency())) {
Dependency dependency = project.getDependencies().create(apContext.getApDependency());
Configuration configuration = project.getConfigurations().detachedConfiguration(dependency);
configuration.setTransitive(false);
for (File file : configuration.getFiles()) {
if (file.getName().endsWith(".ap")) {
apBaseFile = file;
break;
}
}
}
if (null != apBaseFile && apBaseFile.exists()) {
File explodedDir = project.file(project.getBuildDir().getAbsolutePath() + "/" + FD_INTERMEDIATES + "/exploded-ap" + "/");
ZipUtils.unzip(apBaseFile, explodedDir.getAbsolutePath());
apContext.setApExploredFolder(explodedDir);
apContext.setBaseApk(new File(explodedDir, "android.apk"));
}
}
use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.
the class ProcessResAwbsTask method run.
@TaskAction
void run() throws ExecutionException, InterruptedException {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == androidDependencyTree) {
return;
}
final VariantOutputScope outputScope = appVariantOutputContext.getOutputScope();
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
List<Runnable> runnables = new ArrayList<>();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
runnables.add(new Runnable() {
@Override
public void run() {
File symbolLocation = new File(outputScope.getGlobalScope().getIntermediatesDir(), "awb-symbols/" + outputScope.getVariantScope().getVariantConfiguration().getDirName() + "/" + awbBundle.getName());
//把资源写入ap中,给debug用
if ("debug".equals(appVariantOutputContext.getVariantContext().getBaseVariantData().getName())) {
appVariantOutputContext.appBuildInfo.getOtherFilesMap().put("awo/" + awbBundle.getPackageName() + ".R.txt", new File(symbolLocation, "R.txt"));
}
ProcessAwbAndroidResources.ConfigAction configAction = new ProcessAwbAndroidResources.ConfigAction(outputScope, symbolLocation, true, awbBundle, (AtlasBuilder) getBuilder(), appVariantOutputContext);
ProcessAwbAndroidResources processAwbAndroidResources = TaskCreater.create(getProject(), configAction.getName(), configAction.getType());
configAction.execute(processAwbAndroidResources);
processAwbAndroidResources.execute();
}
});
}
executorServicesHelper.execute(runnables);
}
Aggregations