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 does not correctly autolink #37

Closed
mrousavy opened this issue Mar 22, 2021 · 6 comments
Closed

MMKV does not correctly autolink #37

mrousavy opened this issue Mar 22, 2021 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@mrousavy
Copy link
Owner

MMKV does not show up in the left side of Android Studio (dependencies), and can therefore not be imported (as shown in the installation step in the readme).

The current workaround for this is:

  1. Add this to settings.gradle:
include ':react-native-mmkv'
project(':react-native-mmkv').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mmkv/android/')
  1. Add this to build.gradle (in app/), inside of dependencies (under implementation("com.facebook.react:react-native:+")):
  implementation project(':react-native-mmkv')

I am not sure what is missing from my configuration, but this will likely change soon when TurboModules will be released (maybe RN 0.65?), because I will rewrite the library - no extra installation steps will be needed then!

@mydesweb
Copy link

I also had to import com.facebook.react.bridge.JSIModulePackage; in MainApplication.java to make it work on android

@mrousavy
Copy link
Owner Author

mrousavy commented Aug 9, 2021

I believe this works with v1.2.5 now, let me know if anyone can confirm

@GnApollo
Copy link


2021-08-20 16:15:15.292 31642-31690/com.testapp D/SoLoader: Not resolving dependencies for libjscexecutor.so
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err: java.lang.UnsatisfiedLinkError: dlopen failed: library "libjsc.so" not found
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at java.lang.Runtime.load0(Runtime.java:938)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at java.lang.System.load(System.java:1631)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.facebook.soloader.SoLoader$1.load(SoLoader.java:405)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.facebook.soloader.DirectorySoSource.loadLibraryFrom(DirectorySoSource.java:77)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.facebook.soloader.DirectorySoSource.loadLibrary(DirectorySoSource.java:50)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.facebook.soloader.ApplicationSoSource.loadLibrary(ApplicationSoSource.java:89)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:860)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.facebook.soloader.SoLoader.loadLibraryBySoNameImpl(SoLoader.java:740)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:654)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:634)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:582)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.swmansion.reanimated.NativeProxy.getDefaultJSExecutorFactory(NativeProxy.java:98)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.swmansion.reanimated.NativeProxy.<init>(NativeProxy.java:81)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.swmansion.reanimated.NodesManager.initWithContext(NodesManager.java:127)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.swmansion.reanimated.ReanimatedJSIModulePackage.getJSIModules(ReanimatedJSIModulePackage.java:18)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.testapp.MMKVJSIPackage.getJSIModules(MMKVJSIPackage.java:16)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1265)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.facebook.react.ReactInstanceManager.access$1100(ReactInstanceManager.java:131)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1023)
2021-08-20 16:15:15.294 31642-31690/com.testapp W/System.err:     at java.lang.Thread.run(Thread.java:919)
2021-08-20 16:15:15.294 31642-31690/com.testapp E/SoLoader: couldn't find DSO to load: libjscexecutor.so caused by: dlopen failed: library "libjsc.so" not found result: 0
2021-08-20 16:15:15.296 31642-31690/com.testapp D/SoLoader: About to load: libturbomodulejsijni.so
2021-08-20 16:15:15.297 31642-31690/com.testapp D/SoLoader: libturbomodulejsijni.so not found on /data/data/com.testapp/lib-main
2021-08-20 16:15:15.297 31642-31690/com.testapp D/SoLoader: libturbomodulejsijni.so found on /data/app/com.testapp-6na_3ySNovN7Y7TsQ7pyLw==/lib/arm64
2021-08-20 16:15:15.297 31642-31690/com.testapp D/SoLoader: Not resolving dependencies for libturbomodulejsijni.so
2021-08-20 16:15:15.299 31642-31690/com.testapp D/SoLoader: Loaded: libturbomodulejsijni.so
2021-08-20 16:15:17.302 31642-31690/com.testapp I/ReactNativeJNI: Inspector::Inspector transitioning to initial state RunningDetached
2021-08-20 16:15:17.305 31642-31690/com.testapp I/MMKV: <MMKV.cpp:156::initialize> version v1.2.7 page size:4096
2021-08-20 16:15:17.305 31642-31690/com.testapp I/MMKV: <MMKV.cpp:167::initialize> armv8 AES instructions is supported
2021-08-20 16:15:17.305 31642-31690/com.testapp I/MMKV: <MMKV.cpp:175::initialize> armv8 CRC32 instructions is supported
2021-08-20 16:15:17.305 31642-31690/com.testapp I/MMKV: <MMKV.cpp:198::initializeMMKV> root dir: /data/user/0/com.testapp/files/mmkv
2021-08-20 16:15:17.306 31642-31690/com.testapp A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x2 in tid 31690 (create_react_co), pid 31642 (onvergeagentapp)
2021-08-20 16:15:18.575 31642-31642/com.testapp W/ActivityThread: SCHED: com.testapp/.MainActivity [74, r=186ms, a=63ms, w=6242ms]

@GnApollo
Copy link

MMKVJSIPackage.java

package com.testapp;

import com.facebook.react.bridge.JSIModuleSpec;
import com.facebook.react.bridge.JavaScriptContextHolder;
import com.facebook.react.bridge.ReactApplicationContext;
import com.swmansion.reanimated.ReanimatedJSIModulePackage;
import com.facebook.react.bridge.JSIModulePackage;
import com.reactnativemmkv.MmkvModule;

import java.util.Collections;
import java.util.List;

public class MMKVJSIPackage extends ReanimatedJSIModulePackage {
    @Override
    public List<JSIModuleSpec> getJSIModules(ReactApplicationContext reactApplicationContext, JavaScriptContextHolder jsContext) {
        super.getJSIModules(reactApplicationContext, jsContext);
        MmkvModule.install(jsContext, reactApplicationContext.getFilesDir().getAbsolutePath() + "/mmkv");
        return Collections.emptyList();
    }
}

@GnApollo
Copy link

im using sir the latest version "react-native-mmkv": "^1.2.5",

@mrousavy
Copy link
Owner Author

This should work with 1.3.0 and above, so you can revert those two steps mentioned in my original comment. Let me know if you are still having issues autolinking MMKV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants