@dolami-inc/react-native-expo-unity 0.1.8 → 0.1.10
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 +45 -50
- package/ios/ExpoUnity.podspec +3 -3
- package/package.json +1 -1
package/app.plugin.js
CHANGED
|
@@ -1,83 +1,78 @@
|
|
|
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
|
+
* - Adds a build phase that embeds UnityFramework.framework into the app
|
|
10
|
+
* bundle at build time (device builds only)
|
|
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
|
|
|
20
23
|
const unityPath =
|
|
21
24
|
options.unityPath ||
|
|
22
25
|
process.env.EXPO_UNITY_PATH ||
|
|
23
|
-
'
|
|
26
|
+
path.join(projectRoot, 'unity', 'builds', 'ios');
|
|
24
27
|
|
|
28
|
+
// -- Build settings --
|
|
25
29
|
const configurations = xcodeProject.pbxXCBuildConfigurationSection();
|
|
26
|
-
|
|
27
30
|
for (const key of Object.keys(configurations)) {
|
|
28
31
|
const configuration = configurations[key];
|
|
29
32
|
if (typeof configuration !== 'object' || !configuration.buildSettings) {
|
|
30
33
|
continue;
|
|
31
34
|
}
|
|
32
|
-
|
|
33
35
|
const settings = configuration.buildSettings;
|
|
34
|
-
|
|
35
|
-
// Unity as a Library does not support bitcode.
|
|
36
36
|
settings['ENABLE_BITCODE'] = 'NO';
|
|
37
|
-
|
|
38
|
-
// Unity headers require C++17.
|
|
39
|
-
// Must be quoted — '+' causes CocoaPods' plist parser to fail if unquoted.
|
|
40
37
|
settings['CLANG_CXX_LANGUAGE_STANDARD'] = '"c++17"';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// -- Embed UnityFramework via build script phase --
|
|
41
|
+
// UnityFramework is a dynamic framework that must be embedded (copied)
|
|
42
|
+
// into the app bundle's Frameworks/ directory, otherwise dyld fails at
|
|
43
|
+
// launch. We use a shell script build phase instead of vendored_frameworks
|
|
44
|
+
// because the pod source may live in a read-only package manager cache.
|
|
45
|
+
const frameworkSrc = path.join(unityPath, 'UnityFramework.framework');
|
|
46
|
+
if (fs.existsSync(frameworkSrc)) {
|
|
47
|
+
const target = xcodeProject.getFirstTarget();
|
|
41
48
|
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
// Shell script that copies and codesigns the framework (device only).
|
|
50
|
+
const script = [
|
|
51
|
+
'if [ "${PLATFORM_NAME}" = "iphoneos" ]; then',
|
|
52
|
+
' FRAMEWORK_SRC="' + frameworkSrc + '"',
|
|
53
|
+
' DEST="${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}"',
|
|
54
|
+
' mkdir -p "${DEST}"',
|
|
55
|
+
' rsync -av --delete "${FRAMEWORK_SRC}" "${DEST}/"',
|
|
56
|
+
' if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" ]; then',
|
|
57
|
+
' codesign --force --sign "${EXPANDED_CODE_SIGN_IDENTITY}" "${DEST}/UnityFramework.framework"',
|
|
58
|
+
' fi',
|
|
59
|
+
'fi',
|
|
60
|
+
].join('\n');
|
|
61
|
+
|
|
62
|
+
xcodeProject.addBuildPhase(
|
|
63
|
+
[],
|
|
64
|
+
'PBXShellScriptBuildPhase',
|
|
65
|
+
'Embed UnityFramework',
|
|
66
|
+
target.uuid,
|
|
67
|
+
{
|
|
68
|
+
shellPath: '/bin/sh',
|
|
69
|
+
shellScript: script,
|
|
70
|
+
}
|
|
71
|
+
);
|
|
45
72
|
}
|
|
46
73
|
|
|
47
74
|
return config;
|
|
48
75
|
});
|
|
49
76
|
};
|
|
50
77
|
|
|
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
78
|
module.exports = withExpoUnity;
|
package/ios/ExpoUnity.podspec
CHANGED
|
@@ -34,9 +34,9 @@ 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
|