Skip to content

Instantly share code, notes, and snippets.

@wodin
Last active August 12, 2023 03:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wodin/1f39ff118d18a37ff2df29b2ab049ad2 to your computer and use it in GitHub Desktop.
Save wodin/1f39ff118d18a37ff2df29b2ab049ad2 to your computer and use it in GitHub Desktop.
Add `usesCleartextTraffic` to AndroidManifest.xml in Expo managed workflow
/*
* Convert `app.json` to `app.config.js`
* Install `@expo/config-plugins` as a devDependency
* Copy the `withAndroidApplicationAttributes` config plugin and related `addAttributesToApplication` function to `app.config.js`
* Add a `plugins` section to reference the config plugin and specify the attribute to add
* Build with `eas build -p android ...`
*/
import { AndroidConfig, withAndroidManifest } from "@expo/config-plugins";
function addAttributesToApplication(androidManifest, attributes) {
const app = AndroidConfig.Manifest.getMainApplicationOrThrow(androidManifest);
app.$ = { ...app.$, ...attributes };
return androidManifest;
}
function withAndroidApplicationAttributes(config, attributes) {
return withAndroidManifest(config, (config) => {
config.modResults = addAttributesToApplication(
config.modResults,
attributes
);
return config;
});
}
export default {
name: "androidManifestAttributeTest",
slug: "androidManifestAttributeTest",
version: "1.0.0",
plugins: [
[
withAndroidApplicationAttributes,
{
"android:usesCleartextTraffic": false,
},
],
],
orientation: "portrait",
icon: "./assets/icon.png",
splash: {
image: "./assets/splash.png",
resizeMode: "contain",
backgroundColor: "#ffffff",
},
updates: {
fallbackToCacheTimeout: 0,
},
assetBundlePatterns: ["**/*"],
ios: {
supportsTablet: true
},
android: {
adaptiveIcon: {
foregroundImage: "./assets/adaptive-icon.png",
backgroundColor: "#FFFFFF",
},
package: "com.example.androidManifestAttributeTest",
},
web: {
favicon: "./assets/favicon.png",
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment