use of com.android.build.gradle.internal.core.GradleVariantConfiguration in project atlas by alibaba.
the class AwoPackageConfigAction method execute.
@Override
public void execute(PackageApplication packageApp) {
final GradleVariantConfiguration config = scope.getVariantConfiguration();
packageApp.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
packageApp.setVariantName(scope.getVariantConfiguration().getFullName());
packageApp.setMinSdkVersion(config.getMinSdkVersion());
setFieldValueByReflection(packageApp, "dexPackagingPolicy", DexPackagingPolicy.STANDARD);
setFieldValueByReflection(packageApp, "instantRunContext", new InstantRunBuildContext());
ConventionMappingHelper.map(packageApp, "resourceFile", new Callable<File>() {
@Override
public File call() {
return libVariantContext.getOutputResouceAP();
}
});
ConventionMappingHelper.map(packageApp, "dexFolders", new Callable<Set<File>>() {
@Override
public Set<File> call() {
File outFolder = libVariantContext.getDexFolder();
Set<File> folders = Sets.newHashSet();
folders.add(outFolder);
return folders;
}
});
ConventionMappingHelper.map(packageApp, "javaResourceFiles", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return Collections.<File>emptySet();
}
});
// TODO: 增加abiFilter的支持
ConventionMappingHelper.map(packageApp, "jniFolders", new Callable<Set<File>>() {
@Override
public Set<File> call() {
File jniFolder = awbBundle.getJniFolder();
Set<File> folders = Sets.newHashSet();
folders.add(jniFolder);
return folders;
}
});
ConventionMappingHelper.map(packageApp, "abiFilters", new Callable<Set<String>>() {
@Override
public Set<String> call() throws Exception {
Set<String> supportedAbis = config.getSupportedAbis();
if (supportedAbis != null) {
return supportedAbis;
}
return ImmutableSet.of("armeabi", "x86");
}
});
ConventionMappingHelper.map(packageApp, "jniDebugBuild", new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return config.getBuildType().isJniDebuggable();
}
});
ConventionMappingHelper.map(packageApp, "packagingOptions", new Callable<PackagingOptions>() {
@Override
public PackagingOptions call() throws Exception {
return scope.getGlobalScope().getExtension().getPackagingOptions();
}
});
ConventionMappingHelper.map(packageApp, "outputFile", new Callable<File>() {
@Override
public File call() throws Exception {
return libVariantContext.getPackageFile();
}
});
//setFieldValueByReflection(packageApp, "markerFile",
// PrePackageApplication.ConfigAction.getMarkerFile(scope));
setFieldValueByReflection(packageApp, "inOldMode", AndroidGradleOptions.useOldPackaging(scope.getGlobalScope().getProject()));
}
use of com.android.build.gradle.internal.core.GradleVariantConfiguration 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.internal.core.GradleVariantConfiguration 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);
}
}
}
use of com.android.build.gradle.internal.core.GradleVariantConfiguration in project atlas by alibaba.
the class PostProcessManifestAction method execute.
@Override
public void execute(Task task) {
AtlasExtension atlasExtension = appVariantContext.getAtlasExtension();
File bundleBaseLineInfo = appVariantContext.getBundleBaseInfoFile();
VariantScope variantScope = appVariantContext.getScope();
GradleVariantConfiguration config = variantScope.getVariantConfiguration();
AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(config.getFullName());
File androidManifest = null;
File file = variantScope.getInstantRunManifestOutputDirectory();
if (null != file && file.exists() && variantScope.getInstantRunBuildContext().isInInstantRunMode()) {
androidManifest = FileUtils.join(baseVariantOutputData.getProcessManifest().getInstantRunManifestOutputDirectory(), baseVariantOutputData.getDirName(), SdkConstants.ANDROID_MANIFEST_XML);
} else {
androidManifest = FileUtils.join(baseVariantOutputData.getProcessManifest().getManifestOutputDirectory(), baseVariantOutputData.getDirName(), SdkConstants.ANDROID_MANIFEST_XML);
}
try {
Result result = ManifestFileUtils.postProcessManifests(androidManifest, getLibManifestMap(), getLibManifestDepenendyMap(), bundleBaseLineInfo, atlasExtension.manifestOptions, isMultiDexEnabled(), variantScope.getInstantRunBuildContext().isInInstantRunMode(), appVariantContext.getBuildType().isDebuggable(), atlasExtension.getTBuildConfig().getOutOfApkBundles(), atlasExtension.getTBuildConfig().getInsideOfApkBundles(), atlasExtension.getTBuildConfig().isPushInstall());
File proxySrcDir = appVariantContext.getAtlasProxySourceDir();
if (AtlasProxy.genProxyJavaSource(proxySrcDir, result)) {
// appVariantContext.getVariantData().javacTask.source(proxySrcDir);
}
ManifestHelper.checkManifest(appVariantContext, androidManifest, dependencyTree, atlasExtension);
} catch (DocumentException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
// ManifestFileUtils.postProcessManifests(
// instantRunAndroidManifest,
// getLibManifestMap(),
// getLibManifestDepenendyMap(),
// bundleBaseLineInfo,
// atlasExtension.manifestOptions,
// isMultiDexEnabled(),
// true,
// appVariantContext.getBuildType().isDebuggable(),
// atlasExtension.getTBuildConfig()
// .getOutOfApkBundles(),atlasExtension.getTBuildConfig().getInsideOfApkBundles(),atlasExtension.getTBuildConfig().isPushInstall());
// }
// manifest list check
// TODO??
// AtlasBuildContext.androidBuilderMap.get(appVariantContext.getProject()).generateKeepList(
// baseVariantOutputData.manifestProcessorTask.getManifestOutputFile(),
// appVariantContext.getScope()
// .getManifestKeepListProguardFile());
}
use of com.android.build.gradle.internal.core.GradleVariantConfiguration in project atlas by alibaba.
the class PreProcessManifestAction method modifyForIncremental.
private void modifyForIncremental(MergeManifests mergeManifests, List<ManifestProvider> allManifest) {
if (appVariantContext.getAtlasExtension().getTBuildConfig().isIncremental()) {
File mainManifest = mergeManifests.getMainManifest();
File baseManifest = appVariantContext.apContext.getBaseModifyManifest();
// allManifest.add(new ManifestHelper.MainManifestProvider(mainManifest, "main-manifest"));
ConventionMappingHelper.map(mergeManifests, "mainManifest", new Callable<File>() {
@Override
public File call() throws Exception {
return baseManifest;
}
});
if (baseVariantOutput instanceof ApkVariantOutput) {
// TODO Improve performance
ApkVariantOutput variantOutputData = (ApkVariantOutput) baseVariantOutput;
DefaultManifestParser manifestParser = new DefaultManifestParser(baseManifest);
String versionNameOverride = variantOutputData.getVersionNameOverride();
if (Strings.isNullOrEmpty(versionNameOverride)) {
variantOutputData.setVersionNameOverride(manifestParser.getVersionName());
GradleVariantConfiguration variantConfiguration = appVariantContext.getScope().getVariantConfiguration();
ProductFlavor mergedFlavor = variantConfiguration.getMergedFlavor();
String versionName = mergedFlavor.getVersionName();
if (versionName == null) {
((DefaultProductFlavor) mergedFlavor).setVersionName(manifestParser.getVersionName());
}
}
int versionCodeOverride = variantOutputData.getVersionCodeOverride();
if (versionCodeOverride == -1) {
variantOutputData.setVersionCodeOverride(manifestParser.getVersionCode());
}
}
}
}
Aggregations