Ask
42
@rawfileruth ·

do i really need a config plugin to add one line to AndroidManifest, first expo app config-plugin

I need one attribute in the manifest for an SDK I am integrating. Their docs say "add this line to AndroidManifest.xml".

Everything I read says do not edit the file directly in a managed project, write a config plugin instead. Writing a whole plugin to add one line feels like enormous ceremony for a one-line change and I want to check I am not overcomplicating my first app.

9 answers Share
Report

Answering anonymously — a moderator will review it first.

  • @rest_day_rita · 8mo ago · 3 replies

    Probably not, for one line. Work down this list:

    1. Is it already an app.json field? Permissions, intent filters, a lot of common manifest keys are exposed directly and people write plugins for things that were one config key away.
    2. Can expo-build-properties do it? It covers a surprising amount of the Gradle and manifest surface.
    3. Only then write a plugin.

    And if you do get to step 3, a plugin for one manifest attribute is about fifteen lines with withAndroidManifest. It is a function that takes config, mutates a parsed object, returns config. Not a mountain.

    The thing you must not do is edit android/AndroidManifest.xml by hand, because the next prebuild regenerates it and your line silently disappears. You will not notice at the time. You will notice on a build three weeks later when the SDK stops working and nothing in your diff explains it.

    68
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @stack_trace_sy · 8mo ago

      The silent disappearance is the entire reason plugins exist. It is not ceremony, it is the only mechanism by which your change survives a regeneration. Once you see it that way the fifteen lines stop feeling like overhead.

      24
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @bench_dogged · 8mo ago

      Run npx expo prebuild --clean and read the generated manifest afterwards. Seeing your attribute actually appear in the output is a 30 second confirmation and it is weirdly satisfying the first time.

      13
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @treadmill_tara · 8mo ago

    Yes it is normal, and yes it feels absurd the first time. It is the price of not owning the native directories - you gave up direct editing and got automatic upgrades in return.

    If you find yourself writing your fourth plugin, that is a genuine signal you might be happier in the bare workflow. Four is the number. One is not.

    41
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @deadbug_wiring · 8mo ago

    Worth saying explicitly since it is not obvious from the docs: a plugin can be a local file. plugins: ["./plugins/withThing"] in your config and a JS file in your repo. No package, no publish, no build step, no npm anything.

    26
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @p99_hana · 8mo ago · 3 replies

    Prebuild once, commit the android folder, edit it directly. That is where most projects end up anyway and it saves you the abstraction.

    16
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @rest_day_rita · 8mo ago

      Plenty of projects do end up there and it is a legitimate place to be. But it means you now hand-merge every native change at each SDK bump, forever, and that is a recurring cost rather than a saved afternoon. Recommending it to someone on their first app as the shortcut undersells what they are signing up for.

      13
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @treadmill_tara · 8mo ago

      And if you do go bare, go deliberately - remove prebuild from your scripts, commit the folders on purpose, write it down. The bad version is drifting into it because a manifest edit happened to survive once.

      10
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @late_stage_phd · 8mo ago

    Write the plugin. You will need a second one within a month - everyone does - and by then you will already know how, which turns a two hour job into a ten minute one.

    8
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report