Search in sources :

Example 6 with VariantScope

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));
}
Also used : VariantScope(com.android.build.gradle.internal.scope.VariantScope) AndroidLibrary(com.android.builder.model.AndroidLibrary) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 7 with VariantScope

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;
}
Also used : GlobalScope(com.android.build.gradle.internal.scope.GlobalScope) BaseVariantOutput(com.android.build.gradle.api.BaseVariantOutput) VariantScope(com.android.build.gradle.internal.scope.VariantScope) GradleException(org.gradle.api.GradleException) AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree)

Example 8 with VariantScope

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);
//        }
}
Also used : GlobalScope(com.android.build.gradle.internal.scope.GlobalScope) VariantScope(com.android.build.gradle.internal.scope.VariantScope) AndroidLibrary(com.android.builder.model.AndroidLibrary) AssetSet(com.android.ide.common.res2.AssetSet) List(java.util.List) File(java.io.File) VariantConfiguration(com.android.builder.core.VariantConfiguration)

Example 9 with VariantScope

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));
}
Also used : VariantScope(com.android.build.gradle.internal.scope.VariantScope)

Example 10 with VariantScope

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);
        }
    }
}
Also used : AtlasExtension(com.taobao.android.builder.extension.AtlasExtension) VariantScope(com.android.build.gradle.internal.scope.VariantScope) MergeManifests(com.android.build.gradle.tasks.MergeManifests) StopExecutionException(org.gradle.api.tasks.StopExecutionException) AndroidLibrary(com.android.builder.model.AndroidLibrary) GradleVariantConfiguration(com.android.build.gradle.internal.core.GradleVariantConfiguration) BaseVariantOutputData(com.android.build.gradle.internal.variant.BaseVariantOutputData) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) ManifestProcessorTask(com.android.build.gradle.tasks.ManifestProcessorTask)

Aggregations

VariantScope (com.android.build.gradle.internal.scope.VariantScope)16 File (java.io.File)12 IOException (java.io.IOException)8 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)7 GradleException (org.gradle.api.GradleException)7 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)6 AndroidLibrary (com.android.builder.model.AndroidLibrary)5 BaseVariantOutput (com.android.build.gradle.api.BaseVariantOutput)4 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)4 GradleVariantConfiguration (com.android.build.gradle.internal.core.GradleVariantConfiguration)3 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)3 AtlasExtension (com.taobao.android.builder.extension.AtlasExtension)3 JarFile (java.util.jar.JarFile)3 StopExecutionException (org.gradle.api.tasks.StopExecutionException)3 TransformTask (com.android.build.gradle.internal.pipeline.TransformTask)2 BaseVariantOutputData (com.android.build.gradle.internal.variant.BaseVariantOutputData)2 ManifestProcessorTask (com.android.build.gradle.tasks.ManifestProcessorTask)2 MergeManifests (com.android.build.gradle.tasks.MergeManifests)2 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)2 ArrayList (java.util.ArrayList)2