Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict android app for tablet/handset using expo?

I have separate APKs for the same app. For tablets and for handsets. Also I'm using expo in my project. Due to android documentation I should declare <supports-screens> in <manifest> like this for tablet support only:

<manifest ... >
    <supports-screens android:smallScreens="false"
                      android:normalScreens="false"
                      android:largeScreens="true"
                      android:xlargeScreens="true"/>
</manifest>

But it's not good solution, because eject is necessary. How can solve my problem without expo eject ?

like image 525
Artem Bochkarev Avatar asked Oct 21 '25 11:10

Artem Bochkarev


1 Answers

I used this answer (among others) to help me piece together how to do this. Here is my plugin file to add <supports-screens> in <manifest>:

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

function addAttributesToManifest(androidManifest) {
  const { manifest } = androidManifest;

  const supportsScreens = {};
  supportsScreens.$ = {
    ...supportsScreens.$,
    ...{
      "android:smallScreens": false,
      "android:normalScreens": false,
      "android:largeScreens": true,
      "android:xlargeScreens": true,
    },
  };

  manifest["supports-screens"] = supportsScreens;

  return androidManifest
}

module.exports = function withSupportsScreens(config) {
  return withAndroidManifest(config, (config) => {
    config.modResults = addAttributesToManifest(config.modResults);
    return config;
  });
};

Run expo prebuild --platform android --no-install and check that android/app/src/main/AndroidManifest.xml now contains <supports-screens>. Make sure to delete the generated android folder when you're done setting up your plugin so that EAS does not assume a bare workflow.

like image 116
Libby Avatar answered Oct 24 '25 00:10

Libby