use of com.taobao.android.builder.dependency.model.AwbBundle in project atlas by alibaba.
the class PrepareBundleInfoTask method collectBundleInfo.
private Map<String, AwbBundle> collectBundleInfo(AppVariantOutputContext appVariantOutputContext) {
List<AwbBundle> awbBundles = AtlasBuildContext.androidDependencyTrees.get(appVariantOutputContext.getVariantData().getName()).getAwbBundles();
Map<String, AwbBundle> map = new HashMap<String, AwbBundle>();
for (AwbBundle awbBundle : awbBundles) {
map.put(awbBundle.getAwbSoName(), awbBundle);
}
return map;
}
use of com.taobao.android.builder.dependency.model.AwbBundle 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 com.taobao.android.builder.dependency.model.AwbBundle 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);
}
use of com.taobao.android.builder.dependency.model.AwbBundle in project atlas by alibaba.
the class DataBindingExportBuildInfoAwbsConfigAction method execute.
@Override
public void execute(MtlParallelTask parallelTask) {
super.execute(parallelTask);
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(parallelTask.getVariantName());
if (null == androidDependencyTree) {
return;
}
DataBindingBuilder dataBindingBuilder = new DataBindingBuilder();
dataBindingBuilder.setPrintMachineReadableOutput(false);
dataBindingBuilder.setDebugLogEnabled(appVariantContext.getProject().getLogger().isDebugEnabled());
List<DefaultTask> tasks = new ArrayList<DefaultTask>();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
AwbDataBindingExportBuildInfoConfigAction exportBuildInfoConfigAction = new AwbDataBindingExportBuildInfoConfigAction(appVariantContext, awbBundle, dataBindingBuilder.getPrintMachineReadableOutput(), dataBindingBuilder);
DataBindingExportBuildInfoTask exportBuildInfoTask = TaskCreater.create(appVariantContext.getProject(), exportBuildInfoConfigAction.getName(), exportBuildInfoConfigAction.getType());
exportBuildInfoConfigAction.execute(exportBuildInfoTask);
tasks.add(exportBuildInfoTask);
}
parallelTask.parallelTask = tasks;
parallelTask.uniqueTaskName = getName();
parallelTask.concurrent = true;
}
use of com.taobao.android.builder.dependency.model.AwbBundle in project atlas by alibaba.
the class DataBindingRenameTask method createAwbPackages.
/**
* 生成so的目录
*/
@TaskAction
void createAwbPackages() throws ExecutionException, InterruptedException {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == androidDependencyTree) {
return;
}
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() {
try {
File dataBindingClazzFolder = appVariantOutputContext.getVariantContext().getJAwbavaOutputDir(awbBundle);
String packageName = ManifestFileUtils.getPackage(awbBundle.getOrgManifestFile());
String appName = appVariantContext.getVariantConfiguration().getOriginalApplicationId();
//删除那些已经存在的类
File dataMapperClazz = new File(dataBindingClazzFolder, "android/databinding/DataBinderMapper.class");
if (!dataMapperClazz.exists()) {
throw new GradleException("missing datamapper class");
}
FileInputStream fileInputStream = new FileInputStream(dataMapperClazz);
ClassReader in1 = new ClassReader(fileInputStream);
ClassWriter cw = new ClassWriter(0);
Map<String, String> reMapping = new HashedMap();
reMapping.put(appName.replace(".", "/") + "/BR", packageName.replace(".", "/") + "/BR");
RemappingClassAdapter remappingClassAdapter = new RemappingClassAdapter(cw, new SimpleRemapper(reMapping));
in1.accept(remappingClassAdapter, 8);
ClassReader in2 = new ClassReader(cw.toByteArray());
ClassWriter cw2 = new ClassWriter(0);
Set<String> renames = new HashSet<String>();
renames.add("android/databinding/DataBinderMapper");
in2.accept(new ClassRenamer(cw2, renames, packageName.replace(".", "/") + "/DataBinderMapper"), 8);
File destClass = new File(dataBindingClazzFolder, packageName.replace(".", "/") + "/DataBinderMapper.class");
destClass.getParentFile().mkdirs();
FileOutputStream fileOutputStream = new FileOutputStream(destClass);
fileOutputStream.write(cw2.toByteArray());
IOUtils.closeQuietly(fileOutputStream);
IOUtils.closeQuietly(fileInputStream);
FileUtils.deleteDirectory(new File(dataBindingClazzFolder, "android/databinding"));
FileUtils.deleteDirectory(new File(dataBindingClazzFolder, "com/android/databinding"));
File appDir = new File(dataBindingClazzFolder, appName.replace(".", "/"));
if (appDir.exists()) {
File[] files = appDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile() && !pathname.isDirectory();
}
});
for (File tmp : files) {
FileUtils.forceDelete(tmp);
}
}
} catch (Throwable e) {
e.printStackTrace();
throw new GradleException("package awb failed");
}
}
});
}
executorServicesHelper.execute(runnables);
}
Aggregations