Search in sources :

Example 21 with AndroidDependencyTree

use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.

the class AwbProguradHook method hookProguardTask.

/**
     * hook混淆的任务,加入awb的混淆配置
     *
     * @param appVariantContext
     */
public void hookProguardTask(final AppVariantContext appVariantContext) {
    final VariantScope variantScope = appVariantContext.getScope();
    List<TransformTask> proguaradTransformTasks = getTransformTaskByTransformType(appVariantContext, ProGuardTransform.class);
    for (TransformTask proguaradTransformTask : proguaradTransformTasks) {
        final ProGuardTransform proGuardTransform = (ProGuardTransform) proguaradTransformTask.getTransform();
        if (null != proGuardTransform) {
            proguaradTransformTask.doFirst(new Action<Task>() {

                @Override
                public void execute(Task task) {
                    GlobalScope globalScope = variantScope.getGlobalScope();
                    File proguardOut = new File(Joiner.on(File.separatorChar).join(String.valueOf(globalScope.getBuildDir()), FD_OUTPUTS, "mapping", variantScope.getVariantConfiguration().getDirName()));
                    //为了方便排查,先把configuration打印到目录
                    proGuardTransform.printconfiguration(new File(proguardOut, "tmp_config.cfg"));
                    final File outConfigFile = new File(proguardOut, "awb_config.cfg");
                    //增加awb的配置
                    AndroidDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantScope.getVariantConfiguration().getFullName());
                    if (null == dependencyTree) {
                        throw new StopExecutionException("DependencyTree cannot be null!");
                    }
                    if (dependencyTree.getAwbBundles().size() > 0) {
                        BaseVariantOutputData vod = appVariantContext.getVariantData().getOutputs().get(0);
                        AppVariantOutputContext appVariantOutputContext = getAppVariantOutputContext(appVariantContext, vod);
                        File awbObfuscatedDir = new File(globalScope.getIntermediatesDir(), "/classes-proguard/" + variantScope.getVariantConfiguration().getDirName());
                        AwbProguardConfiguration awbProguardConfiguration = new AwbProguardConfiguration(appVariantOutputContext.getAwbTransformMap().values(), awbObfuscatedDir, appVariantOutputContext);
                        try {
                            awbProguardConfiguration.printConfigFile(outConfigFile);
                        } catch (IOException e) {
                            throw new GradleException("", e);
                        }
                        proGuardTransform.setConfigurationFiles(new Supplier<Collection<File>>() {

                            @Override
                            public Collection<File> get() {
                                Set<File> proguardFiles = new HashSet<File>();
                                ((HashSet<File>) proguardFiles).add(outConfigFile);
                                return proguardFiles;
                            }
                        });
                    }
                    File mappingFile = null;
                    if (null != appVariantContext.apContext.getApExploredFolder() && appVariantContext.apContext.getApExploredFolder().exists()) {
                        mappingFile = new File(appVariantContext.apContext.getApExploredFolder(), "mapping.txt");
                    } else {
                        mappingFile = new File(appVariantContext.getScope().getGlobalScope().getProject().getProjectDir(), "mapping.txt");
                    }
                    if (null != mappingFile && mappingFile.exists()) {
                        proGuardTransform.applyTestedMapping(mappingFile);
                    }
                }
            });
        }
    }
}
Also used : GlobalScope(com.android.build.gradle.internal.scope.GlobalScope) VariantScope(com.android.build.gradle.internal.scope.VariantScope) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) Task(org.gradle.api.Task) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) BaseVariantOutputData(com.android.build.gradle.internal.variant.BaseVariantOutputData) AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext) IOException(java.io.IOException) ProGuardTransform(com.android.build.gradle.internal.transforms.ProGuardTransform) StopExecutionException(org.gradle.api.tasks.StopExecutionException) AwbProguardConfiguration(com.taobao.android.builder.tasks.app.bundle.AwbProguardConfiguration) GradleException(org.gradle.api.GradleException) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) Supplier(java.util.function.Supplier) File(java.io.File)

Example 22 with AndroidDependencyTree

use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.

the class ApkFileListUtils method recordApkFileInfos.

/**
     * 记录apk文件的资源信息
     */
public static void recordApkFileInfos(AppVariantContext appVariantContext) {
    if (inited) {
        return;
    }
    inited = true;
    List<File> mainBundleResFolders = new ArrayList<File>();
    mainBundleResFolders.add(appVariantContext.getScope().getVariantData().mergeResourcesTask.getOutputDir());
    prepareApkFileList(appVariantContext.getScope().getVariantData().mergeAssetsTask.getOutputDir(), "assets");
    for (File resFolder : mainBundleResFolders) {
        prepareApkFileList(resFolder, "res");
    }
    // 记录各自bundle的资源信息
    AndroidDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
    if (null == dependencyTree) {
        throw new StopExecutionException("DependencyTree cannot be null!");
    }
    List<AwbBundle> libs = dependencyTree.getAwbBundles();
    for (AwbBundle awbLib : libs) {
        File mergeAssertFolder = appVariantContext.getMergeAssets(awbLib);
        File mergeResFolder = appVariantContext.getMergeResources(awbLib);
        String awbName = awbLib.getName();
        prepareApkFileList(mergeAssertFolder, "assets", awbName);
        prepareApkFileList(mergeResFolder, "res", awbName);
    }
}
Also used : StopExecutionException(org.gradle.api.tasks.StopExecutionException) ArrayList(java.util.ArrayList) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File)

Example 23 with AndroidDependencyTree

use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.

the class BundleInfoUtils method setupAwbBundleInfos.

public static void setupAwbBundleInfos(AppVariantContext appVariantContext) throws IOException, DocumentException {
    String apkVersion = appVariantContext.getVariantConfiguration().getVersionName();
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
    /**
         * name 是artifictId
         */
    Map<String, BundleInfo> bundleInfoMap = getBundleInfoMap(appVariantContext);
    for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        update(awbBundle, bundleInfoMap, appVariantContext, apkVersion);
    }
}
Also used : BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle)

Example 24 with AndroidDependencyTree

use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.

the class DiffBundleInfoTask method getArtifactBundleInfo.

private Set<ArtifactBundleInfo> getArtifactBundleInfo(DependencyDiff dependencyDiff, File mainfestFile, File apDir) throws IOException, DocumentException {
    Set<ArtifactBundleInfo> artifactBundleInfos = new HashSet<ArtifactBundleInfo>();
    if (null == apDir) {
        throw new GradleException("No Ap dependency found!");
    }
    File apManifest = new File(apDir, "AndroidManifest.xml");
    String apVersion = null;
    try {
        apVersion = ManifestFileUtils.getVersionName(apManifest);
    } catch (Exception e) {
        throw new GradleException(e.getMessage(), e);
    }
    // 1. 首先添加主bundle
    ArtifactBundleInfo mainBundleInfo = getMainArtifactBundInfo(mainfestFile);
    mainBundleInfo.setBaseVersion(apVersion);
    mainBundleInfo.setMainBundle(true);
    mainBundleInfo.setVersion(appVariantOutputContext.getVariantContext().getVariantConfiguration().getVersionName());
    if (dependencyDiff.getMainDexDiffs().size() > 0) {
        mainBundleInfo.setDiffType(DiffType.MODIFY);
    } else {
        mainBundleInfo.setDiffType(DiffType.NONE);
    }
    artifactBundleInfos.add(mainBundleInfo);
    // 2. 添加各自的bundle
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantOutputContext.getVariantContext().getVariantConfiguration().getFullName());
    for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        BundleInfo bundleInfo = awbBundle.bundleInfo;
        ArtifactBundleInfo awbBundleInfo = new ArtifactBundleInfo();
        awbBundleInfo.setMainBundle(false);
        awbBundleInfo.setDependency(bundleInfo.getDependency());
        awbBundleInfo.setPkgName(bundleInfo.getPkgName());
        awbBundleInfo.setApplicationName(bundleInfo.getApplicationName());
        awbBundleInfo.setArtifactId(awbBundle.getResolvedCoordinates().getArtifactId());
        awbBundleInfo.setName(bundleInfo.getName());
        String version = bundleInfo.getVersion();
        if (version.indexOf("@") > 0) {
            String[] arr = version.split("@");
            version = arr[arr.length - 1];
        }
        awbBundleInfo.setVersion(version);
        String libBundleName = getBundleName(awbBundle);
        if (dependencyDiff.getAwbDiffs().contains(libBundleName)) {
            if (dependencyDiff.getNewAwbs().contains(libBundleName)) {
                awbBundleInfo.setDiffType(DiffType.ADD);
            } else {
                awbBundleInfo.setDiffType(DiffType.MODIFY);
            }
        } else {
            awbBundleInfo.setDiffType(DiffType.NONE);
        }
        artifactBundleInfos.add(awbBundleInfo);
    }
    return artifactBundleInfos;
}
Also used : ArtifactBundleInfo(com.taobao.android.object.ArtifactBundleInfo) BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) ArtifactBundleInfo(com.taobao.android.object.ArtifactBundleInfo) GradleException(org.gradle.api.GradleException) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) HashSet(java.util.HashSet)

Aggregations

AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)24 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)19 ArrayList (java.util.ArrayList)14 File (java.io.File)12 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)9 TaskAction (org.gradle.api.tasks.TaskAction)9 GradleException (org.gradle.api.GradleException)8 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)5 DefaultTask (org.gradle.api.DefaultTask)5 BundleInfo (com.taobao.android.builder.tools.bundleinfo.model.BundleInfo)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 StopExecutionException (org.gradle.api.tasks.StopExecutionException)3 DataBindingBuilder (android.databinding.tool.DataBindingBuilder)2 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)2 AwbTransform (com.android.build.gradle.internal.api.AwbTransform)2 VariantScope (com.android.build.gradle.internal.scope.VariantScope)2 BaseVariantOutputData (com.android.build.gradle.internal.variant.BaseVariantOutputData)2 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 AwoDependency (com.taobao.android.builder.tasks.awo.utils.AwoDependency)2