com.android.manifmerger.ManifestMerger2 Java Examples

The following examples show how to use com.android.manifmerger.ManifestMerger2. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProcessManifest.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void doFullTaskAction() {

    final File file = getAaptFriendlyManifestOutputFile();
    getBuilder().mergeManifests(
            getMainManifest(),
            getManifestOverlays(),
            Collections.<ManifestDependency>emptyList(),
            getPackageOverride(),
            getVersionCode(),
            getVersionName(),
            getMinSdkVersion(),
            getTargetSdkVersion(),
            getMaxSdkVersion(),
            getManifestOutputFile().getAbsolutePath(),
            (file == null ? null : file.getAbsolutePath()),
            ManifestMerger2.MergeType.LIBRARY,
            (Map<String, String>) variantConfiguration.getManifestPlaceholders(),
            getReportFile());
}
 
Example #2
Source File: AndroidBuilder.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the {@link com.android.manifmerger.ManifestMerger2.SystemProperty} that can be injected
 * in the manifest file.
 */
private static void setInjectableValues(
        ManifestMerger2.Invoker<?> invoker,
        String packageOverride,
        int versionCode,
        String versionName,
        @Nullable String minSdkVersion,
        @Nullable String targetSdkVersion,
        @Nullable Integer maxSdkVersion) {

    if (!Strings.isNullOrEmpty(packageOverride)) {
        invoker.setOverride(SystemProperty.PACKAGE, packageOverride);
    }
    if (versionCode > 0) {
        invoker.setOverride(SystemProperty.VERSION_CODE,
                String.valueOf(versionCode));
    }
    if (!Strings.isNullOrEmpty(versionName)) {
        invoker.setOverride(SystemProperty.VERSION_NAME, versionName);
    }
    if (!Strings.isNullOrEmpty(minSdkVersion)) {
        invoker.setOverride(SystemProperty.MIN_SDK_VERSION, minSdkVersion);
    }
    if (!Strings.isNullOrEmpty(targetSdkVersion)) {
        invoker.setOverride(SystemProperty.TARGET_SDK_VERSION, targetSdkVersion);
    }
    if (maxSdkVersion != null) {
        invoker.setOverride(SystemProperty.MAX_SDK_VERSION, maxSdkVersion.toString());
    }
}
 
Example #3
Source File: AndroidManifestProcessor.java    From bazel with Apache License 2.0 5 votes vote down vote up
/** Process a manifest for a library or a binary and return the merged android data. */
public MergedAndroidData processManifest(
    VariantType variantType,
    String customPackageForR,
    String applicationId,
    int versionCode,
    String versionName,
    MergedAndroidData primaryData,
    Path processedManifest,
    boolean logWarnings) {

  ManifestMerger2.MergeType mergeType =
      variantType == VariantType.DEFAULT
          ? ManifestMerger2.MergeType.APPLICATION
          : ManifestMerger2.MergeType.LIBRARY;

  String newManifestPackage =
      variantType == VariantType.DEFAULT ? applicationId : customPackageForR;

  if (versionCode != -1 || versionName != null || newManifestPackage != null) {
    processManifest(
        versionCode,
        versionName,
        primaryData.getManifest(),
        processedManifest,
        mergeType,
        newManifestPackage,
        logWarnings);
    return new MergedAndroidData(
        primaryData.getResourceDir(), primaryData.getAssetDir(), processedManifest);
  }
  return primaryData;
}
 
Example #4
Source File: GenerateManifestStep.java    From buck with Apache License 2.0 5 votes vote down vote up
private MergingReport mergeManifests(
    File mainManifestFile, List<File> libraryManifestFiles, BuckEventAndroidLogger logger) {
  try {
    ManifestMerger2.Invoker<?> manifestInvoker =
        ManifestMerger2.newMerger(
            mainManifestFile, logger, ManifestMerger2.MergeType.APPLICATION);
    if (!module.isRootModule()) {
      manifestInvoker.setPlaceHolderValue("split", module.getName());
    } else {
      manifestInvoker.withFeatures(ManifestMerger2.Invoker.Feature.NO_PLACEHOLDER_REPLACEMENT);
    }

    MergingReport mergingReport =
        manifestInvoker
            .withFeatures(
                ManifestMerger2.Invoker.Feature.REMOVE_TOOLS_DECLARATIONS,
                ManifestMerger2.Invoker.Feature.SKIP_BLAME)
            .addLibraryManifests(Iterables.toArray(libraryManifestFiles, File.class))
            .setMergeReportFile(mergeReportPath.toFile())
            .merge();
    if (mergingReport.getResult().isError()) {
      for (MergingReport.Record record : mergingReport.getLoggingRecords()) {
        logger.error(null, record.toString());
      }
      throw new HumanReadableException("Error generating manifest file");
    }

    return mergingReport;
  } catch (ManifestMerger2.MergeFailureException e) {
    throw new HumanReadableException(
        e.getCause(), "Error generating manifest file: %s", e.getMessage());
  }
}
 
Example #5
Source File: AtlasBuilder.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
public MergingReport mergeManifestsForApplication(
        @NonNull File mainManifest,
        @NonNull List<File> manifestOverlays,
        @NonNull List<? extends ManifestProvider> dependencies,
        @Nullable String featureName,
        String packageOverride,
        int versionCode,
        String versionName,
        @Nullable String minSdkVersion,
        @Nullable String targetSdkVersion,
        @Nullable Integer maxSdkVersion,
        @NonNull String outManifestLocation,
        @Nullable String outAaptSafeManifestLocation,
        @Nullable String outInstantRunManifestLocation,
        ManifestMerger2.MergeType mergeType,
        Map<String, Object> placeHolders,
        @NonNull List<ManifestMerger2.Invoker.Feature> optionalFeatures,
        @Nullable File reportFile) {


    return super.mergeManifestsForApplication(
            mainManifest,
            manifestOverlays,
            manifestProviders,
            featureName,
            packageOverride,
            versionCode,
            versionName,
            minSdkVersion,
            targetSdkVersion,
            maxSdkVersion,
            outManifestLocation,
            outAaptSafeManifestLocation,
            outInstantRunManifestLocation,
            mergeType,
            placeHolders,
            optionalFeatures,
            reportFile);

}
 
Example #6
Source File: AndroidManifestProcessor.java    From bazel with Apache License 2.0 4 votes vote down vote up
private void processManifest(
    int versionCode,
    String versionName,
    Path primaryManifest,
    Path processedManifest,
    MergeType mergeType,
    String newManifestPackage,
    boolean logWarnings) {
  try {
    Files.createDirectories(processedManifest.getParent());

    // The generics on Invoker don't make sense, so ignore them.
    @SuppressWarnings("unchecked")
    Invoker<?> manifestMergerInvoker =
        ManifestMerger2.newMerger(primaryManifest.toFile(), stdLogger, mergeType);
    // Stamp new package
    if (newManifestPackage != null) {
      manifestMergerInvoker.setOverride(SystemProperty.PACKAGE, newManifestPackage);
    }
    // Stamp version and applicationId (if provided) into the manifest
    if (versionCode > 0) {
      manifestMergerInvoker.setOverride(SystemProperty.VERSION_CODE, String.valueOf(versionCode));
    }
    if (versionName != null) {
      manifestMergerInvoker.setOverride(SystemProperty.VERSION_NAME, versionName);
    }

    MergedManifestKind mergedManifestKind = MergedManifestKind.MERGED;
    if (mergeType == MergeType.APPLICATION) {
      manifestMergerInvoker.withFeatures(Feature.REMOVE_TOOLS_DECLARATIONS);
    }

    MergingReport mergingReport = manifestMergerInvoker.merge();
    switch (mergingReport.getResult()) {
      case WARNING:
        if (logWarnings) {
          mergingReport.log(stdLogger);
        }
        writeMergedManifest(mergedManifestKind, mergingReport, processedManifest);
        break;
      case SUCCESS:
        writeMergedManifest(mergedManifestKind, mergingReport, processedManifest);
        break;
      case ERROR:
        mergingReport.log(stdLogger);
        throw new ManifestProcessingException(mergingReport.getReportString());
      default:
        throw new ManifestProcessingException(
            "Unhandled result type : " + mergingReport.getResult());
    }
  } catch (IOException | MergeFailureException e) {
    throw new ManifestProcessingException(e);
  }
}