Skip to content

Commit b9ccc1c

Browse files
committed
feat(expo): added Gradle and Podfile plugins
1 parent aa09182 commit b9ccc1c

File tree

6 files changed

+1306
-4
lines changed

6 files changed

+1306
-4
lines changed

app.plugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("./expo/withVlcMediaPlayer");

expo/android/withGradleTasks.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { withAppBuildGradle } = require("@expo/config-plugins");
2+
const generateCode = require("@expo/config-plugins/build/utils/generateCode");
3+
4+
const resolveAppGradleString = (options) => {
5+
// for React Native 0.71, the file value now contains "jetified-react-android" instead of "jetified-react-native"
6+
const rnJetifierName = options?.android?.legacyJetifier ? "jetified-react-native" : "jetified-react-android";
7+
8+
const gradleString = `tasks.whenTaskAdded((tas -> {
9+
// when task is 'mergeLocalDebugNativeLibs' or 'mergeLocalReleaseNativeLibs'
10+
if (tas.name.contains("merge") && tas.name.contains("NativeLibs")) {
11+
tasks.named(tas.name) {it
12+
doFirst {
13+
java.nio.file.Path notNeededDirectory = it.externalLibNativeLibs
14+
.getFiles()
15+
.stream()
16+
.filter(file -> file.toString().contains("${rnJetifierName}"))
17+
.findAny()
18+
.orElse(null)
19+
.toPath();
20+
java.nio.file.Files.walk(notNeededDirectory).forEach(file -> {
21+
if (file.toString().contains("libc++_shared.so")) {
22+
java.nio.file.Files.delete(file);
23+
}
24+
});
25+
}
26+
}
27+
}
28+
}))`;
29+
30+
return gradleString;
31+
};
32+
33+
const withGradleTasks = (config, options) => {
34+
return withAppBuildGradle(config, (config) => {
35+
const newCode = generateCode.mergeContents({
36+
tag: "withVlcMediaPlayer",
37+
src: config.modResults.contents,
38+
newSrc: resolveAppGradleString(options),
39+
anchor: /applyNativeModulesAppBuildGradle\(project\)/i,
40+
offset: 2,
41+
comment: "//",
42+
});
43+
44+
config.modResults.contents = newCode.contents;
45+
46+
return config;
47+
});
48+
};
49+
50+
module.exports = withGradleTasks;

expo/ios/withMobileVlcKit.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const { withDangerousMod } = require("@expo/config-plugins");
2+
const generateCode = require("@expo/config-plugins/build/utils/generateCode");
3+
const path = require("path");
4+
const fs = require("fs");
5+
6+
const withMobileVlcKit = (config, options) => {
7+
// No need if you are running RN 0.61 and up
8+
if (!options?.ios?.includeVLCKit) {
9+
console.log("okok");
10+
return config;
11+
}
12+
13+
return withDangerousMod(config, [
14+
"ios",
15+
(config) => {
16+
const filePath = path.join(config.modRequest.platformProjectRoot, "Podfile");
17+
18+
const contents = fs.readFileSync(filePath, "utf-8");
19+
20+
const newCode = generateCode.mergeContents({
21+
tag: "withVlcMediaPlayer",
22+
src: contents,
23+
newSrc: " pod 'MobileVLCKit', '3.3.10'",
24+
anchor: /use\_expo\_modules\!/i,
25+
offset: 3,
26+
comment: " #",
27+
});
28+
29+
fs.writeFileSync(filePath, newCode.contents);
30+
31+
return config;
32+
},
33+
]);
34+
};
35+
36+
module.exports = withMobileVlcKit;

expo/withVlcMediaPlayer.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const withGradleTasks = require("./android/withGradleTasks");
2+
const withMobileVlcKit = require("./ios/withMobileVlcKit");
3+
4+
/**
5+
* Adds required native code to work with expo development build
6+
*
7+
* @param {object} config - Expo native configuration
8+
* @param {object} options - Plugin options
9+
* @param {boolean} options.ios.includeVLCKit - If `true`, it will include VLC Kit on PodFile (No need if you are running RN 0.61 and up)
10+
* @param {boolean} options.android.legacyJetifier - Must be `true`, if react-native version lower than 0.71 to replace jetifier name on from react native libs
11+
*
12+
* @returns resolved expo configuration
13+
*/
14+
const withVlcMediaPlayer = (config, options) => {
15+
config = withGradleTasks(config, options);
16+
config = withMobileVlcKit(config, options);
17+
18+
return config;
19+
};
20+
21+
module.exports = withVlcMediaPlayer;

0 commit comments

Comments
 (0)