@dolami-inc/react-native-expo-unity 0.3.2 → 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 +78 -7
  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
  *
@@ -16,7 +38,8 @@ const fs = require('fs');
16
38
  * bundle at build time (device builds only)
17
39
  *
18
40
  * Android:
19
- * - Includes the :unityLibrary Gradle module in settings.gradle
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
  *
@@ -84,7 +107,7 @@ const withExpoUnity = (config, options = {}) => {
84
107
  return config;
85
108
  });
86
109
 
87
- // -- Android: settings.gradle (include :unityLibrary module) --
110
+ // -- Android: settings.gradle (include :unityLibrary module + subprojects) --
88
111
  config = withSettingsGradle(config, (config) => {
89
112
  const projectRoot = config.modRequest.projectRoot;
90
113
  const androidUnityPath =
@@ -92,18 +115,66 @@ const withExpoUnity = (config, options = {}) => {
92
115
  process.env.EXPO_UNITY_ANDROID_PATH ||
93
116
  path.join(projectRoot, 'unity', 'builds', 'android');
94
117
 
95
- const contents = config.modResults.contents;
118
+ const unityLibDir = path.join(androidUnityPath, 'unityLibrary');
96
119
 
97
120
  // Include :unityLibrary module
98
121
  const includeSnippet = `include ':unityLibrary'`;
99
- const projectSnippet = `project(':unityLibrary').projectDir = new File('${androidUnityPath}/unityLibrary')`;
122
+ const projectSnippet = `project(':unityLibrary').projectDir = new File('${unityLibDir}')`;
100
123
 
101
- if (!contents.includes(includeSnippet)) {
102
- config.modResults.contents =
103
- contents +
124
+ if (!config.modResults.contents.includes(includeSnippet)) {
125
+ config.modResults.contents +=
104
126
  `\n// Unity as a Library\n${includeSnippet}\n${projectSnippet}\n`;
105
127
  }
106
128
 
129
+ // Auto-discover .androidlib subprojects (e.g. xrmanifest.androidlib)
130
+ if (fs.existsSync(unityLibDir)) {
131
+ const subprojects = fs.readdirSync(unityLibDir).filter((name) =>
132
+ name.endsWith('.androidlib') &&
133
+ fs.existsSync(path.join(unityLibDir, name, 'build.gradle'))
134
+ );
135
+
136
+ for (const sub of subprojects) {
137
+ const subInclude = `include ':unityLibrary:${sub}'`;
138
+ if (!config.modResults.contents.includes(subInclude)) {
139
+ config.modResults.contents += `${subInclude}\n`;
140
+ }
141
+ }
142
+ }
143
+
144
+ return config;
145
+ });
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
+
107
178
  return config;
108
179
  });
109
180
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolami-inc/react-native-expo-unity",
3
- "version": "0.3.2",
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",