From 7b0a31630b1fad2681460cb734a040904c97004b Mon Sep 17 00:00:00 2001 From: Tom Van Laerhoven Date: Tue, 19 Dec 2023 16:02:57 +0100 Subject: [PATCH 1/4] Add expo plugin for Android --- app.plugin.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app.plugin.js diff --git a/app.plugin.js b/app.plugin.js new file mode 100644 index 000000000..7c2c447a7 --- /dev/null +++ b/app.plugin.js @@ -0,0 +1,21 @@ +/** + * Expo plugin for react-native-theoplayer. + */ +const { withProjectBuildGradle } = require('@expo/config-plugins'); + +const withAndroidTHEOplayerGradle = (config) => { + const localMaven = 'maven { url("$rootDir/../node_modules/react-native-theoplayer/android/local") }'; + + return withProjectBuildGradle(config, (config) => { + // Add the localMaven repo to the project's repositories + config.modResults.contents = config.modResults.contents.replace( + /allprojects\s*\{\s*repositories\s*\{/, + `$&\n\t\t${localMaven}` + ) + return config; + }); +}; + +module.exports = (config) => { + return withAndroidTHEOplayerGradle(config); +}; From b26d9ba31b8f2803c90c1b34f88f7ed8b8ebc0c9 Mon Sep 17 00:00:00 2001 From: Tom Van Laerhoven Date: Tue, 19 Dec 2023 16:03:19 +0100 Subject: [PATCH 2/4] Include expo plugin in package --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 2e713fb52..0f85dc8ba 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "react-native-theoplayer.podspec", "react-native-theoplayer.json", "CHANGELOG.md", + "app.plugin.js", "!lib/typescript/example", "!android/build", "!ios/build", From af9fc623d5406f6e826685048c366f25b4f64ef9 Mon Sep 17 00:00:00 2001 From: Tom Van Laerhoven Date: Tue, 19 Dec 2023 16:04:18 +0100 Subject: [PATCH 3/4] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a4d07cd2..fda726e1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + +- Added Expo plugin to support Android dependency configuration. + ### Changed - Changed the Android notification channel name to `Notification channel`. It can be renamed by defining the `notification_channel_name` resource string. From d7ecb99b35c048842417604451618f0004ed1841 Mon Sep 17 00:00:00 2001 From: Tom Van Laerhoven Date: Tue, 19 Dec 2023 23:27:34 +0100 Subject: [PATCH 4/4] Add Android extensions --- app.plugin.js | 62 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/app.plugin.js b/app.plugin.js index 7c2c447a7..fb79ada95 100644 --- a/app.plugin.js +++ b/app.plugin.js @@ -1,21 +1,57 @@ /** * Expo plugin for react-native-theoplayer. + * + * Example: + * "plugins": [ + * ["react-native-theoplayer", { + * "extensions": ["ima", "dai", "cast"] + * }] + * ] */ -const { withProjectBuildGradle } = require('@expo/config-plugins'); +const {withProjectBuildGradle, withGradleProperties} = require('@expo/config-plugins'); -const withAndroidTHEOplayerGradle = (config) => { - const localMaven = 'maven { url("$rootDir/../node_modules/react-native-theoplayer/android/local") }'; +function mapAndroidExtensionKey(ext) { + switch (ext) { + case "ima": + return "THEOplayer_extensionGoogleIMA"; + case "dai": + return "THEOplayer_extensionGoogleDAI"; + case "cast": + return "THEOplayer_extensionCast"; + default: + return undefined; + } +} + +const applyAndroidExtensions = (config, extensions) => { + return withGradleProperties(config, (config) => { + extensions?.forEach(ext => { + const key = mapAndroidExtensionKey(ext); + if (key) { + config.modResults.push({type: "property", key, value: true}); + } + }); + return config; + }); +} + +const withAndroidTHEOplayer = (config, props) => { + // Apply Android extensions + const {extensions} = props; + config = applyAndroidExtensions(config, extensions); - return withProjectBuildGradle(config, (config) => { // Add the localMaven repo to the project's repositories - config.modResults.contents = config.modResults.contents.replace( - /allprojects\s*\{\s*repositories\s*\{/, - `$&\n\t\t${localMaven}` - ) - return config; - }); + return withProjectBuildGradle(config, (config) => { + const localMaven = 'maven { url("$rootDir/../node_modules/react-native-theoplayer/android/local") }'; + config.modResults.contents = config.modResults.contents.replace( + /allprojects\s*\{\s*repositories\s*\{/, + `$&\n\t\t${localMaven}` + ) + return config; + }); }; -module.exports = (config) => { - return withAndroidTHEOplayerGradle(config); -}; +module.exports = (config, props) => { + // Apply Android modifications + return withAndroidTHEOplayer(config, props); +}