use of com.android.builder.model.AndroidLibrary 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.android.builder.model.AndroidLibrary in project atlas by alibaba.
the class PostProcessManifestTask method getLibManifestDepenendyMap.
public Multimap<String, File> getLibManifestDepenendyMap() {
Multimap<String, File> maps = HashMultimap.create();
List<? extends AndroidLibrary> libs = getAwbLibraries();
if (libs == null || libs.isEmpty()) {
return maps;
}
for (AndroidLibrary mdi : libs) {
for (AndroidLibrary childLib : mdi.getLibraryDependencies()) {
((HashMultimap<String, File>) maps).put(mdi.getName(), childLib.getManifest());
}
}
return maps;
}
use of com.android.builder.model.AndroidLibrary in project atlas by alibaba.
the class PostProcessManifestTask method getLibManifestMap.
public Map<String, File> getLibManifestMap() {
Map<String, File> maps = Maps.newHashMap();
List<? extends AndroidLibrary> libs = getAwbLibraries();
if (libs == null || libs.isEmpty()) {
return Collections.emptyMap();
}
for (AndroidLibrary mdi : libs) {
((HashMap<String, File>) maps).put(mdi.getName(), mdi.getManifest());
}
return maps;
}
use of com.android.builder.model.AndroidLibrary in project atlas by alibaba.
the class PreProcessManifestTask method addAwbManifest2Merge.
private void addAwbManifest2Merge() {
AtlasExtension atlasExtension = appVariantContext.getAtlasExtension();
for (final BaseVariantOutputData vod : appVariantContext.getVariantData().getOutputs()) {
ManifestProcessorTask manifestProcessorTask = vod.manifestProcessorTask;
Set<String> notMergedArtifacts = Sets.newHashSet();
if (null != atlasExtension.getManifestOptions() && null != atlasExtension.getManifestOptions().getNotMergedBundles()) {
notMergedArtifacts = atlasExtension.getManifestOptions().getNotMergedBundles();
}
if (manifestProcessorTask instanceof MergeManifests) {
MergeManifests mergeManifests = (MergeManifests) manifestProcessorTask;
VariantScope variantScope = appVariantContext.getScope();
GradleVariantConfiguration config = variantScope.getVariantConfiguration();
AndroidDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(config.getFullName());
if (null == dependencyTree) {
throw new StopExecutionException("DependencyTree cannot be null!");
}
List<? extends AndroidLibrary> awbManifests = ManifestDependencyUtil.getManifestDependencies(dependencyTree.getAwbBundles(), notMergedArtifacts, getLogger());
for (AndroidLibrary manifest : awbManifests) {
getLogger().info("[MTLPlugin]Add manifest:" + manifest.getName() + ",path is:" + manifest.getManifest().getAbsolutePath());
}
//FIXME 不加这一步,每次的getibraries 都会从mapping里去重新计算
mergeManifests.setLibraries(mergeManifests.getLibraries());
mergeManifests.getLibraries().addAll(awbManifests);
}
}
}
use of com.android.builder.model.AndroidLibrary in project atlas by alibaba.
the class PrepareAwoBundleTask method doFullTaskAction.
@TaskAction
public void doFullTaskAction() throws IOException {
AwbBundle awbBundle = libVariantContext.getAwbBundle();
prepare(awbBundle.getBundle(), awbBundle.getFolder(), true);
List<SoLibrary> soLibraries = awbBundle.getSoLibraries();
for (final SoLibrary soLibrary : soLibraries) {
prepare(soLibrary.getSoLibFile(), soLibrary.getFolder(), false);
}
List<? extends AndroidLibrary> aarBundles = awbBundle.getLibraryDependencies();
for (final AndroidLibrary libraryDependency : aarBundles) {
if (libraryDependency instanceof AarBundle) {
AarBundle aarBundle = (AarBundle) libraryDependency;
prepare(aarBundle.getBundle(), aarBundle.getFolder(), true);
}
}
}
Aggregations