Search in sources :

Example 16 with AwbTransform

use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.

the class AtlasProguardHelper method addChildDependency.

private static void addChildDependency(BundleItem bundleItem, Input input, Map<BundleInfo, AwbTransform> bundleInfoAwbTransformMap) throws IOException {
    List<String> pkgNames = new ArrayList<>();
    input.getAwbBundles().forEach(awbTransform -> pkgNames.add(awbTransform.getAwbBundle().getPackageName()));
    sLogger.info("combine to proguard bundles:" + pkgNames.toString());
    List<AwbTransform> childTransforms = new ArrayList<>();
    sLogger.info("combine to proguard bundles:" + pkgNames.toString());
    for (BundleItem child : bundleItem.children) {
        if (!pkgNames.contains(child.bundleInfo.getPkgName())) {
            childTransforms.add(bundleInfoAwbTransformMap.get(child.bundleInfo));
        } else {
            sLogger.error(child.bundleInfo.getPkgName() + " in proguard bundles so discard from " + bundleItem.bundleInfo.getPkgName() + "libraries...");
        }
        for (BundleInfo sub : child.circles) {
            if (!pkgNames.contains(sub.getPkgName())) {
                childTransforms.add(bundleInfoAwbTransformMap.get(sub));
            } else {
                sLogger.error(sub.getPkgName() + " in proguard bundles so discard from " + bundleItem.bundleInfo.getPkgName() + " libraries...");
            }
        }
    }
    List<AwbBundle> childBundles = new ArrayList<>();
    for (AwbTransform child : childTransforms) {
        input.getLibraries().addAll(child.getInputLibraries());
        // join
        childBundles.add(child.getAwbBundle());
    }
}
Also used : BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) BundleItem(com.taobao.android.builder.tools.bundleinfo.BundleItem) AwbTransform(com.android.build.gradle.internal.api.AwbTransform) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle)

Example 17 with AwbTransform

use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.

the class BundleProguarder method doProguard.

public static void doProguard(AppVariantContext appVariantContext, Input input) throws Exception {
    Configuration configuration = parseConfiguration(appVariantContext, input);
    configuration.dump = input.dump;
    if (null == input.printConfiguration) {
        configuration.printConfiguration = new File(appVariantContext.getAwbProguardDir(input.getAwbBundles().get(0).getAwbBundle()), "proguard.cfg");
    } else {
        configuration.printConfiguration = input.printConfiguration;
    }
    configuration.printSeeds = null;
    configuration.dump = null;
    configuration.obfuscate = false;
    // configuration.optimizationPasses = 1;
    configuration.printUsage = input.printUsage;
    configuration.printMapping = input.printMapping;
    // Execute ProGuard with these options.
    ProGuard proGuard = new ProGuard(configuration);
    System.out.println(">>> start to do proguard");
    proGuard.execute();
    System.out.println("<<< end proguard");
    ClassPool classPool = (ClassPool) ReflectUtils.getField(proGuard, "programClassPool");
    Map<String, ClazzRefInfo> clazzRefInfoMap = BundleProguardDumper.dump(proGuard, input.getDefaultLibraryClasses());
    // Fileoutputs
    for (AwbTransform awbTransform : input.getAwbBundles()) {
        if (!awbTransform.getAwbBundle().isMainBundle()) {
            AwbBundle awbBundle = awbTransform.getAwbBundle();
            File fileOut = new File(appVariantContext.getAwbProguardDir(awbBundle), "keep.json");
            fileOut.delete();
            fileOut.getParentFile().mkdirs();
            FileUtils.write(fileOut, JSON.toJSONString(clazzRefInfoMap));
            awbBundle.setKeepProguardFile(fileOut);
        }
    }
}
Also used : Configuration(proguard.Configuration) ProGuard(proguard.ProGuard) AwbTransform(com.android.build.gradle.internal.api.AwbTransform) ClassPool(proguard.classfile.ClassPool) ClazzRefInfo(com.taobao.android.builder.tools.proguard.dump.ClazzRefInfo) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File)

Example 18 with AwbTransform

use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.

the class AwbProguardConfiguration method printConfigFile.

/**
 * Print the proguard config file to the specified file
 *
 * @param outConfigFile
 */
public List<File> printConfigFile(File outConfigFile) throws IOException {
    List<String> configs = Lists.newArrayList();
    List<File> bundleFiles = Lists.newArrayList();
    // awbProguard for no lib, convenient for predex
    for (AwbTransform awbTransform : awbTransforms) {
        List<File> inputLibraries = Lists.newArrayList();
        String name = awbTransform.getAwbBundle().getName();
        File obuscateDir = new File(awbObfuscatedDir, awbTransform.getAwbBundle().getName());
        obuscateDir.mkdirs();
        if (null != awbTransform.getInputDirs() && awbTransform.getInputDirs().size() > 0) {
            for (File dir : awbTransform.getInputDirs()) {
                if (dir.exists()) {
                    configs.add(INJARS_OPTION + " " + dir.getAbsolutePath());
                    File obsJar = new File(obuscateDir, "inputdir_" + OBUSCATED_JAR);
                    inputLibraries.add(obsJar);
                    configs.add(OUTJARS_OPTION + " " + obsJar.getAbsolutePath());
                }
            }
        }
        Set<String> classNames = new HashSet<>();
        for (File inputLibrary : awbTransform.getInputLibraries()) {
            configs.add(INJARS_OPTION + " " + inputLibrary.getAbsolutePath());
            bundleFiles.add(inputLibrary);
            String fileName = inputLibrary.getName();
            if (classNames.contains(fileName)) {
                fileName = "a" + classNames.size() + "_" + fileName;
            }
            classNames.add(fileName);
            File obsJar = new File(obuscateDir, fileName);
            inputLibraries.add(obsJar);
            configs.add(OUTJARS_OPTION + " " + obsJar.getAbsolutePath());
        }
        // configs.add();
        awbTransform.setInputFiles(inputLibraries);
        awbTransform.getInputDirs().clear();
        awbTransform.getInputLibraries().clear();
        appVariantOutputContext.getAwbTransformMap().put(name, awbTransform);
    }
    FileUtils.writeLines(outConfigFile, configs);
    return bundleFiles;
}
Also used : AwbTransform(com.android.build.gradle.internal.api.AwbTransform) File(java.io.File) HashSet(java.util.HashSet)

Example 19 with AwbTransform

use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.

the class BuildAtlasEnvTask method fillAwbSolibs.

private void fillAwbSolibs(String name, String moudleName, AwbBundle awbBundle) {
    AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get(awbBundle.getName());
    File id = null;
    if ((id = allSolibs.get(name)) == null) {
        id = allSolibs.get(moudleName);
    }
    if (id != null) {
        awbTransform.getLibraryJniLibsInputDir().add(id);
    }
}
Also used : AwbTransform(com.android.build.gradle.internal.api.AwbTransform) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 20 with AwbTransform

use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.

the class BuildAtlasEnvTask method fillAwbAllJavaRes.

private void fillAwbAllJavaRes(String name, String moudleName, AwbBundle awbBundle) {
    AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get(awbBundle.getName());
    File id = null;
    if ((id = allJavaRes.get(name)) == null) {
        id = allJavaRes.get(moudleName);
    }
    if (id != null) {
        awbTransform.getLibraryResourcesInutDir().add(id);
    }
}
Also used : AwbTransform(com.android.build.gradle.internal.api.AwbTransform) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

AwbTransform (com.android.build.gradle.internal.api.AwbTransform)23 File (java.io.File)16 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)12 JarFile (java.util.jar.JarFile)8 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)7 ArrayList (java.util.ArrayList)6 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)5 WaitableExecutor (com.android.ide.common.internal.WaitableExecutor)4 GradleException (org.gradle.api.GradleException)4 Nullable (com.android.annotations.Nullable)3 BaseVariantOutput (com.android.build.gradle.api.BaseVariantOutput)3 AppVariantContext (com.android.build.gradle.internal.api.AppVariantContext)3 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)3 IOException (java.io.IOException)3 TaskAction (org.gradle.api.tasks.TaskAction)3 NonNull (com.android.annotations.NonNull)2 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 AtlasBuildContext (com.taobao.android.builder.AtlasBuildContext)2 BuildAtlasEnvTask (com.taobao.android.builder.tasks.app.BuildAtlasEnvTask)2 BundleItem (com.taobao.android.builder.tools.bundleinfo.BundleItem)2