diff --git a/CHANGELOG.md b/CHANGELOG.md index 9aa6b869e..326dec6eb 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. diff --git a/app.plugin.js b/app.plugin.js new file mode 100644 index 000000000..fb79ada95 --- /dev/null +++ b/app.plugin.js @@ -0,0 +1,57 @@ +/** + * Expo plugin for react-native-theoplayer. + * + * Example: + * "plugins": [ + * ["react-native-theoplayer", { + * "extensions": ["ima", "dai", "cast"] + * }] + * ] + */ +const {withProjectBuildGradle, withGradleProperties} = require('@expo/config-plugins'); + +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); + + // Add the localMaven repo to the project's repositories + 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, props) => { + // Apply Android modifications + return withAndroidTHEOplayer(config, props); +} 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",