diff --git a/app.plugin.js b/app.plugin.js new file mode 100644 index 0000000..26c3f33 --- /dev/null +++ b/app.plugin.js @@ -0,0 +1,61 @@ +const { withAndroidManifest, AndroidConfig, withDangerousMod } = require('@expo/config-plugins'); +const { writeFileSync, mkdirSync } = require('fs'); +const { join } = require('path'); + +const withCarService = (config, { service = '.CarService' } = {}) => { + return withAndroidManifest(config, async (config) => { + let mainApplication = AndroidConfig.Manifest.getMainApplicationOrThrow(config.modResults); + + mainApplication['meta-data'] = [ + { + $: { + 'android:name': 'androidx.car.app.minCarApiLevel', + 'android:value': '1', + }, + }, + { + $: { + 'android:name': 'com.google.android.gms.car.application', + 'android:resource': '@xml/automotive_app_desc', + }, + }, + ]; + + return config; + }); +}; + +const withAutomotiveAppDesc = (config) => { + return withDangerousMod(config, [ + 'android', + async (config) => { + const automotiveAppDescXml = ` + + +`; + + const dirPath = join( + config.modRequest.projectRoot, + 'android', + 'app', + 'src', + 'main', + 'res', + 'xml' + ); + mkdirSync(dirPath, { recursive: true }); // This will create the directories if they don't exist + + const filePath = join(dirPath, 'automotive_app_desc.xml'); + + writeFileSync(filePath, automotiveAppDescXml); + + return config; + }, + ]); +}; + +module.exports = (config) => { + config = withCarService(config); + config = withAutomotiveAppDesc(config); + return config; +}; diff --git a/package.json b/package.json index 999d774..eaaea3d 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "!ios/build", "!**/__tests__", "!**/__fixtures__", - "!**/__mocks__" + "!**/__mocks__", + "app.plugin.js" ], "scripts": { "test": "jest", @@ -46,6 +47,7 @@ "registry": "https://registry.npmjs.org/" }, "dependencies": { + "@expo/config-plugins": "^6.0.1", "lodash": "^4.17.20", "react-reconciler": "^0.26.1" }, @@ -56,10 +58,10 @@ "@react-native-community/eslint-config": "^3.0.2", "@release-it/conventional-changelog": "^5.0.0", "@types/jest": "^28.1.2", + "@types/lodash": "^4.14.186", "@types/react": "~17.0.21", "@types/react-native": "0.68.0", "@types/react-reconciler": "^0.18.0", - "@types/lodash": "^4.14.186", "commitlint": "^17.0.2", "eslint": "^8.4.1", "eslint-config-prettier": "^8.5.0",