@dolami-inc/react-native-expo-unity 0.1.9 → 0.2.0

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.
Files changed (3) hide show
  1. package/README.md +22 -4
  2. package/app.plugin.js +34 -19
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -73,20 +73,38 @@ cp node_modules/@dolami-inc/react-native-expo-unity/plugin/NativeCallProxy.mm <U
73
73
 
74
74
  ### 2. Unity project — build iOS
75
75
 
76
+ > 📹 **Video guide** (click to play):
77
+ >
78
+ > [![Xcode export settings](xcode-settings-thumb.jpg)](xcode-settings.mp4)
79
+
76
80
  1. Unity → File → Build Settings → iOS → Build
77
81
  2. Open generated Xcode project
78
82
  3. Select `NativeCallProxy.h` in Libraries/Plugins/iOS/
79
83
  4. Set Target Membership → `UnityFramework` → **Public**
80
- 5. Build `UnityFramework` scheme
84
+ 5. **Select the `Data` folder** in the Project Navigator
85
+ 6. In the right panel under **Target Membership**, check **`UnityFramework`** ✅
86
+ > ⚠️ **This is critical.** Without this, the `Data` folder (which contains `global-metadata.dat` and all Unity assets) will NOT be included inside `UnityFramework.framework`. The app will crash at launch with: `Could not open .../global-metadata.dat — IL2CPP initialization failed`
87
+ 7. Build `UnityFramework` scheme
81
88
 
82
89
  ### 3. Copy build artifacts to your RN project
83
90
 
84
- Create `unity/builds/ios/` in your project root and copy all artifacts from your Unity iOS build:
91
+ Create `unity/builds/ios/` in your project root and copy the built framework and static libraries:
85
92
 
86
93
  ```bash
87
94
  mkdir -p unity/builds/ios
88
- cp -R <unity-build>/UnityFramework.framework unity/builds/ios/
89
- cp <unity-build>/*.a unity/builds/ios/
95
+
96
+ # Copy the compiled framework (should already contain Data/ inside after step 2.6)
97
+ cp -R <xcode-build-output>/UnityFramework.framework unity/builds/ios/
98
+
99
+ # Copy static libraries from the Unity Xcode project root
100
+ cp <unity-xcode-project>/*.a unity/builds/ios/
101
+ ```
102
+
103
+ Verify that `Data/` exists inside the framework:
104
+
105
+ ```bash
106
+ ls unity/builds/ios/UnityFramework.framework/Data
107
+ # Should show: Managed/ Resources/ etc.
90
108
  ```
91
109
 
92
110
  The podspec references these files **directly by path** — nothing is copied or embedded into the npm package. Updating your Unity build is as simple as replacing the contents of `unity/builds/ios/` and re-running `pod install`.
package/app.plugin.js CHANGED
@@ -6,8 +6,8 @@ const fs = require('fs');
6
6
  * Expo Config Plugin for @dolami-inc/react-native-expo-unity.
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
+ * - Adds a build phase that embeds UnityFramework.framework into the app
10
+ * bundle at build time (device builds only)
11
11
  *
12
12
  * @param {object} config - Expo config
13
13
  * @param {{ unityPath?: string }} options
@@ -20,7 +20,6 @@ const withExpoUnity = (config, options = {}) => {
20
20
  const xcodeProject = config.modResults;
21
21
  const projectRoot = config.modRequest.projectRoot;
22
22
 
23
- // Resolve actual filesystem path for the Unity build artifacts.
24
23
  const unityPath =
25
24
  options.unityPath ||
26
25
  process.env.EXPO_UNITY_PATH ||
@@ -33,27 +32,43 @@ const withExpoUnity = (config, options = {}) => {
33
32
  if (typeof configuration !== 'object' || !configuration.buildSettings) {
34
33
  continue;
35
34
  }
36
-
37
35
  const settings = configuration.buildSettings;
38
-
39
- // Unity as a Library does not support bitcode.
40
36
  settings['ENABLE_BITCODE'] = 'NO';
41
-
42
- // Unity headers require C++17.
43
- // Must be quoted — '+' causes CocoaPods' plist parser to fail if unquoted.
44
37
  settings['CLANG_CXX_LANGUAGE_STANDARD'] = '"c++17"';
45
38
  }
46
39
 
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
- });
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();
48
+
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
+ );
57
72
  }
58
73
 
59
74
  return config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolami-inc/react-native-expo-unity",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "Unity as a Library (UaaL) bridge for React Native / Expo",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",