Search in sources :

Example 1 with SplitList

use of com.android.build.gradle.internal.scope.SplitList in project atlas by alibaba.

the class TPatchDiffResAPBuildTask method doAction.

@TaskAction
protected void doAction() throws IOException {
    manifestFile = getManifestFile();
    aaptOptions = getAaptOptions();
    diffResDir = getDiffResDir();
    resourceConfigs = getResourceConfigs();
    preferredDensity = getPreferredDensity();
    SplitList splitList = SplitList.load(splitListInput);
    // TODO  minifyManifest
    File miniManifest = new File(packageOutputFile.getParentFile(), "AndroidManifest.xml");
    try {
        ManifestFileUtils.createPatchManifest(manifestFile, getBaseManifestFile(), miniManifest);
    } catch (DocumentException e) {
        throw new GradleException(e.getMessage());
    }
    String splitFilter = apkData.getFilter(com.android.build.OutputFile.FilterType.DENSITY);
    String preferredDensity = splitFilter != null ? splitFilter : // if resConfigs is set, we should not use our preferredDensity.
    splitList.getFilters(SplitList.RESOURCE_CONFIGS).isEmpty() ? buildTargetDensity : null;
    File assetsFolder = new File(diffResDir, "assets");
    File resFolder = new File(diffResDir, "res");
    if (!assetsFolder.exists()) {
        assetsFolder.mkdirs();
    }
    if (!resFolder.exists()) {
        resFolder.mkdirs();
    }
    aaptOptions.getAdditionalParameters().add("-A");
    aaptOptions.getAdditionalParameters().add(assetsFolder.getAbsolutePath());
    AaptGeneration aaptGeneration = AaptGeneration.fromProjectOptions(appVariantContext.getScope().getGlobalScope().getProjectOptions());
    Aapt aapt = makeAapt(aaptGeneration);
    AaptPackageConfig.Builder config = new AaptPackageConfig.Builder().setManifestFile(miniManifest).setOptions(DslAdaptersKt.convert(aaptOptions)).setResourceDir(resFolder).setLibrarySymbolTableFiles(ImmutableSet.of()).setCustomPackageForR(packageForR).setResourceOutputApk(packageOutputFile).setVariantType(type).setDebuggable(debuggable).setResourceConfigs(splitList.getFilters(SplitList.RESOURCE_CONFIGS)).setSplits(getSplits(splitList)).setPreferredDensity(preferredDensity).setListResourceFiles(aaptGeneration == AaptGeneration.AAPT_V2);
    try {
        getBuilder().processResources(aapt, config);
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ProcessException e) {
        e.printStackTrace();
    }
}
Also used : SplitList(com.android.build.gradle.internal.scope.SplitList) ProcessException(com.android.ide.common.process.ProcessException) AaptGeneration(com.android.build.gradle.internal.aapt.AaptGeneration) DocumentException(org.dom4j.DocumentException) GradleException(org.gradle.api.GradleException) AndroidBuilder(com.android.builder.core.AndroidBuilder) AtlasBuilder(com.android.builder.core.AtlasBuilder) Aapt(com.android.builder.internal.aapt.Aapt) File(java.io.File) AaptPackageConfig(com.android.builder.internal.aapt.AaptPackageConfig) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)

Aggregations

AaptGeneration (com.android.build.gradle.internal.aapt.AaptGeneration)1 SplitList (com.android.build.gradle.internal.scope.SplitList)1 AndroidBuilder (com.android.builder.core.AndroidBuilder)1 AtlasBuilder (com.android.builder.core.AtlasBuilder)1 Aapt (com.android.builder.internal.aapt.Aapt)1 AaptPackageConfig (com.android.builder.internal.aapt.AaptPackageConfig)1 ProcessException (com.android.ide.common.process.ProcessException)1 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)1 File (java.io.File)1 DocumentException (org.dom4j.DocumentException)1 GradleException (org.gradle.api.GradleException)1