-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathapp.plugin.js
More file actions
109 lines (99 loc) · 3.31 KB
/
app.plugin.js
File metadata and controls
109 lines (99 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const {
AndroidConfig,
withProjectBuildGradle,
withDangerousMod,
withGradleProperties,
withSettingsGradle,
withStringsXml,
} = require('@expo/config-plugins');
const fs = require('fs');
const path = require('path');
const withUnity = (config, { name = 'react-native-unity' } = {}) => {
config.name = name;
config = withProjectBuildGradleMod(config);
config = withSettingsGradleMod(config);
config = withGradlePropertiesMod(config);
config = withStringsXMLMod(config);
config = withPodfileDangerousMod(config);
return config;
};
const REPOSITORIES_END_LINE = `maven { url 'https://www.jitpack.io' }`;
const withProjectBuildGradleMod = (config) =>
withProjectBuildGradle(config, (modConfig) => {
if (modConfig.modResults.contents.includes(REPOSITORIES_END_LINE)) {
// use the last known line in expo's build.gradle file to append the newline after
modConfig.modResults.contents = modConfig.modResults.contents.replace(
REPOSITORIES_END_LINE,
REPOSITORIES_END_LINE +
'\nflatDir { dirs "${project(\':unityLibrary\').projectDir}/libs" }\n'
);
} else {
throw new Error(
'Failed to find the end of repositories in the android/build.gradle file`'
);
}
return modConfig;
});
const withSettingsGradleMod = (config) =>
withSettingsGradle(config, (modConfig) => {
modConfig.modResults.contents += `
include ':unityLibrary'
project(':unityLibrary').projectDir=new File('../unity/builds/android/unityLibrary')
`;
return modConfig;
});
const withGradlePropertiesMod = (config) =>
withGradleProperties(config, (modConfig) => {
modConfig.modResults.push({
type: 'property',
key: 'unityStreamingAssets',
value: '.unity3d',
});
return modConfig;
});
// add string
const withStringsXMLMod = (config) =>
withStringsXml(config, (modConfig) => {
modConfig.modResults = AndroidConfig.Strings.setStringItem(
[
{
_: 'Game View',
$: {
name: 'game_view_content_description',
},
},
],
modConfig.modResults
);
return modConfig;
});
/*
Adjust the Podfile to exclude arm64 architecture for simulator builds
for all the pods in the project
This is also necessary in order to get the Unity project to build for simulator
*/
const withPodfileDangerousMod = (config) =>
withDangerousMod(config, [
'ios',
(modConfig) => {
/*
We need to do a 'dangerous' mod to the Podfile
and add lines to the post install hook to exclude arm64 architecture for simulator builds
*/
const file = path.join(
modConfig.modRequest.platformProjectRoot,
'Podfile'
);
const contents = fs.readFileSync(file).toString();
// look for the closing bracket of the `react_native_post_install` block, insert stuff on the following lines
const regex = /react_native_post_install\([^)]+\)\s*/;
const newLine = `
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end\n\n`;
const newContents = contents.replace(regex, '$&\n' + newLine);
fs.writeFileSync(file, newContents);
return modConfig;
},
]);
module.exports = withUnity;