@mendix/native 10.1.1 → 10.1.2

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.
@@ -10,18 +10,15 @@
10
10
  <key>HeadersPath</key>
11
11
  <string>Headers</string>
12
12
  <key>LibraryIdentifier</key>
13
- <string>ios-arm64_x86_64-simulator</string>
13
+ <string>ios-arm64</string>
14
14
  <key>LibraryPath</key>
15
15
  <string>libMendixNative.a</string>
16
16
  <key>SupportedArchitectures</key>
17
17
  <array>
18
18
  <string>arm64</string>
19
- <string>x86_64</string>
20
19
  </array>
21
20
  <key>SupportedPlatform</key>
22
21
  <string>ios</string>
23
- <key>SupportedPlatformVariant</key>
24
- <string>simulator</string>
25
22
  </dict>
26
23
  <dict>
27
24
  <key>BinaryPath</key>
@@ -29,15 +26,18 @@
29
26
  <key>HeadersPath</key>
30
27
  <string>Headers</string>
31
28
  <key>LibraryIdentifier</key>
32
- <string>ios-arm64</string>
29
+ <string>ios-arm64_x86_64-simulator</string>
33
30
  <key>LibraryPath</key>
34
31
  <string>libMendixNative.a</string>
35
32
  <key>SupportedArchitectures</key>
36
33
  <array>
37
34
  <string>arm64</string>
35
+ <string>x86_64</string>
38
36
  </array>
39
37
  <key>SupportedPlatform</key>
40
38
  <string>ios</string>
39
+ <key>SupportedPlatformVariant</key>
40
+ <string>simulator</string>
41
41
  </dict>
42
42
  </array>
43
43
  <key>CFBundlePackageType</key>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mendix/native",
3
- "version": "10.1.1",
3
+ "version": "10.1.2",
4
4
  "copyright": "© Mendix Technology BV. All rights reserved.",
5
5
  "files": [
6
6
  "androidlib/",
@@ -1,2 +0,0 @@
1
- configurations.maybeCreate("default")
2
- artifacts.add("default", file("mendixnative-release.aar"))
@@ -1,438 +0,0 @@
1
- import groovy.json.JsonSlurper
2
-
3
- def LOG_PREFIX = ":Mendix: "
4
-
5
- def rootDir = buildscript.sourceFile.toString().split("node_modules")[0]
6
- def cliBinPath = "${rootDir}/node_modules/.bin/react-native${System.properties['os.name'].toLowerCase().contains('windows') ? ".cmd" : ""}"
7
-
8
- def generatedFilePackage = "com.mendix.nativetemplate"
9
- def mainActivityObserverFileName = "MendixActivityObserver.java"
10
- def mainActivityObserverTemplate = """package $generatedFilePackage;
11
-
12
- import android.content.Context;
13
-
14
- import androidx.lifecycle.Lifecycle;
15
- import androidx.lifecycle.LifecycleObserver;
16
- import androidx.lifecycle.OnLifecycleEvent;
17
- {{imports}}
18
-
19
- public class MendixActivityObserver implements LifecycleObserver {
20
- private final Context context;
21
-
22
- public MendixActivityObserver(Context activity) {
23
- this.context = activity;
24
- }
25
-
26
- @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
27
- void onCreate() {
28
- {{onCreate}}
29
- }
30
-
31
- @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
32
- void onResume() {
33
- {{onResume}}
34
- }
35
-
36
- @OnLifecycleEvent(Lifecycle.Event.ON_START)
37
- void onStart() {
38
- {{onStart}}
39
- }
40
-
41
- @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
42
- void onPause() {
43
- {{onPause}}
44
- }
45
-
46
- @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
47
- void onStop() {
48
- {{onStop}}
49
- }
50
-
51
- @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
52
- void onDestroy() {
53
- {{onDestroy}}
54
- }
55
- }
56
- """
57
- def mendixPackageListFileName = "MendixPackageList.java"
58
- def mendixPackageListTemplate = """package $generatedFilePackage;
59
-
60
- import android.app.Application;
61
- import android.content.Context;
62
- import android.content.res.Resources;
63
-
64
- import com.facebook.react.ReactPackage;
65
- import com.facebook.react.shell.MainPackageConfig;
66
- import com.facebook.react.shell.MainReactPackage;
67
- import java.util.Arrays;
68
- import java.util.ArrayList;
69
-
70
- {{imports}}
71
-
72
- public class MendixPackageList {
73
- private Application application;
74
-
75
- public MendixPackageList(Application application) {
76
- this.application = application;
77
- }
78
-
79
- private Resources getResources() {
80
- return this.getApplication().getResources();
81
- }
82
-
83
- private Application getApplication() {
84
- return this.application;
85
- }
86
-
87
- private Context getApplicationContext() {
88
- return this.getApplication().getApplicationContext();
89
- }
90
-
91
- public ArrayList<ReactPackage> getPackages() {
92
- return new ArrayList<>(Arrays.<ReactPackage>asList(
93
- {{packageClassInstances}}
94
- ));
95
- }
96
- }
97
- """
98
-
99
- class MendixModules {
100
- private static String LINE_ENDING_CHAR = "\n"
101
-
102
- private String cliBinPath
103
- private String rootDir
104
- private String logPrefix
105
- private Logger logger
106
- private ArrayList<HashMap<String, String>> reactNativeModules
107
- private Map dependenciesConfig = [:]
108
- private File capabilitiesConfigFile
109
- private File projectCapabilitiesFile
110
- private File nodeModulesDependenciesConfigFile
111
-
112
- MendixModules(File capabilitiesConfigFile, File nodeModulesDependenciesConfigFile, File projectCapabilitiesFile, String cliBinPath, String rootDir, Logger logger, String logPrefix) {
113
- this.logger = logger
114
- this.rootDir = rootDir
115
- this.cliBinPath = cliBinPath
116
- this.logPrefix = logPrefix
117
- this.capabilitiesConfigFile = capabilitiesConfigFile
118
- this.nodeModulesDependenciesConfigFile = nodeModulesDependenciesConfigFile
119
- this.projectCapabilitiesFile = projectCapabilitiesFile
120
-
121
- def (nativeModules) = this.getReactNativeConfig()
122
- this.reactNativeModules = nativeModules
123
- parseDependenciesConfig()
124
- }
125
-
126
- void printDependencies() {
127
- this.reactNativeModules.each {
128
- logDebug(it["name"])
129
- }
130
- }
131
-
132
- void parseDependenciesConfig() {
133
- def dependenciesConfig = [:]
134
- def capabilitiesConfig = [:]
135
-
136
- try {
137
- capabilitiesConfig = new JsonSlurper().parse(this.capabilitiesConfigFile)
138
- def projectCapabilities = new JsonSlurper().parse(this.projectCapabilitiesFile)
139
- capabilitiesConfig.retainAll { capabilityConfig ->
140
- projectCapabilities.find { enabledCapability ->
141
- enabledCapability.key == capabilityConfig.key && enabledCapability.value == true
142
- } && capabilityConfig.value["android"] != null
143
- }
144
- } catch (ignored) {
145
- this.logLifecycle("Failed parsing the capabilities file. Error?")
146
- }
147
-
148
- if (this.nodeModulesDependenciesConfigFile.exists()) {
149
- try {
150
- dependenciesConfig = new JsonSlurper().parse(this.nodeModulesDependenciesConfigFile)
151
- (dependenciesConfig as Map).retainAll { dependencyConfig ->
152
- this.reactNativeModules.find { nativeModule ->
153
- nativeModule.get("name") == dependencyConfig.key
154
- } && dependencyConfig.value["android"] != null
155
- }
156
- } catch (ignored) {
157
- this.logLifecycle("Failed parsing the configuration for unlinked node_modules. Error?")
158
- }
159
- }
160
-
161
- this.dependenciesConfig = capabilitiesConfig + dependenciesConfig
162
- printDependencies()
163
- }
164
-
165
- void generateMainActivityObserver(File outDir, String fileName, String template) {
166
- def activityImports = []
167
- def activityOnCreateEntries = []
168
- def activityOnStartEntries = []
169
- def activityOnResumeEntries = []
170
- def activityOnPauseEntries = []
171
- def activityOnStopEntries = []
172
- def activityOnDestroyEntries = []
173
-
174
- dependenciesConfig.each {
175
- def mainActivityDelegateEntry = it.value["android"]["MainActivity"]
176
- if (!mainActivityDelegateEntry)
177
- return
178
-
179
- def imports = mainActivityDelegateEntry.get("imports")
180
- if (imports)
181
- activityImports.addAll(imports)
182
-
183
- def onCreateEntries = mainActivityDelegateEntry.get("onCreate")
184
- if (onCreateEntries)
185
- activityOnCreateEntries.addAll(onCreateEntries)
186
-
187
- def onStartEntries = mainActivityDelegateEntry.get("onStart")
188
- if (onStartEntries)
189
- activityOnStartEntries.addAll(onStartEntries)
190
-
191
- def onResumeEntries = mainActivityDelegateEntry.get("onResume")
192
- if (onResumeEntries)
193
- activityOnResumeEntries.addAll(onResumeEntries)
194
-
195
- def onPauseEntries = mainActivityDelegateEntry.get("onPause")
196
- if (onPauseEntries)
197
- activityOnPauseEntries.addAll(onPauseEntries)
198
-
199
- def onStopEntries = mainActivityDelegateEntry.get("onStop")
200
- if (onStopEntries)
201
- activityOnStopEntries.addAll(onStopEntries)
202
-
203
- def onDestroyEntries = mainActivityDelegateEntry.get("onDestroy")
204
- if (onDestroyEntries)
205
- activityOnDestroyEntries.addAll(onDestroyEntries)
206
- }
207
-
208
- String CODE_PADDING = "${LINE_ENDING_CHAR} "
209
- String generatedFileContents = template
210
- .replace("{{imports}}", activityImports.join(LINE_ENDING_CHAR))
211
- .replace("{{onCreate}}", activityOnCreateEntries.join(CODE_PADDING))
212
- .replace("{{onStart}}", activityOnStartEntries.join(CODE_PADDING))
213
- .replace("{{onResume}}", activityOnResumeEntries.join(CODE_PADDING))
214
- .replace("{{onPause}}", activityOnPauseEntries.join(CODE_PADDING))
215
- .replace("{{onStop}}", activityOnStopEntries.join(CODE_PADDING))
216
- .replace("{{onDestroy}}", activityOnDestroyEntries.join(CODE_PADDING))
217
-
218
- outDir.mkdirs()
219
- new FileTreeBuilder(outDir).file(fileName).newWriter().withWriter {
220
- w ->
221
- w << generatedFileContents
222
- }
223
- }
224
-
225
- void generateMendixPackageList(File outDir, String fileName, String template) {
226
- String CODE_PADDING = "${LINE_ENDING_CHAR} "
227
- def imports = []
228
- def entries = []
229
- def entrySeparator = "," + CODE_PADDING
230
- dependenciesConfig.each {
231
- def packageListEntry = it.value["android"]["packageListEntries"]
232
- if (packageListEntry) {
233
- def importsEntry = packageListEntry["imports"]
234
- def packageClassInstances = packageListEntry["packageClassInstances"]
235
- if (importsEntry)
236
- imports.addAll(importsEntry)
237
- if (packageClassInstances)
238
- entries.addAll(packageClassInstances)
239
- }
240
- }
241
-
242
- String generatedFileContents = template.replace("{{imports}}", imports.join(CODE_PADDING)).replace("{{packageClassInstances}}", entries.join(entrySeparator))
243
-
244
- outDir.mkdirs()
245
- new FileTreeBuilder(outDir).file(fileName).newWriter().withWriter {
246
- w ->
247
- w << generatedFileContents
248
- }
249
- }
250
-
251
- void addClassPaths(Project project) {
252
- project.buildscript {
253
- dependencies {
254
- dependenciesConfig.each {
255
- def gradle = (it.value as Object)["android"]["gradle"]
256
- if (!gradle) {
257
- return
258
- }
259
- def customClassPaths = gradle.get("classpaths") as ArrayList<String>
260
- customClassPaths.each { customClassPath ->
261
- this.logLifecycle("Adding classPath ${customClassPath}")
262
- classpath(customClassPath)
263
- }
264
- }
265
- }
266
- }
267
- }
268
-
269
- void addExtraDependencies(Project project) {
270
- project.dependencies {
271
- dependenciesConfig.each {
272
- def dependencies = it.value["android"]["externalDependencies"] as ArrayList<String>
273
- dependencies.each { dependency ->
274
- this.logLifecycle("Registering extra library ${dependency}")
275
- implementation(dependency)
276
- }
277
- }
278
- }
279
- }
280
-
281
- void addAndroidPlugins(Project project) {
282
- dependenciesConfig.each {
283
- def gradleConfig = it.value["android"]["gradle"]
284
- if (!gradleConfig)
285
- return
286
-
287
- def dependencies = gradleConfig["plugins"] as ArrayList<String>
288
- if (!dependencies)
289
- return
290
-
291
- dependencies.each { plugin ->
292
- this.logLifecycle("Adding plugin ${plugin}")
293
- project.getPluginManager().apply(plugin)
294
- }
295
- }
296
- }
297
-
298
- void logDebug(String message) {
299
- this.logger.debug("${this.logPrefix}${message}")
300
- }
301
-
302
- void logLifecycle(String message) {
303
- this.logger.lifecycle("${this.logPrefix}${message}")
304
- }
305
-
306
- void logError(String message) {
307
- this.logger.error("${this.logPrefix}${message}")
308
- }
309
-
310
- /**
311
- * Runs a specified command using Runtime exec() in a specified directory.
312
- * Throws when the command result is empty.
313
- */
314
- String getCommandOutput(String[] command, File directory) {
315
- try {
316
- def output = ""
317
- def cmdProcess = Runtime.getRuntime().exec(command, null, directory)
318
- def bufferedReader = new BufferedReader(new InputStreamReader(cmdProcess.getInputStream()))
319
- def buff = ""
320
- def readBuffer = new StringBuffer()
321
- while ((buff = bufferedReader.readLine()) != null) {
322
- readBuffer.append(buff)
323
- }
324
- output = readBuffer.toString()
325
- if (!output) {
326
- this.logger.error("${logPrefix}Unexpected empty result of running '${command}' command.")
327
- def bufferedErrorReader = new BufferedReader(new InputStreamReader(cmdProcess.getErrorStream()))
328
- def errBuff = ""
329
- def readErrorBuffer = new StringBuffer()
330
- while ((errBuff = bufferedErrorReader.readLine()) != null) {
331
- readErrorBuffer.append(errBuff)
332
- }
333
- throw new Exception(readErrorBuffer.toString())
334
- }
335
- return output
336
- } catch (Exception exception) {
337
- this.logError("Running '${command}' command failed.")
338
- throw exception
339
- }
340
- }
341
-
342
- /**
343
- * Runs a process to call the React Native CLI Config command and parses the output
344
- */
345
- ArrayList<HashMap<String, String>> getReactNativeConfig() {
346
- if (this.reactNativeModules != null) return this.reactNativeModules
347
-
348
- ArrayList<HashMap<String, String>> reactNativeModules = new ArrayList<HashMap<String, String>>()
349
-
350
- String[] reactNativeConfigCommand = [this.cliBinPath, "config"]
351
- def reactNativeConfigOutput = this.getCommandOutput(reactNativeConfigCommand, new File(this.rootDir))
352
-
353
- def json
354
- try {
355
- json = new JsonSlurper().parseText(reactNativeConfigOutput)
356
- } catch (Exception exception) {
357
- throw new Exception("Calling `${reactNativeConfigCommand}` finished with an exception. Error message: ${exception.toString()}. Output: ${reactNativeConfigOutput}");
358
- }
359
- def dependencies = json["dependencies"]
360
- def project = json["project"]["android"]
361
-
362
- if (project == null) {
363
- throw new Exception("React Native CLI failed to determine Android project configuration. This is likely due to misconfiguration. Config output:\n${json.toMapString()}")
364
- }
365
-
366
- dependencies.each { name, value ->
367
- def platformsConfig = value["platforms"];
368
- def androidConfig = platformsConfig["android"]
369
-
370
- if (androidConfig != null && androidConfig["sourceDir"] != null) {
371
- this.logger.info("${logPrefix}Automatically adding native module '${name}'")
372
-
373
- HashMap reactNativeModuleConfig = new HashMap<String, String>()
374
- reactNativeModuleConfig.put("name", name)
375
- reactNativeModuleConfig.put("nameCleansed", name.replaceAll('^@([\\w-]+)/', '$1_'))
376
- reactNativeModuleConfig.put("androidSourceDir", androidConfig["sourceDir"])
377
- reactNativeModuleConfig.put("packageInstance", androidConfig["packageInstance"])
378
- reactNativeModuleConfig.put("packageImportPath", androidConfig["packageImportPath"])
379
- this.logger.trace("${logPrefix}'${name}': ${reactNativeModuleConfig.toMapString()}")
380
-
381
- reactNativeModules.add(reactNativeModuleConfig)
382
- } else {
383
- this.logger.info("${logPrefix}Skipping native module '${name}'")
384
- }
385
- }
386
-
387
- return [reactNativeModules, json["project"]["android"]["packageName"]];
388
- }
389
- }
390
-
391
- def generatedSrcDir = new File(buildDir, "generated/mendix/src/main/java")
392
- def generatedCodeDir = new File(generatedSrcDir, generatedFilePackage.replace('.', '/'))
393
-
394
- def capabilitiesConfig = new File("${rootDir}capabilities-setup-config.json")
395
- def unlinkedDependenciesConfigFile = new File("${rootDir}unlinked-dependency-config.json")
396
- def capabilitiesFile = new File("${rootDir}capabilities.android.json")
397
- def mendixModules = new MendixModules(capabilitiesConfig, unlinkedDependenciesConfigFile, capabilitiesFile, cliBinPath, rootDir, logger, LOG_PREFIX)
398
-
399
- def logLifecycle = { String message -> logger.lifecycle("${LOG_PREFIX}${message}") }
400
-
401
-
402
- ext.applyMendixGradle = { Project project ->
403
- logLifecycle("Registering extra dependencies")
404
- mendixModules.addExtraDependencies(project)
405
-
406
- logLifecycle("Registering plugins")
407
- mendixModules.addAndroidPlugins(project)
408
- task generateMendixDependencies {
409
- doLast {
410
- logLifecycle("Executing Mendix Module Generator")
411
- logLifecycle("App root: ${rootDir}")
412
- logLifecycle("CLI path: ${cliBinPath}")
413
-
414
- logLifecycle("Generating ${mainActivityObserverFileName}")
415
- mendixModules.generateMainActivityObserver(generatedCodeDir, mainActivityObserverFileName, mainActivityObserverTemplate)
416
-
417
- logLifecycle("Generating ${mendixPackageListFileName}")
418
- mendixModules.generateMendixPackageList(generatedCodeDir, mendixPackageListFileName, mendixPackageListTemplate)
419
- }
420
- }
421
-
422
- preBuild.dependsOn generateMendixDependencies
423
-
424
- android {
425
- sourceSets {
426
- main {
427
- java {
428
- srcDirs += generatedSrcDir
429
- }
430
- }
431
- }
432
- }
433
- }
434
-
435
- ext.applyMendixClassPaths = { Project project ->
436
- logLifecycle("Registering class paths")
437
- mendixModules.addClassPaths(project)
438
- }