use of com.android.build.gradle.internal.scope.VariantScope in project atlas by alibaba.
the class AtlasProguardHelper method applyBundleProguardConfigration.
// TODO move
// public static Set<String> blackList = Sets.newHashSet("com.alibaba:eaze","com.alibaba.mobileim:IMKit");
public static void applyBundleProguardConfigration(final AppVariantContext appVariantContext, ProGuardTransform proGuardTransform) {
Set<String> blackList = appVariantContext.getAtlasExtension().getTBuildConfig().getBundleProguardConfigBlackList();
List<File> proguardFiles = new ArrayList<>();
VariantScope variantScope = appVariantContext.getScope();
for (AwbBundle awbBundle : AtlasBuildContext.androidDependencyTrees.get(variantScope.getVariantConfiguration().getFullName()).getAwbBundles()) {
for (AndroidLibrary androidDependency : awbBundle.getAllLibraryAars()) {
File proguardRules = androidDependency.getProguardRules();
String groupName = androidDependency.getResolvedCoordinates().getGroupId() + ":" + androidDependency.getResolvedCoordinates().getArtifactId();
if (blackList.contains(groupName)) {
sLogger.info("[proguard] skip proguard from " + androidDependency.getResolvedCoordinates());
continue;
}
if (proguardRules.isFile()) {
proguardFiles.add(proguardRules);
sLogger.warn("[proguard] load proguard from " + androidDependency.getResolvedCoordinates());
} else {
sLogger.info("[proguard] missing proguard from " + androidDependency.getResolvedCoordinates());
}
}
}
proGuardTransform.setConfigurationFiles(appVariantContext.getScope().getGlobalScope().getProject().files(proguardFiles));
}
use of com.android.build.gradle.internal.scope.VariantScope in project atlas by alibaba.
the class AtlasProguardHelper method applyBundleInOutConfigration.
public static File applyBundleInOutConfigration(final AppVariantContext appVariantContext, ProGuardTransform proGuardTransform) {
VariantScope variantScope = appVariantContext.getScope();
GlobalScope globalScope = variantScope.getGlobalScope();
File proguardOut = new File(Joiner.on(File.separatorChar).join(String.valueOf(globalScope.getBuildDir()), FD_OUTPUTS, "mapping", variantScope.getVariantConfiguration().getDirName()));
File awbInOutConfig = new File(proguardOut, "awb_inout_config.cfg");
// Add awb configuration
AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantScope.getVariantConfiguration().getFullName());
if (dependencyTree.getAwbBundles().size() > 0) {
BaseVariantOutput vod = (BaseVariantOutput) appVariantContext.getVariantOutputData().iterator().next();
AppVariantOutputContext appVariantOutputContext = appVariantContext.getAppVariantOutputContext(ApkDataUtils.get(vod));
File awbObfuscatedDir = new File(globalScope.getIntermediatesDir(), "/classes-proguard/" + variantScope.getVariantConfiguration().getDirName());
AwbProguardConfiguration awbProguardConfiguration = new AwbProguardConfiguration(appVariantOutputContext.getAwbTransformMap().values(), awbObfuscatedDir, appVariantOutputContext);
try {
configs = awbProguardConfiguration.printConfigFile(awbInOutConfig);
} catch (IOException e) {
throw new GradleException("", e);
}
proGuardTransform.setConfigurationFiles(appVariantContext.getScope().getGlobalScope().getProject().files(awbInOutConfig));
}
return awbInOutConfig;
}
use of com.android.build.gradle.internal.scope.VariantScope in project atlas by alibaba.
the class MergeAwbAssetConfigAction method execute.
@Override
public void execute(MergeSourceSetFolders task) {
final VariantScope scope = variantContext.getScope();
BaseVariantData<? extends BaseVariantOutputData> variantData = scope.getVariantData();
final VariantConfiguration variantConfig = variantData.getVariantConfiguration();
task.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
task.setVariantName(variantConfig.getFullName());
task.setIncrementalFolder(scope.getIncrementalDir(getName()));
ConventionMappingHelper.map(task, "inputDirectorySets", new Callable<List<AssetSet>>() {
@Override
public List<AssetSet> call() throws Exception {
List<AssetSet> assetSets = Lists.newArrayList();
List<? extends AndroidLibrary> bundleDeps = awbBundle.getLibraryDependencies();
// the list of dependency must be reversed to use the right overlay order.
for (int n = bundleDeps.size() - 1; n >= 0; n--) {
AndroidLibrary dependency = bundleDeps.get(n);
File assetFolder = dependency.getAssetsFolder();
if (assetFolder.isDirectory()) {
AssetSet assetSet = new AssetSet(dependency.getFolder().getName());
assetSet.addSource(assetFolder);
assetSets.add(assetSet);
}
}
File awbAssetFolder = awbBundle.getAssetsFolder();
if (awbAssetFolder.isDirectory()) {
AssetSet awbAssetSet = new AssetSet(awbBundle.getFolder().getName());
awbAssetSet.addSource(awbAssetFolder);
assetSets.add(awbAssetSet);
}
return assetSets;
}
});
ConventionMappingHelper.map(task, "outputDir", new Callable<File>() {
@Override
public File call() throws Exception {
GlobalScope globalScope = scope.getGlobalScope();
return variantContext.getMergeAssets(awbBundle);
}
});
// if (variantContext instanceof AppVariantContext) {
// AppVariantContext appVariantContext = (AppVariantContext) variantContext;
// appVariantContext.getAwbMergeAssetTasks().put(awbBundle.getName(), task);
// }
}
use of com.android.build.gradle.internal.scope.VariantScope in project atlas by alibaba.
the class AwbDataBindingProcessLayoutsConfigAction method execute.
@Override
public void execute(DataBindingProcessLayoutsTask task) {
VariantScope variantScope = appVariantContext.getScope();
task.setXmlProcessor(AwbXmlProcessor.getLayoutXmlProcessor(appVariantContext, awbBundle, dataBindingBuilder));
task.setSdkDir(variantScope.getGlobalScope().getSdkHandler().getSdkFolder());
task.setMinSdk(variantScope.getVariantConfiguration().getMinSdkVersion().getApiLevel());
task.setLayoutInputFolder(appVariantContext.getAwbMergeResourcesOutputDir(awbBundle));
task.setLayoutOutputFolder(appVariantContext.getAwbLayoutFolderOutputForDataBinding(awbBundle));
task.setXmlInfoOutFolder(appVariantContext.getAwbLayoutInfoOutputForDataBinding(awbBundle));
}
use of com.android.build.gradle.internal.scope.VariantScope 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);
}
}
}
Aggregations