use of com.android.build.gradle.api.BaseVariantOutput in project atlas by alibaba.
the class MainDexLister method getMainDexList.
public List<String> getMainDexList(Collection<File> files, File mainDexListFile) {
GradleVariantConfiguration config = appVariantContext.getVariantConfiguration();
Set<String> mainDexList = new HashSet<String>();
// Confusion of the map
// Map<String, String> classMap = getClassObfMap(config);
Collection<BaseVariantOutput> collection = appVariantContext.getVariantOutputData();
File manifest = com.android.utils.FileUtils.join(collection.iterator().next().getProcessManifest().getManifestOutputDirectory(), new String[] { collection.iterator().next().getDirName(), "AndroidManifest.xml" });
if (appVariantContext.getScope().getInstantRunBuildContext().isInInstantRunMode()) {
manifest = com.android.utils.FileUtils.join(collection.iterator().next().getProcessManifest().getInstantRunManifestOutputDirectory(), new String[] { collection.iterator().next().getDirName(), "AndroidManifest.xml" });
}
String applicationName = ManifestFileUtils.getApplicationName(manifest);
ClassPool classPool = new ClassPool();
try {
for (File file : files) {
if (file.isFile()) {
classPool.insertClassPath(file.getAbsolutePath());
} else {
classPool.appendClassPath(file.getAbsolutePath());
}
}
} catch (NotFoundException e) {
throw new GradleException(e.getMessage(), e);
}
TBuildConfig tBuildConfig = appVariantContext.getAtlasExtension().getTBuildConfig();
HashSet handleList = new HashSet<String>();
Set<String> headClasses = new LinkedHashSet<>();
headClasses.add(applicationName);
headClasses.add("android.taobao.atlas.bridge.BridgeApplicationDelegate");
headClasses.addAll(multiDexConfig.getFirstDexClasses());
List<String> maindexListClazz = new ArrayList<String>();
String preLaunchStr = tBuildConfig.getPreLaunch();
if (!org.apache.commons.lang3.StringUtils.isEmpty(preLaunchStr)) {
String[] launchArray = preLaunchStr.split("\\|");
if (launchArray.length > 0) {
for (String launchItem : launchArray) {
String[] launchInfo = launchItem.split(":");
String clazzName = launchInfo[0];
headClasses.add(clazzName);
}
}
}
for (String clazz : headClasses) {
clazz = clazz.replaceAll("\\.", "/") + ".class";
maindexListClazz.add(clazz);
}
for (String headClass : headClasses) {
addRefClazz(classPool, headClass, mainDexList, handleList, "");
}
// get manifest
for (String newLine : mainDexList) {
newLine = newLine.replaceAll("\\.", "/") + ".class";
maindexListClazz.add(newLine);
}
for (String className : headClasses) {
className = className.replaceAll("\\.", "/") + ".class";
maindexListClazz.add(className);
}
if (multiDexConfig.getMainDexListCount() != 0) {
maindexListClazz = maindexListClazz.subList(0, multiDexConfig.getMainDexListCount());
}
try {
FileUtils.writeLines(mainDexListFile, maindexListClazz);
} catch (IOException e) {
e.printStackTrace();
}
return maindexListClazz;
}
use of com.android.build.gradle.api.BaseVariantOutput 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.api.BaseVariantOutput in project atlas by alibaba.
the class AtlasTransformUtils method getTransformInputs.
public static Collection<File> getTransformInputs(AppVariantContext appVariantContext, TransformInvocation invocation) {
ImmutableSet.Builder<File> builder = ImmutableSet.builder();
Collection<File> transformInputs = TransformInputUtil.getAllFiles(invocation.getInputs());
builder.addAll(transformInputs);
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getVariantConfiguration().getFullName());
if (atlasDependencyTree.getAwbBundles().size() > 0) {
BaseVariantOutput vod = (BaseVariantOutput) appVariantContext.getVariantOutputData().iterator().next();
AppVariantOutputContext appVariantOutputContext = appVariantContext.getAppVariantOutputContext(ApkDataUtils.get(vod));
Collection<AwbTransform> awbTransforms = appVariantOutputContext.getAwbTransformMap().values();
awbTransforms.forEach(awbTransform -> {
builder.addAll(awbTransform.getInputLibraries());
});
}
return builder.build();
}
use of com.android.build.gradle.api.BaseVariantOutput in project atlas by alibaba.
the class MtlTransformInjector method injectTasks.
public void injectTasks(List<MtlTransformContext> mtlTaskContexts) {
for (final Object vod : appVariantContext.getVariantOutputData()) {
for (MtlTransformContext mtlTransformContext : mtlTaskContexts) {
TransformTask transformTask = findTransformTask(mtlTransformContext);
TransformTask injectedTask = appVariantContext.getInjectTransformManager().addInjectTransformBeforeTransform(transformTask.getTransform().getClass(), TransformManager.createTransform(appVariantContext, mtlTransformContext.getTransformTask(), (BaseVariantOutput) vod), appVariantContext.getScope());
injectedTask.dependsOn(appVariantContext.getVariantData().compileTask);
}
}
}
use of com.android.build.gradle.api.BaseVariantOutput in project atlas by alibaba.
the class AtlasProguardHelper method doBundleProguard.
public static void doBundleProguard(final AppVariantContext appVariantContext, List<File> mainDexJars) throws Exception {
Profiler.enter("preparebundleproguard");
VariantScope variantScope = appVariantContext.getScope();
AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantScope.getVariantConfiguration().getFullName());
if (dependencyTree.getAwbBundles().isEmpty()) {
return;
}
List<File> libs = new ArrayList<>(appVariantContext.getScope().getGlobalScope().getAndroidBuilder().getBootClasspath(true));
// All dependent classes
Profiler.enter("getDefaultClasses");
Set<String> defaultLibClasses = getClassList(libs);
Profiler.release();
libs.addAll(mainDexJars);
// Get the basic proguard configuration
List<File> defaultProguardFiles = new ArrayList<>(appVariantContext.getVariantConfiguration().getBuildType().getProguardFiles());
Collections.sort(defaultProguardFiles);
BaseVariantOutput vod = (BaseVariantOutput) appVariantContext.getVariantOutputData().iterator().next();
AppVariantOutputContext appVariantOutputContext = appVariantContext.getAppVariantOutputContext(ApkDataUtils.get(vod));
int parallelCount = appVariantContext.getAtlasExtension().getTBuildConfig().getProguardParallelCount();
// //FIXME
// parallelCount = 1;
Map<BundleInfo, AwbTransform> bundleInfoAwbTransformMap = new HashMap<>();
for (AwbTransform awbTransform : appVariantOutputContext.getAwbTransformMap().values()) {
bundleInfoAwbTransformMap.put(awbTransform.getAwbBundle().bundleInfo, awbTransform);
}
Profiler.release();
BundleGraphExecutor.execute(new ArrayList<>(bundleInfoAwbTransformMap.keySet()), parallelCount, new BundleItemRunner() {
@Override
public void execute(BundleItem bundleItem) {
try {
Input input = new Input();
AwbTransform awbTransform = bundleInfoAwbTransformMap.get(bundleItem.bundleInfo);
input.getAwbBundles().add(awbTransform);
for (BundleInfo sub : bundleItem.circles) {
input.getAwbBundles().add(bundleInfoAwbTransformMap.get(sub));
}
input.getDefaultProguardFiles().addAll(defaultProguardFiles);
input.getLibraries().addAll(libs);
input.getDefaultLibraryClasses().addAll(defaultLibClasses);
input.printConfiguration = new File(appVariantContext.getAwbProguardDir(input.getAwbBundles().get(0).getAwbBundle()), "proguard.cfg");
input.printUsage = new File(appVariantContext.getAwbProguardDir(input.getAwbBundles().get(0).getAwbBundle()), "usage.cfg");
addLibraryProguardFiles(appVariantContext, input);
addChildDependency(bundleItem, input, bundleInfoAwbTransformMap);
addParentKeeps(bundleItem, input, awbTransform, bundleInfoAwbTransformMap, appVariantContext);
BundleProguarder.execute(appVariantContext, input);
} catch (Exception e) {
e.printStackTrace();
throw new GradleException("proguard " + bundleItem.bundleInfo.getPkgName(), e);
}
}
});
}
Aggregations