Search in sources :

Example 1 with GradleVariantConfiguration

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()));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) GradleVariantConfiguration(com.android.build.gradle.internal.core.GradleVariantConfiguration) InstantRunBuildContext(com.android.build.gradle.internal.incremental.InstantRunBuildContext) StopExecutionException(org.gradle.api.tasks.StopExecutionException) PackagingOptions(com.android.build.gradle.internal.dsl.PackagingOptions) File(java.io.File)

Example 2 with GradleVariantConfiguration

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;
}
Also used : ClassPool(javassist.ClassPool) GradleVariantConfiguration(com.android.build.gradle.internal.core.GradleVariantConfiguration) NotFoundException(javassist.NotFoundException) TBuildConfig(com.taobao.android.builder.extension.TBuildConfig) IOException(java.io.IOException) BaseVariantOutput(com.android.build.gradle.api.BaseVariantOutput) GradleException(org.gradle.api.GradleException) File(java.io.File)

Example 3 with GradleVariantConfiguration

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);
        }
    }
}
Also used : AtlasExtension(com.taobao.android.builder.extension.AtlasExtension) VariantScope(com.android.build.gradle.internal.scope.VariantScope) MergeManifests(com.android.build.gradle.tasks.MergeManifests) StopExecutionException(org.gradle.api.tasks.StopExecutionException) AndroidLibrary(com.android.builder.model.AndroidLibrary) GradleVariantConfiguration(com.android.build.gradle.internal.core.GradleVariantConfiguration) BaseVariantOutputData(com.android.build.gradle.internal.variant.BaseVariantOutputData) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) ManifestProcessorTask(com.android.build.gradle.tasks.ManifestProcessorTask)

Example 4 with GradleVariantConfiguration

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());
}
Also used : AtlasExtension(com.taobao.android.builder.extension.AtlasExtension) VariantScope(com.android.build.gradle.internal.scope.VariantScope) DocumentException(org.dom4j.DocumentException) GradleVariantConfiguration(com.android.build.gradle.internal.core.GradleVariantConfiguration) IOException(java.io.IOException) File(java.io.File) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) Result(com.taobao.android.builder.tools.manifest.Result)

Example 5 with GradleVariantConfiguration

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());
            }
        }
    }
}
Also used : ApkVariantOutput(com.android.build.gradle.api.ApkVariantOutput) ProductFlavor(com.android.builder.model.ProductFlavor) DefaultProductFlavor(com.android.builder.core.DefaultProductFlavor) DefaultManifestParser(com.android.builder.core.DefaultManifestParser) GradleVariantConfiguration(com.android.build.gradle.internal.core.GradleVariantConfiguration) DefaultProductFlavor(com.android.builder.core.DefaultProductFlavor) File(java.io.File)

Aggregations

GradleVariantConfiguration (com.android.build.gradle.internal.core.GradleVariantConfiguration)6 File (java.io.File)4 VariantScope (com.android.build.gradle.internal.scope.VariantScope)3 AtlasExtension (com.taobao.android.builder.extension.AtlasExtension)3 ManifestProcessorTask (com.android.build.gradle.tasks.ManifestProcessorTask)2 MergeManifests (com.android.build.gradle.tasks.MergeManifests)2 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)2 IOException (java.io.IOException)2 StopExecutionException (org.gradle.api.tasks.StopExecutionException)2 ApkVariantOutput (com.android.build.gradle.api.ApkVariantOutput)1 BaseVariantOutput (com.android.build.gradle.api.BaseVariantOutput)1 PackagingOptions (com.android.build.gradle.internal.dsl.PackagingOptions)1 InstantRunBuildContext (com.android.build.gradle.internal.incremental.InstantRunBuildContext)1 BaseVariantOutputData (com.android.build.gradle.internal.variant.BaseVariantOutputData)1 DefaultManifestParser (com.android.builder.core.DefaultManifestParser)1 DefaultProductFlavor (com.android.builder.core.DefaultProductFlavor)1 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 ProductFlavor (com.android.builder.model.ProductFlavor)1 ManifestProvider (com.android.manifmerger.ManifestProvider)1 ImmutableSet (com.google.common.collect.ImmutableSet)1