@dolami-inc/react-native-expo-unity 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.plugin.js +24 -44
- package/ios/ExpoUnity.podspec +10 -10
- package/package.json +1 -1
package/app.plugin.js
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
// @ts-check
|
|
2
1
|
const { withXcodeProject } = require('@expo/config-plugins');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
|
-
* Expo Config Plugin for react-native-expo-unity.
|
|
6
|
+
* Expo Config Plugin for @dolami-inc/react-native-expo-unity.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
8
|
+
* - Injects required Xcode build settings (bitcode, C++17)
|
|
9
|
+
* - Embeds UnityFramework.framework into the app bundle so it's
|
|
10
|
+
* available at runtime (Unity ships as a dynamic framework)
|
|
9
11
|
*
|
|
10
|
-
* @param {
|
|
12
|
+
* @param {object} config - Expo config
|
|
11
13
|
* @param {{ unityPath?: string }} options
|
|
12
|
-
* unityPath — path to the Unity iOS build artifacts directory.
|
|
13
|
-
* Defaults to
|
|
14
|
+
* unityPath — absolute path to the Unity iOS build artifacts directory.
|
|
15
|
+
* Defaults to `<projectRoot>/unity/builds/ios`.
|
|
14
16
|
* Can also be set via the EXPO_UNITY_PATH environment variable.
|
|
15
17
|
*/
|
|
16
18
|
const withExpoUnity = (config, options = {}) => {
|
|
17
19
|
return withXcodeProject(config, (config) => {
|
|
18
20
|
const xcodeProject = config.modResults;
|
|
21
|
+
const projectRoot = config.modRequest.projectRoot;
|
|
19
22
|
|
|
23
|
+
// Resolve actual filesystem path for the Unity build artifacts.
|
|
20
24
|
const unityPath =
|
|
21
25
|
options.unityPath ||
|
|
22
26
|
process.env.EXPO_UNITY_PATH ||
|
|
23
|
-
'
|
|
27
|
+
path.join(projectRoot, 'unity', 'builds', 'ios');
|
|
24
28
|
|
|
29
|
+
// -- Build settings --
|
|
25
30
|
const configurations = xcodeProject.pbxXCBuildConfigurationSection();
|
|
26
|
-
|
|
27
31
|
for (const key of Object.keys(configurations)) {
|
|
28
32
|
const configuration = configurations[key];
|
|
29
33
|
if (typeof configuration !== 'object' || !configuration.buildSettings) {
|
|
@@ -38,46 +42,22 @@ const withExpoUnity = (config, options = {}) => {
|
|
|
38
42
|
// Unity headers require C++17.
|
|
39
43
|
// Must be quoted — '+' causes CocoaPods' plist parser to fail if unquoted.
|
|
40
44
|
settings['CLANG_CXX_LANGUAGE_STANDARD'] = '"c++17"';
|
|
45
|
+
}
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
// -- Embed UnityFramework --
|
|
48
|
+
// UnityFramework is a dynamic framework. It must be embedded (copied) into
|
|
49
|
+
// the app bundle's Frameworks/ directory, otherwise dyld fails at launch.
|
|
50
|
+
const frameworkPath = path.join(unityPath, 'UnityFramework.framework');
|
|
51
|
+
if (fs.existsSync(frameworkPath)) {
|
|
52
|
+
xcodeProject.addFramework(frameworkPath, {
|
|
53
|
+
customFramework: true,
|
|
54
|
+
embed: true,
|
|
55
|
+
sign: true,
|
|
56
|
+
});
|
|
45
57
|
}
|
|
46
58
|
|
|
47
59
|
return config;
|
|
48
60
|
});
|
|
49
61
|
};
|
|
50
62
|
|
|
51
|
-
/**
|
|
52
|
-
* Appends `unityPath` to FRAMEWORK_SEARCH_PATHS without duplicating it.
|
|
53
|
-
*
|
|
54
|
-
* The xcode npm package stores this setting as either:
|
|
55
|
-
* - undefined (not set)
|
|
56
|
-
* - a plain string: `"$(inherited)"`
|
|
57
|
-
* - a parenthesised list: `("$(inherited)", "/some/path")`
|
|
58
|
-
*
|
|
59
|
-
* @param {Record<string, any>} settings
|
|
60
|
-
* @param {string} unityPath
|
|
61
|
-
*/
|
|
62
|
-
function addFrameworkSearchPath(settings, unityPath) {
|
|
63
|
-
const quoted = `"${unityPath}"`;
|
|
64
|
-
const existing = settings['FRAMEWORK_SEARCH_PATHS'];
|
|
65
|
-
|
|
66
|
-
if (!existing) {
|
|
67
|
-
settings['FRAMEWORK_SEARCH_PATHS'] = `(${quoted}, "$(inherited)")`;
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const asStr = String(existing);
|
|
72
|
-
|
|
73
|
-
// Already present — nothing to do.
|
|
74
|
-
if (asStr.includes(unityPath)) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Strip surrounding parens if present, then rebuild.
|
|
79
|
-
const inner = asStr.replace(/^\(|\)$/g, '').trim();
|
|
80
|
-
settings['FRAMEWORK_SEARCH_PATHS'] = `(${quoted}, ${inner})`;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
63
|
module.exports = withExpoUnity;
|
package/ios/ExpoUnity.podspec
CHANGED
|
@@ -34,26 +34,26 @@ Pod::Spec.new do |s|
|
|
|
34
34
|
framework_exists = File.exist?(File.join(unity_ios_dir, 'UnityFramework.framework'))
|
|
35
35
|
a_files = Dir.glob(File.join(unity_ios_dir, '*.a'))
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
unity_ldflags
|
|
37
|
+
# Only static libs (.a) here — UnityFramework.framework linking + embedding
|
|
38
|
+
# is handled by the Expo config plugin (app.plugin.js) via addFramework.
|
|
39
|
+
unity_ldflags = a_files.map { |f| "\"#{f}\"" }
|
|
40
40
|
|
|
41
41
|
# Unity framework is ARM-only (device build) — never link it for Simulator.
|
|
42
42
|
# The [sdk=iphoneos*] conditional ensures these settings only apply when
|
|
43
43
|
# building for a physical device, not the Simulator SDK.
|
|
44
44
|
s.pod_target_xcconfig = {
|
|
45
|
-
'HEADER_SEARCH_PATHS' => "\"#{unity_ios_dir}/UnityFramework.framework/Headers\"",
|
|
46
|
-
'FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]' => "\"#{unity_ios_dir}\"",
|
|
47
|
-
'OTHER_LDFLAGS[sdk=iphoneos*]' => unity_ldflags.join(' '),
|
|
45
|
+
'HEADER_SEARCH_PATHS' => "$(inherited) \"#{unity_ios_dir}/UnityFramework.framework/Headers\"",
|
|
46
|
+
'FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]' => "$(inherited) \"#{unity_ios_dir}\"",
|
|
47
|
+
'OTHER_LDFLAGS[sdk=iphoneos*]' => "$(inherited) #{unity_ldflags.join(' ')}",
|
|
48
48
|
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
|
|
49
|
-
'GCC_PREPROCESSOR_DEFINITIONS' => 'UNITY_FRAMEWORK=1',
|
|
49
|
+
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) UNITY_FRAMEWORK=1',
|
|
50
50
|
'ENABLE_BITCODE' => 'NO'
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
s.user_target_xcconfig = {
|
|
54
54
|
'ENABLE_BITCODE' => 'NO',
|
|
55
|
-
'FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]' => "\"#{unity_ios_dir}\"",
|
|
56
|
-
'LIBRARY_SEARCH_PATHS[sdk=iphoneos*]' => "\"#{unity_ios_dir}\"",
|
|
57
|
-
'OTHER_LDFLAGS[sdk=iphoneos*]' => unity_ldflags.join(' ')
|
|
55
|
+
'FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]' => "$(inherited) \"#{unity_ios_dir}\"",
|
|
56
|
+
'LIBRARY_SEARCH_PATHS[sdk=iphoneos*]' => "$(inherited) \"#{unity_ios_dir}\"",
|
|
57
|
+
'OTHER_LDFLAGS[sdk=iphoneos*]' => "$(inherited) #{unity_ldflags.join(' ')}"
|
|
58
58
|
}
|
|
59
59
|
end
|