How to write plugin to handle Android ManifestMerger issue?

I am trying to run both Adapty and AppsFlyer SDKs in my Managed Workflow, which should theoretically be possible, but I have one issue where both SDKs are trying to write backup rules and this causes builds to fail when merging them.

To resolve it, the solutions involved modifying the Manifest:

I have tried every variation of a plugin to handle this but they have all failed. Right now, I have been trying to set the allowBackup to false, but whenever I run the prebuild command to check if it is being applied, it doesn’t update.

Current plugin:

const { withAndroidManifest } = require('@expo/config-plugins');

const withAllowBackupFalse = (config) => {
  return withAndroidManifest(config, (config) => {
    console.log('Applying withAllowBackupFalse...');

    if (!config.modResults.application || !Array.isArray(config.modResults.application)) {
      console.log('Unexpected format in AndroidManifest.xml. Make sure you have an <application> tag.');
      return config;
    }

    for (const application of config.modResults.application) {
      if (application && application['$']) {
        application['$']['android:allowBackup'] = 'false';
        console.log('Set android:allowBackup to false.');
      } else {
        console.log('Skipped an application element.');
      }
    }

    return config;
  });
};

module.exports = withAllowBackupFalse;

It prints the console.log(‘Unexpected format in AndroidManifest.xml. Make sure you have an tag.’);

So it’s like the manifest is not able to be edited when the plugin runs. Any ideas how I can do this?

Nevermind, I resolved it with:

const { withAndroidManifest } = require('@expo/config-plugins');

const withAllowBackupFalseAndAppsflyerBackupRules = (config) => {
  return withAndroidManifest(config, (config) => {
    console.log('Applying withAllowBackupFalseAndAppsflyerBackupRules...');

    const manifest = config.modResults.manifest;

    if (!manifest.application || !Array.isArray(manifest.application)) {
      console.error('Unexpected format in AndroidManifest.xml. No <application> tag found.');
      return config;
    }

    for (const app of manifest.application) {
      if (app && app['$']) {
        app['$']['android:allowBackup'] = 'false';
        app['$']['android:fullBackupContent'] = '@xml/appsflyer_backup_rules';
        console.log('Set android:allowBackup to false and using Appsflyer backup rules.');
      } else {
        console.log('Skipped an application element.');
      }
    }

    return config;
  });
};

module.exports = withAllowBackupFalseAndAppsflyerBackupRules;

Hi @zodiworld

I believe, from Expo SDK 47 onwards, you should import/require expo/config-plugins instead of @expo/config-plugins. e.g see the example here:

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.