Search in sources :

Example 1 with ClazzRefInfo

use of com.taobao.android.builder.tools.proguard.dump.ClazzRefInfo in project atlas by alibaba.

the class AtlasProguardHelper method generateKeepFile.

@NotNull
private static File generateKeepFile(List<AwbBundle> awbBundles, File dir) throws IOException {
    KeepConverter refClazzContainer = new KeepConverter();
    for (AwbBundle awbBundle : awbBundles) {
        if (null != awbBundle.getKeepProguardFile() && awbBundle.getKeepProguardFile().exists()) {
            String json = FileUtils.readFileToString(awbBundle.getKeepProguardFile());
            Map<String, ClazzRefInfo> refClazzMap = JSON.parseObject(json, new TypeReference<Map<String, ClazzRefInfo>>() {
            });
            refClazzContainer.addRefClazz(refClazzMap);
        } else {
            sLogger.error("missing " + awbBundle.getKeepProguardFile().getAbsolutePath());
        }
    }
    File maindexkeep = new File(dir, "maindexkeep.cfg");
    FileUtils.writeLines(maindexkeep, refClazzContainer.convertToKeeplines());
    return maindexkeep;
}
Also used : KeepConverter(com.taobao.android.builder.tools.proguard.dump.KeepConverter) ClazzRefInfo(com.taobao.android.builder.tools.proguard.dump.ClazzRefInfo) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) JarFile(java.util.jar.JarFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ClazzRefInfo

use of com.taobao.android.builder.tools.proguard.dump.ClazzRefInfo 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)

Aggregations

AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)2 ClazzRefInfo (com.taobao.android.builder.tools.proguard.dump.ClazzRefInfo)2 File (java.io.File)2 AwbTransform (com.android.build.gradle.internal.api.AwbTransform)1 KeepConverter (com.taobao.android.builder.tools.proguard.dump.KeepConverter)1 JarFile (java.util.jar.JarFile)1 NotNull (org.jetbrains.annotations.NotNull)1 Configuration (proguard.Configuration)1 ProGuard (proguard.ProGuard)1 ClassPool (proguard.classfile.ClassPool)1