Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MMKV with Expo #261

Closed
danilo-vieira opened this issue Dec 21, 2021 · 12 comments
Closed

MMKV with Expo #261

danilo-vieira opened this issue Dec 21, 2021 · 12 comments

Comments

@danilo-vieira
Copy link

danilo-vieira commented Dec 21, 2021

Im trying to setup mmkv in my Expo project but still with the following error:
Failed to create a new MMKV instance, the native initializer function does not exists

What i do according #157:

  • Install react-native-mmkv v1.3.2;
  • Create a file react-native-mmkv-plugin.js at the project root;
  • Paste this gist content inside react-native-mmkv-plugin.js;
  • (Not sure this step is right) Create an app.config.js file and paste the following code according expo guide:
module.exports = {
  name: "my app",
  plugins: ["./react-native-mmkv-plugin"]
}
  • Run expo prebuild command and it shows:
What would you like your Android package name to be? ... com.app.myapp

Cannot automatically write to dynamic config at: app.config.js
Please add the following to your Expo config

{
  "android": {
    "package": "com.app.myapp"
  }
}

After that, i run the app and get the same error.

@intergalacticspacehighway
Copy link

Can you try this solution?
If it doesn't work, I would recommend to check this guide and compare it with your android/ folder which is generated on running the prebuild command. The mmkv expo plugin is trying to implement installation instructions.

@mrousavy
Copy link
Owner

Can you share the ADB logs?

@junaiddarajat
Copy link

I was having the same issue but got it to work; when you say you 'run' the application, how are you doing that?

This command works for me:
npm i && expo prebuild --clean && expo run:android -d

You can omit out npm install, but do run a prebuild with clean switch, this seems to be running for me, but then now I'm facing an issue mentioned here

@hirbod
Copy link
Contributor

hirbod commented Jan 5, 2022

MMKV 1.6.2 is working flawlessly on Expo SDK 44 with this config plugin:
https://gist.github.com/axeldelafosse/8cd7274501180257ae4951a0dc8759c2

Running prebuild with --clean is nearly mandatory as soon as you have couple of config plugins. Most of them apply the patches once and fail once the patches have been done. So always clean when you install a new config-plugin.

@danilo-vieira
Copy link
Author

danilo-vieira commented Jan 5, 2022

@hirbod i tryed to use MMKV 1.6.2, create a file react-native-mmkv-plugin.js at the project root and paste this content: https://gist.github.com/axeldelafosse/8cd7274501180257ae4951a0dc8759c2

Change app.json to this:

{
  "expo": {
    "name": "mmkvtest",
    "slug": "mmkvtest",
    "version": "1.0.0",
    "assetBundlePatterns": [
      "**/*"
    ],
    "android": {
      "package": "com.danilovieira.mmkvtest"
    } // this is added after run `expo run:android`
  },
  "name": "mmkvtest",
  "plugins": [
    "./react-native-mmkv-plugin"
  ] // add 'plugins' line
}

When i run expo prebuild --clean and then expo run:android i got this log:

> Configure project :react-native-mmkv
MMKV: node_modules/ found at: C:\Users\danil\codes\testing\mmkvtest\node_modules
Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Observed package id 'extras;google;Android_Emulator_Hypervisor_Driver' in inconsistent location 'C:\Android\Sdk\extras\google\Android_Emulator_Hypervisor_Driver-2' (Expected 'C:\Android\Sdk\extras\google\Android_Emulator_Hypervisor_Driver')
(node:17064) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at C:\Users\danil\codes\testing\mmkvtest\node_modules\tslib\package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)

> Task :expo-file-system:processDebugManifest
C:\Users\danil\codes\testing\mmkvtest\node_modules\expo-file-system\android\src\main\AndroidManifest.xml:8:9-10:20 Warning:
        provider#expo.modules.filesystem.FileSystemFileProvider@android:authorities was tagged at AndroidManifest.xml:8 to replace other declarations but no other declaration present

> Task :app:processDebugMainManifest
C:\Users\danil\codes\testing\mmkvtest\android\app\src\debug\AndroidManifest.xml:25:9-34:20 Warning:
        provider#expo.modules.filesystem.FileSystemFileProvider@android:authorities was tagged at AndroidManifest.xml:25 to replace other declarations but no other declaration present

> Task :expo-modules-core:compileDebugKotlin
w: C:\Users\danil\codes\testing\mmkvtest\node_modules\expo-modules-core\android\src\main\java\expo\modules\kotlin\records\RecordTypeConverter.kt: (38, 13): Name shadowed: value

> Task :expo-modules-core:compileDebugJavaWithJavac
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :react-native-mmkv:downloadBoost
Download https://github.com/react-native-community/boost-for-react-native/releases/download/v1.63.0-0/boost_1_63_0.tar.gz

> Task :react-native-mmkv:downloadDoubleConversion
Download https://github.com/google/double-conversion/archive/v1.1.6.tar.gz

> Task :react-native-mmkv:downloadFolly
Download https://github.com/facebook/folly/archive/v2020.01.13.00.tar.gz

> Task :react-native-mmkv:downloadGlog
Download https://github.com/google/glog/archive/v0.3.5.tar.gz

> Task :react-native-mmkv:generateJsonModelDebug FAILED

FAILURE: Build failed with an exception.                                                       

* What went wrong:
Execution failed for task ':react-native-mmkv:generateJsonModelDebug'.
> C:\Users\danil\codes\testing\mmkvtest\node_modules\react-native-mmkv\android\CMakeLists.txt : C/C++ debug|armeabi-v7a : CMake Error at C:\Users\danil\codes\testing\mmkvtest\node_modules\react-native-mmkv\android\CMakeLists.txt:22 (add_library):
    Syntax error in cmake code when parsing string

      C:\Users\danil\codes\testing\mmkvtest\node_modules/react-native/ReactCommon/jsi/jsi/jsi.cpp

    Invalid character escape '\U'.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.    
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 3m 1s
165 actionable tasks: 165 executed
C:\Users\danil\codes\testing\mmkvtest\android\gradlew.bat exited with non-zero code: 1
Error: C:\Users\danil\codes\testing\mmkvtest\android\gradlew.bat exited with non-zero code: 1
    at ChildProcess.completionListener (C:\Users\danil\AppData\Local\Yarn\Data\global\node_modules\@expo\spawn-async\src\spawnAsync.ts:65:13)
    at Object.onceWrapper (node:events:510:26)
    at ChildProcess.emit (node:events:390:28)
    at ChildProcess.cp.emit (C:\Users\danil\AppData\Local\Yarn\Data\global\node_modules\cross-spawn\lib\enoent.js:34:29)
    at maybeClose (node:internal/child_process:1064:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
    ...
    at spawnAsync (C:\Users\danil\AppData\Local\Yarn\Data\global\node_modules\@expo\spawn-async\src\spawnAsync.ts:26:19)
    at spawnGradleAsync (C:\Users\danil\AppData\Local\Yarn\Data\global\node_modules\expo-cli\src\commands\run\android\spawnGradleAsync.ts:83:18)
    at assembleAsync (C:\Users\danil\AppData\Local\Yarn\Data\global\node_modules\expo-cli\src\commands\run\android\spawnGradleAsync.ts:57:16)
    at actionAsync (C:\Users\danil\AppData\Local\Yarn\Data\global\node_modules\expo-cli\src\commands\run\android\runAndroid.ts:143:9)

@mrousavy sorry for delay

Am i doing something wrong?

@danilo-vieira
Copy link
Author

danilo-vieira commented Jan 5, 2022

Can you try this solution? If it doesn't work, I would recommend to check this guide and compare it with your android/ folder which is generated on running the prebuild command. The mmkv expo plugin is trying to implement installation instructions.

@intergalacticspacehighway according this comment it's working now but im still facering an error (above).

@hirbod
Copy link
Contributor

hirbod commented Jan 5, 2022

@danilo-vieira kinda smells like windows weirdness. I am on Mac, not facing this issue :/

@danilo-vieira
Copy link
Author

@hirbod lol so im doing it right?

@danilo-vieira
Copy link
Author

Thank you guys! The issue was only on Windows and this solution works for me. Thanks @hirbod

@rupakhetibinit
Copy link

rupakhetibinit commented Jan 6, 2022

I just ejected from expo and tried building this but get this error

* What went wrong:
Execution failed for task ':react-native-mmkv:generateJsonModelDebug'.
> D:\Binit Things\Programming\bare-react-native\recipetohome\node_modules\react-native-mmkv\android\CMakeLists.txt : C/C++ debug|armeabi-v7a : CMake Error at D:\Binit Things\Programming\bare-react-native\recipetohome\node_modules\react-native-mmkv\android\CMakeLists.txt:22 (add_library):
    Syntax error in cmake code when parsing string

      D:\Binit Things\Programming\bare-react-native\recipetohome\node_modules/react-native/ReactCommon/jsi/jsi/jsi.cpp

    Invalid character escape '\B'.

Edit: I tried expo prebuild as well but it still shows this error

@intergalacticspacehighway

@rupakhetibinit this looks like some kind of path issue on Windows. I don't have a windows system to test. This might sound weird but can you move your project to a folder that doesn't have spaces or try renaming init Things folder to init-things.

@rupakhetibinit
Copy link

@intergalacticspacehighway Unfortunately didn't work. I tried moving it to a location with no spaces in the file path yet still gives me this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants