From 609ebb6612589a6de0da8e3d3a3ca4a54a74a9a8 Mon Sep 17 00:00:00 2001 From: Sven van der Zwet <48092471+JanSneeuw@users.noreply.github.com> Date: Mon, 15 May 2023 20:34:15 +0200 Subject: [PATCH 1/5] Added expo config plugin --- app.plugin.js | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 app.plugin.js diff --git a/app.plugin.js b/app.plugin.js new file mode 100644 index 0000000..1e7c332 --- /dev/null +++ b/app.plugin.js @@ -0,0 +1,80 @@ +const { withAndroidManifest, AndroidConfig, withDangerousMod } = require('@expo/config-plugins'); +const { writeFileSync } = require('fs'); +const { join } = require('path'); + +const withCarService = (config, { service = '.CarService' } = {}) => { + return withAndroidManifest(config, async (config) => { + let mainApplication = AndroidConfig.Manifest.getMainApplicationOrThrow(config.modResults); + + mainApplication['service'] = [ + { + $: { + 'android:name': service, + 'android:exported': 'true', + }, + 'intent-filter': [ + { + 'action': [ + { + $: { + 'android:name': 'androidx.car.app.CarAppService', + }, + }, + ], + 'category': [ + { + $: { + 'android:name': 'androidx.car.app.category.NAVIGATION', + }, + }, + ], + }, + ], + }, + ]; + + mainApplication['meta-data'] = [ + { + $: { + 'android:name': 'androidx.car.app.minCarApiLevel', + 'android:value': '1', + }, + }, + ]; + + return config; + }); +}; + +const withAutomotiveAppDesc = (config) => { + return withDangerousMod(config, [ + 'android', + async (config) => { + const automotiveAppDescXml = ` + + +`; + + const filePath = join( + config.modRequest.projectRoot, + 'android', + 'app', + 'src', + 'main', + 'res', + 'xml', + 'automotive_app_desc.xml' + ); + + writeFileSync(filePath, automotiveAppDescXml); + + return config; + }, + ]); +}; + +module.exports = (config) => { + config = withCarService(config); + config = withAutomotiveAppDesc(config); + return config; +}; From df2909452f90ca53ca0227ae09f10f844f13d20b Mon Sep 17 00:00:00 2001 From: Sven van der Zwet <48092471+JanSneeuw@users.noreply.github.com> Date: Mon, 15 May 2023 20:45:16 +0200 Subject: [PATCH 2/5] exported expo config plugin --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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", From a4cc6122bcdd3a9ab05912ccd32b51176beaa952 Mon Sep 17 00:00:00 2001 From: Sven van der Zwet <48092471+JanSneeuw@users.noreply.github.com> Date: Mon, 15 May 2023 20:51:54 +0200 Subject: [PATCH 3/5] creating needed directories before appending automotive_app_desc.xml --- app.plugin.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app.plugin.js b/app.plugin.js index 1e7c332..2c65d75 100644 --- a/app.plugin.js +++ b/app.plugin.js @@ -1,5 +1,5 @@ const { withAndroidManifest, AndroidConfig, withDangerousMod } = require('@expo/config-plugins'); -const { writeFileSync } = require('fs'); +const { writeFileSync, mkdirSync } = require('fs'); const { join } = require('path'); const withCarService = (config, { service = '.CarService' } = {}) => { @@ -55,16 +55,18 @@ const withAutomotiveAppDesc = (config) => { `; - const filePath = join( + const dirPath = join( config.modRequest.projectRoot, 'android', 'app', 'src', 'main', 'res', - 'xml', - 'automotive_app_desc.xml' + '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); From 796b7a17dd6d68d05e6b74721934f7e5cec7c383 Mon Sep 17 00:00:00 2001 From: Sven van der Zwet <48092471+JanSneeuw@users.noreply.github.com> Date: Mon, 15 May 2023 21:17:01 +0200 Subject: [PATCH 4/5] added com.google.android.gms.car.application metadata to the manifest --- app.plugin.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app.plugin.js b/app.plugin.js index 2c65d75..74c7605 100644 --- a/app.plugin.js +++ b/app.plugin.js @@ -40,6 +40,12 @@ const withCarService = (config, { service = '.CarService' } = {}) => { 'android:value': '1', }, }, + { + $: { + 'android:name': 'com.google.android.gms.car.application', + 'android:resource': '@xml/automotive_app_desc', + }, + }, ]; return config; From 8433e6257c353d0762c95f10753cc30a34cbb185 Mon Sep 17 00:00:00 2001 From: Sven van der Zwet <48092471+JanSneeuw@users.noreply.github.com> Date: Sat, 20 May 2023 14:30:38 +0200 Subject: [PATCH 5/5] removed CarService as this is already defined in the manifest of the library --- app.plugin.js | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/app.plugin.js b/app.plugin.js index 74c7605..26c3f33 100644 --- a/app.plugin.js +++ b/app.plugin.js @@ -6,33 +6,6 @@ const withCarService = (config, { service = '.CarService' } = {}) => { return withAndroidManifest(config, async (config) => { let mainApplication = AndroidConfig.Manifest.getMainApplicationOrThrow(config.modResults); - mainApplication['service'] = [ - { - $: { - 'android:name': service, - 'android:exported': 'true', - }, - 'intent-filter': [ - { - 'action': [ - { - $: { - 'android:name': 'androidx.car.app.CarAppService', - }, - }, - ], - 'category': [ - { - $: { - 'android:name': 'androidx.car.app.category.NAVIGATION', - }, - }, - ], - }, - ], - }, - ]; - mainApplication['meta-data'] = [ { $: {