Skip to content

Commit

Permalink
make ExcludeArchs, optional
Browse files Browse the repository at this point in the history
  • Loading branch information
killerchip committed Jan 25, 2024
1 parent 56812e0 commit 5532fc4
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 30 deletions.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,37 @@ In your app.json `plugins` array:
}
```

Note: This plugin enables by default the watermelon JSI interface in Android.
## JSI support for Android

This plugin installs automatically JSI support for Android builds, as per [WatermelonDB for Android instructions](https://watermelondb.dev/docs/Installation#android-react-native).
If you wish to disable JSI support during build you may add the option in config plugin:
```json
[
"@morrowdigital/watermelondb-expo-plugin",
{ "disableJSI": true }
]
```

## Build errors with M1 architectures for simulators

There have been errors building with M1 architectures for simulators on iOS, with Error:
```
No such module 'ExpoModulesCore'
```
See these discussions:
* [https://github.com/morrowdigital/watermelondb-expo-plugin/issues/20](https://github.com/morrowdigital/watermelondb-expo-plugin/issues/20)
* [https://github.com/morrowdigital/watermelondb-expo-plugin/issues/34](https://github.com/morrowdigital/watermelondb-expo-plugin/issues/34)
* [https://github.com/facebook/react-native/issues/32704#issuecomment-1174458011](https://github.com/facebook/react-native/issues/32704#issuecomment-1174458011)

This plugin will NOT add the `arm64` in `Exlcuded_Archs`, in SDK 50 builds:
```
'"EXCLUDED_ARCHS[sdk=iphonesimulator*]"'] = '"arm64"'
```

If you wish to add the above in configuration, you can add it with option:
```json
[
"@morrowdigital/watermelondb-expo-plugin",
{ "excludeSimArch": true }
]
```
7 changes: 6 additions & 1 deletion build/withWatermelon.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ExpoConfig } from "@expo/config-types";
export declare function withSDK50(config: ExpoConfig): ExpoConfig;
type Options = {
disableJsi?: boolean;
databases?: string[];
excludeSimArch?: boolean;
};
export declare function withSDK50(options: Options): (config: ExpoConfig) => ExpoConfig;
declare const _default: (config: any, options: any) => any;
export default _default;
31 changes: 19 additions & 12 deletions build/withWatermelon.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,30 @@ const withWatermelonDBAndroidJSI = (config, options) => {
return mainApplication(settingGradle(buildGradle(config)));
};
// @ts-ignore
function withSDK50(config) {
// Android
let currentConfig = settingGradle(config);
currentConfig = buildGradle(currentConfig);
currentConfig = proGuardRules(currentConfig);
currentConfig = mainApplication(currentConfig);
// iOS
currentConfig = setWmelonBridgingHeader(currentConfig);
currentConfig = withCocoaPods(currentConfig);
currentConfig = withExcludedSimulatorArchitectures(currentConfig);
return currentConfig;
function withSDK50(options) {
return (config) => {
let currentConfig = config;
// Android
if (options?.disableJsi !== true) {
currentConfig = settingGradle(config);
currentConfig = buildGradle(currentConfig);
currentConfig = proGuardRules(currentConfig);
currentConfig = mainApplication(currentConfig);
}
// iOS
currentConfig = setWmelonBridgingHeader(currentConfig);
currentConfig = withCocoaPods(currentConfig);
if (options?.excludeSimArch === true) {
currentConfig = withExcludedSimulatorArchitectures(currentConfig);
}
return currentConfig;
};
}
exports.withSDK50 = withSDK50;
// @ts-ignore
exports.default = (config, options) => {
if (config.sdkVersion >= '50.0.0') {
return withSDK50(config);
return withSDK50(options)(config);
}
;
if (config.sdkVersion < '50.0.0') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@morrowdigital/watermelondb-expo-plugin",
"version": "2.3.0-beta1",
"version": "2.3.0-beta2",
"main": "build/withWatermelon.js",
"types": "build/withWatermelon.d.ts",
"license": "MIT",
Expand Down
40 changes: 25 additions & 15 deletions src/withWatermelon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const fs = filesys.promises;
type Options = {
disableJsi?: boolean;
databases?: string[];
excludeSimArch?: boolean;
}

/**
Expand Down Expand Up @@ -144,7 +145,7 @@ function proGuardRules(config: ExpoConfig): ExpoConfig {
/**
* Platform: Android
* */
function addFlipperDb(config: ExportedConfigWithProps, databases: string[]) {
function addFlipperDb(config: ExpoConfig, databases: string[]) {
return withDangerousMod(config, [
"android",
async (config) => {
Expand Down Expand Up @@ -202,7 +203,7 @@ import java.util.ArrayList;`,

return config;
},
]);
]) as ExpoConfig;
}

function setWmelonBridgingHeader(config: ExpoConfig): ExpoConfig {
Expand Down Expand Up @@ -384,32 +385,41 @@ const withWatermelonDBAndroidJSI = (config: ExpoConfig, options: Options) => {
return mainApplication(settingGradle(buildGradle(config)));
};


// @ts-ignore
export function withSDK50(config: ExpoConfig): ExpoConfig {
// Android
let currentConfig = settingGradle(config);
currentConfig = buildGradle(currentConfig);
currentConfig = proGuardRules(currentConfig);
currentConfig = mainApplication(currentConfig);
// iOS
currentConfig = setWmelonBridgingHeader(currentConfig);
currentConfig = withCocoaPods(currentConfig);
currentConfig = withExcludedSimulatorArchitectures(currentConfig);
return currentConfig as ExpoConfig;
export function withSDK50(options: Options) {
return (config: ExpoConfig): ExpoConfig => {
let currentConfig: ExpoConfig = config;
// Android
if (options?.disableJsi !== true) {
currentConfig = settingGradle(config);
currentConfig = buildGradle(currentConfig);
currentConfig = proGuardRules(currentConfig);
currentConfig = mainApplication(currentConfig);
}

// iOS
currentConfig = setWmelonBridgingHeader(currentConfig);
currentConfig = withCocoaPods(currentConfig);
if (options?.excludeSimArch === true) {
currentConfig = withExcludedSimulatorArchitectures(currentConfig);
}

return currentConfig as ExpoConfig;
}
}

// @ts-ignore
export default (config, options) => {
if (config.sdkVersion >= '50.0.0') {
return withSDK50(config);
return withSDK50(options)(config);
};

if (config.sdkVersion < '50.0.0') {
config = setAndroidMainApplication(config);
config = addFlipperDb(config, options?.databases ?? []);
config = withWatermelonDBAndroidJSI(setWmelonBridgingHeader(config), options);
config = withCocoaPods(config);

config = withExcludedSimulatorArchitectures(config);
}

Expand Down

0 comments on commit 5532fc4

Please sign in to comment.