Search in sources :

Example 1 with LoggedErrorException

use of com.android.ide.common.internal.LoggedErrorException in project bazel by bazelbuild.

the class AndroidResourceProcessingAction method main.

public static void main(String[] args) throws Exception {
    final Stopwatch timer = Stopwatch.createStarted();
    OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class, AaptConfigOptions.class);
    optionsParser.enableParamsFileSupport(FileSystems.getDefault());
    optionsParser.parseAndExitUponError(args);
    aaptConfigOptions = optionsParser.getOptions(AaptConfigOptions.class);
    options = optionsParser.getOptions(Options.class);
    final AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(STD_LOGGER);
    try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("android_resources_tmp")) {
        final Path tmp = scopedTmp.getPath();
        final Path mergedAssets = tmp.resolve("merged_assets");
        final Path mergedResources = tmp.resolve("merged_resources");
        final Path filteredResources = tmp.resolve("resources-filtered");
        final Path densityManifest = tmp.resolve("manifest-filtered/AndroidManifest.xml");
        final Path processedManifest = tmp.resolve("manifest-processed/AndroidManifest.xml");
        final Path dummyManifest = tmp.resolve("manifest-aapt-dummy/AndroidManifest.xml");
        Path generatedSources = null;
        if (options.srcJarOutput != null || options.rOutput != null || options.symbolsOut != null) {
            generatedSources = tmp.resolve("generated_resources");
        }
        logger.fine(String.format("Setup finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
        List<DependencyAndroidData> data = ImmutableSet.<DependencyAndroidData>builder().addAll(options.directData).addAll(options.transitiveData).build().asList();
        final MergedAndroidData mergedData = AndroidResourceMerger.mergeData(options.primaryData, options.directData, options.transitiveData, mergedResources, mergedAssets, selectPngCruncher(), options.packageType, options.symbolsOut);
        logger.fine(String.format("Merging finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
        final DensityFilteredAndroidData filteredData = mergedData.filter(new DensitySpecificResourceFilter(options.densities, filteredResources, mergedResources), new DensitySpecificManifestProcessor(options.densities, densityManifest));
        logger.fine(String.format("Density filtering finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
        MergedAndroidData processedData = AndroidManifestProcessor.with(STD_LOGGER).processManifest(options.packageType, options.packageForR, options.applicationId, options.versionCode, options.versionName, filteredData, processedManifest);
        // Write manifestOutput now before the dummy manifest is created.
        if (options.manifestOutput != null) {
            AndroidResourceOutputs.copyManifestToOutput(processedData, options.manifestOutput);
        }
        if (options.packageType == VariantType.LIBRARY) {
            resourceProcessor.writeDummyManifestForAapt(dummyManifest, options.packageForR);
            processedData = new MergedAndroidData(processedData.getResourceDir(), processedData.getAssetDir(), dummyManifest);
        }
        resourceProcessor.processResources(aaptConfigOptions.aapt, aaptConfigOptions.androidJar, aaptConfigOptions.buildToolsVersion, options.packageType, aaptConfigOptions.debug, options.packageForR, new FlagAaptOptions(aaptConfigOptions), aaptConfigOptions.resourceConfigs, aaptConfigOptions.splits, processedData, data, generatedSources, options.packagePath, options.proguardOutput, options.mainDexProguardOutput, options.resourcesOutput != null ? processedData.getResourceDir().resolve("values").resolve("public.xml") : null, options.dataBindingInfoOut);
        logger.fine(String.format("aapt finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
        if (options.srcJarOutput != null) {
            AndroidResourceOutputs.createSrcJar(generatedSources, options.srcJarOutput, VariantType.LIBRARY == options.packageType);
        }
        if (options.rOutput != null) {
            AndroidResourceOutputs.copyRToOutput(generatedSources, options.rOutput, VariantType.LIBRARY == options.packageType);
        }
        if (options.resourcesOutput != null) {
            AndroidResourceOutputs.createResourcesZip(processedData.getResourceDir(), processedData.getAssetDir(), options.resourcesOutput, false);
        }
        logger.fine(String.format("Packaging finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
    } catch (MergingException e) {
        logger.log(java.util.logging.Level.SEVERE, "Error during merging resources", e);
        throw e;
    } catch (IOException | InterruptedException | LoggedErrorException | UnrecognizedSplitsException e) {
        logger.log(java.util.logging.Level.SEVERE, "Error during processing resources", e);
        throw e;
    } catch (Exception e) {
        logger.log(java.util.logging.Level.SEVERE, "Unexpected", e);
        throw e;
    } finally {
        resourceProcessor.shutdown();
    }
    logger.fine(String.format("Resources processed in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
Also used : Path(java.nio.file.Path) AaptConfigOptions(com.google.devtools.build.android.AndroidResourceProcessor.AaptConfigOptions) FlagAaptOptions(com.google.devtools.build.android.AndroidResourceProcessor.FlagAaptOptions) FlagAaptOptions(com.google.devtools.build.android.AndroidResourceProcessor.FlagAaptOptions) UnrecognizedSplitsException(com.google.devtools.build.android.SplitConfigurationFilter.UnrecognizedSplitsException) MergingException(com.android.ide.common.res2.MergingException) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) OptionsParser(com.google.devtools.common.options.OptionsParser) UnrecognizedSplitsException(com.google.devtools.build.android.SplitConfigurationFilter.UnrecognizedSplitsException) LoggedErrorException(com.android.ide.common.internal.LoggedErrorException) MergingException(com.android.ide.common.res2.MergingException) IOException(java.io.IOException) LoggedErrorException(com.android.ide.common.internal.LoggedErrorException) AaptConfigOptions(com.google.devtools.build.android.AndroidResourceProcessor.AaptConfigOptions)

Aggregations

LoggedErrorException (com.android.ide.common.internal.LoggedErrorException)1 MergingException (com.android.ide.common.res2.MergingException)1 Stopwatch (com.google.common.base.Stopwatch)1 AaptConfigOptions (com.google.devtools.build.android.AndroidResourceProcessor.AaptConfigOptions)1 FlagAaptOptions (com.google.devtools.build.android.AndroidResourceProcessor.FlagAaptOptions)1 UnrecognizedSplitsException (com.google.devtools.build.android.SplitConfigurationFilter.UnrecognizedSplitsException)1 OptionsParser (com.google.devtools.common.options.OptionsParser)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1