@dolami-inc/react-native-expo-unity 0.3.3 → 0.3.4

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 (2) hide show
  1. package/app.plugin.js +57 -0
  2. package/package.json +1 -1
package/app.plugin.js CHANGED
@@ -3,10 +3,32 @@ const {
3
3
  withSettingsGradle,
4
4
  withProjectBuildGradle,
5
5
  withAppBuildGradle,
6
+ withGradleProperties,
6
7
  } = require('@expo/config-plugins');
7
8
  const path = require('path');
8
9
  const fs = require('fs');
9
10
 
11
+ /**
12
+ * Parse a Java .properties file into an array of { type, key, value } entries.
13
+ */
14
+ function parsePropertiesFile(filePath) {
15
+ if (!fs.existsSync(filePath)) return [];
16
+ const lines = fs.readFileSync(filePath, 'utf8').split('\n');
17
+ const entries = [];
18
+ for (const line of lines) {
19
+ const trimmed = line.trim();
20
+ if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith('!')) continue;
21
+ const eqIndex = trimmed.indexOf('=');
22
+ if (eqIndex === -1) continue;
23
+ entries.push({
24
+ type: 'property',
25
+ key: trimmed.slice(0, eqIndex).trim(),
26
+ value: trimmed.slice(eqIndex + 1).trim(),
27
+ });
28
+ }
29
+ return entries;
30
+ }
31
+
10
32
  /**
11
33
  * Expo Config Plugin for @dolami-inc/react-native-expo-unity.
12
34
  *
@@ -17,6 +39,7 @@ const fs = require('fs');
17
39
  *
18
40
  * Android:
19
41
  * - Includes the :unityLibrary Gradle module and .androidlib subprojects in settings.gradle
42
+ * - Copies Unity gradle properties (unity.*, unityStreamingAssets) to host gradle.properties
20
43
  * - Adds flatDir repos for Unity's .aar/.jar libs in root build.gradle
21
44
  * - Adds the unityLibrary dependency and NDK abiFilters in app/build.gradle
22
45
  *
@@ -121,6 +144,40 @@ const withExpoUnity = (config, options = {}) => {
121
144
  return config;
122
145
  });
123
146
 
147
+ // -- Android: gradle.properties (copy Unity properties to host project) --
148
+ // Unity's build.gradle references properties like `unityStreamingAssets` and
149
+ // `unity.*` that are defined in the Unity export's gradle.properties. When the
150
+ // unityLibrary is included as a subproject, it inherits the host's properties,
151
+ // so we need to copy the required ones over.
152
+ config = withGradleProperties(config, (config) => {
153
+ const projectRoot = config.modRequest.projectRoot;
154
+ const androidUnityPath =
155
+ options.androidUnityPath ||
156
+ process.env.EXPO_UNITY_ANDROID_PATH ||
157
+ path.join(projectRoot, 'unity', 'builds', 'android');
158
+
159
+ const unityPropsPath = path.join(androidUnityPath, 'gradle.properties');
160
+ const unityProps = parsePropertiesFile(unityPropsPath);
161
+
162
+ // Only copy unity-specific properties (unity.* and unityStreamingAssets)
163
+ const existingKeys = new Set(
164
+ config.modResults
165
+ .filter((p) => p.type === 'property')
166
+ .map((p) => p.key)
167
+ );
168
+
169
+ for (const prop of unityProps) {
170
+ if (
171
+ (prop.key.startsWith('unity.') || prop.key === 'unityStreamingAssets' || prop.key === 'unityTemplateVersion') &&
172
+ !existingKeys.has(prop.key)
173
+ ) {
174
+ config.modResults.push(prop);
175
+ }
176
+ }
177
+
178
+ return config;
179
+ });
180
+
124
181
  // -- Android: build.gradle (flatDir repos for Unity's native libs) --
125
182
  // This must go in the root build.gradle (not settings.gradle) because
126
183
  // `allprojects` is not a valid method in settings.gradle on Gradle 8+.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolami-inc/react-native-expo-unity",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
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",