morrowdigital / watermelondb-expo-plugin

125 stars 30 forks source link

any plans to add jsi support to the plugin ? #4

Closed a-eid closed 11 months ago

a-eid commented 2 years ago

hey, thank you for the plugin, it works with expo 45, you just need to change the kotlin version manually.

I was wondering if you're planning to add the jsi step to the plugin, it looks like it's not yet added / installed.

[šŸ‰] JSI SQLiteAdapter not availableā€¦ falling back to asynchronous operation. This will happen if you're using remote debugger, and may happen if you forgot to recompile native app after WatermelonDB update

Screen Shot 2022-06-14 at 04 13 28
ansh commented 2 years ago

@a-eid How did you change the Kotlin version?

Also, does it work for iOS?

a-eid commented 2 years ago

@ansh

How did you change the Kotlin version?

you need to use expo-build-properties

Also, does it work for iOS?

I think so yes.

ansh commented 2 years ago

@a-eid Are you using expo-dev-client? When I try to build my app with EAS Build, it fails and gives me a bunch of errors.

Also, what Kotlin version did you change it to?

a-eid commented 2 years ago

I don't think I was using expo-dev-client for that project.

I changed kotlin version to 1.6.10.

luccasr73 commented 1 year ago

i will try to add this on next weeks

tom-at-pixel commented 1 year ago

@luccasr73 Have you had a chance to look at this yet? This could greatly improve performance for Android. :-)

rlgo commented 1 year ago
const withWatermelonDBAndroidJSI = (config) => {
  function settingGradle(gradleConfig) {
    return withSettingsGradle(gradleConfig, (mod) => {
      if (!mod.modResults.contents.includes(':watermelondb-jsi')) {
        mod.modResults.contents += `
          include ':watermelondb-jsi'
          project(':watermelondb-jsi').projectDir =
            new File(rootProject.projectDir, '../node_modules/@nozbe/watermelondb/native/android-jsi')
        `;
      }
      return mod;
    });
  }

  function buildGradle(gradleConfig) {
    return withAppBuildGradle(gradleConfig, (mod) => {
      if (
        !mod.modResults.contents.includes("pickFirst '**/libc++_shared.so'")
      ) {
        mod.modResults.contents = mod.modResults.contents.replace(
          'android {',
          `
          android {
            packagingOptions {
               pickFirst '**/libc++_shared.so' 
            }
          `
        );
      }
      if (
        !mod.modResults.contents.includes(
          "implementation project(':watermelondb-jsi')"
        )
      ) {
        mod.modResults.contents = mod.modResults.contents.replace(
          'dependencies {',
          `
          dependencies {
            implementation project(':watermelondb-jsi')
          `
        );
      }
      return mod;
    });
  }

  function mainApplication(mainAppConfig) {
    return withMainApplication(mainAppConfig, (mod) => {
      if (
        !mod.modResults.contents.includes(
          'import com.nozbe.watermelondb.jsi.WatermelonDBJSIPackage;'
        )
      ) {
        mod.modResults.contents = mod.modResults.contents.replace(
          'import com.nozbe.watermelondb.WatermelonDBPackage;',
          `
          import com.nozbe.watermelondb.WatermelonDBPackage;
          import com.nozbe.watermelondb.jsi.WatermelonDBJSIPackage;
          import com.facebook.react.bridge.JSIModulePackage;
        `
        );
      }
      if (
        !mod.modResults.contents.includes('return new WatermelonDBJSIPackage()')
      ) {
        mod.modResults.contents = mod.modResults.contents.replace(
          'new ReactNativeHostWrapper(this, new DefaultReactNativeHost(this) {',
          `
          new ReactNativeHostWrapper(this, new DefaultReactNativeHost(this) {
            @Override
             protected JSIModulePackage getJSIModulePackage() {
               return new WatermelonDBJSIPackage(); 
             }
          `
        );
      }
      return mod;
    });
  }

  return mainApplication(settingGradle(buildGradle(config)));
};

This is how I do it But beware that you might need to change it accordingly if you have multiple JSI packages See the docs for more info https://watermelondb.dev/docs/Installation#android-react-native

rohankm commented 1 year ago
const withWatermelonDBAndroidJSI = (config) => {
  function settingGradle(gradleConfig) {
    return withSettingsGradle(gradleConfig, (mod) => {
      if (!mod.modResults.contents.includes(':watermelondb-jsi')) {
        mod.modResults.contents += `
          include ':watermelondb-jsi'
          project(':watermelondb-jsi').projectDir =
            new File(rootProject.projectDir, '../node_modules/@nozbe/watermelondb/native/android-jsi')
        `;
      }
      return mod;
    });
  }

  function buildGradle(gradleConfig) {
    return withAppBuildGradle(gradleConfig, (mod) => {
      if (
        !mod.modResults.contents.includes("pickFirst '**/libc++_shared.so'")
      ) {
        mod.modResults.contents = mod.modResults.contents.replace(
          'android {',
          `
          android {
            packagingOptions {
               pickFirst '**/libc++_shared.so' 
            }
          `
        );
      }
      if (
        !mod.modResults.contents.includes(
          "implementation project(':watermelondb-jsi')"
        )
      ) {
        mod.modResults.contents = mod.modResults.contents.replace(
          'dependencies {',
          `
          dependencies {
            implementation project(':watermelondb-jsi')
          `
        );
      }
      return mod;
    });
  }

  function mainApplication(mainAppConfig) {
    return withMainApplication(mainAppConfig, (mod) => {
      if (
        !mod.modResults.contents.includes(
          'import com.nozbe.watermelondb.jsi.WatermelonDBJSIPackage;'
        )
      ) {
        mod.modResults.contents = mod.modResults.contents.replace(
          'import com.nozbe.watermelondb.WatermelonDBPackage;',
          `
          import com.nozbe.watermelondb.WatermelonDBPackage;
          import com.nozbe.watermelondb.jsi.WatermelonDBJSIPackage;
          import com.facebook.react.bridge.JSIModulePackage;
        `
        );
      }
      if (
        !mod.modResults.contents.includes('return new WatermelonDBJSIPackage()')
      ) {
        mod.modResults.contents = mod.modResults.contents.replace(
          'new ReactNativeHostWrapper(this, new DefaultReactNativeHost(this) {',
          `
          new ReactNativeHostWrapper(this, new DefaultReactNativeHost(this) {
            @Override
             protected JSIModulePackage getJSIModulePackage() {
               return new WatermelonDBJSIPackage(); 
             }
          `
        );
      }
      return mod;
    });
  }

  return mainApplication(settingGradle(buildGradle(config)));
};

This is how I do it But beware that you might need to change it accordingly if you have multiple JSI packages See the docs for more info https://watermelondb.dev/docs/Installation#android-react-native

hi how to use this code in expo?