Skip to content

Failed to create a new MMKV instance: The native MMKV Module could not be found. #491

@MOHAMED-LAAGUILI

Description

@MOHAMED-LAAGUILI

Failed to create a new MMKV instance: The native MMKV Module could not be found. * Make sure react-native-mmkv is correctly autolinked

It's also telling me I have new Architecture enabled, so it requires react-native-mmkv to be v 3.x.x
if i want to use the old arch i disabled newArch to false and down graded mmkv to v 2.x.x
still same error on android
im using expo
heres my config files @tlebeitsuk @flexbox @ahmedouvic @mo-mughrabi @ryamazaki any help guys is appreciated

package.json

{
  "name": "timetracker",
  "version": "1.0.0",
  "private": true,
  "packageManager": "[email protected]",
  "main": "expo-router/entry",
  "scripts": {
    "start": "cross-env EXPO_NO_DOTENV=1 expo start",
    "prebuild": "cross-env EXPO_NO_DOTENV=1 pnpm expo prebuild",
    "android": "cross-env EXPO_NO_DOTENV=1 expo run:android",
    "ios": "cross-env EXPO_NO_DOTENV=1 expo run:ios",
    "web": "cross-env EXPO_NO_DOTENV=1 expo start --web",
    "xcode": "xed -b ios",
    "doctor": "npx expo-doctor@latest",
    "preinstall": "npx only-allow pnpm",
    "start:staging": "cross-env APP_ENV=staging pnpm run start",
    "prebuild:staging": "cross-env APP_ENV=staging pnpm run prebuild",
    "prebuild:development": "cross-env APP_ENV=development pnpm run prebuild",
    "android:staging": "cross-env APP_ENV=staging pnpm run android",
    "ios:staging": "cross-env APP_ENV=staging pnpm run ios",
    "start:production": "cross-env APP_ENV=production pnpm run start",
    "prebuild:production": "cross-env APP_ENV=production pnpm run prebuild",
    "android:production": "cross-env APP_ENV=production pnpm run android",
    "ios:production": "cross-env APP_ENV=production pnpm run ios",
    "build:development:ios": "cross-env APP_ENV=development EXPO_NO_DOTENV=1 eas build --profile development --platform ios",
    "build:development:android": "cross-env APP_ENV=development EXPO_NO_DOTENV=1 eas build --profile development --platform android--clear-cache",
    "build:staging:ios": "cross-env APP_ENV=staging EXPO_NO_DOTENV=1 eas build --profile staging --platform ios",
    "build:staging:android": "cross-env APP_ENV=staging EXPO_NO_DOTENV=1 eas build --profile staging --platform android ",
    "build:production:ios": "cross-env APP_ENV=production EXPO_NO_DOTENV=1 eas build --profile production --platform ios",
    "build:production:android": "cross-env APP_ENV=production EXPO_NO_DOTENV=1 eas build --profile production --platform android --clear-cache",
    "prepare": "husky",
    "app-release": "cross-env SKIP_BRANCH_PROTECTION=true np --no-publish --no-cleanup --no-release-draft",
    "version": "pnpm run prebuild && git add .",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
    "type-check": "tsc  --noemit",
    "lint:translations": "eslint ./src/translations/ --fix --ext .json  ",
    "test": "jest",
    "check-all": "pnpm run lint && pnpm run type-check && pnpm run lint:translations && pnpm run test",
    "test:ci": "pnpm run test --coverage",
    "test:watch": "pnpm run test --watch",
    "install-maestro": "curl -Ls 'https://get.maestro.mobile.dev' | bash",
    "e2e-test": "maestro test .maestro/ -e APP_ID=com.obytes.development"
  },
  "browser": {
    "better-sqlite3": false,
    "@nozbe/watermelondb/adapters/sqlite": false
  },
  "lint-staged": {
    "package.json": [
      "pnpm install --lockfile-only",
      "git add pnpm-lock.yaml"
    ],
    "pnpm-lock.yaml": [
      "git add pnpm-lock.yaml"
    ]
  },
  "dependencies": {
    "@expo/metro-runtime": "^5.0.4",
    "@expo/next-adapter": "^6.0.0",
    "@gorhom/bottom-sheet": "^5.0.5",
    "@hookform/resolvers": "^3.9.0",
    "@nozbe/watermelondb": "^0.28.0",
    "@react-native-async-storage/async-storage": "2.1.2",
    "@react-native-community/netinfo": "11.4.1",
    "@react-navigation/drawer": "^7.3.9",
    "@react-navigation/native": "^7.1.6",
    "@shopify/flash-list": "1.7.6",
    "@shopify/react-native-skia": "2.0.0-next.4",
    "@tanstack/react-query": "^5.85.5",
    "@tanstack/react-table": "^8.21.3",
    "@wuba/react-native-echarts": "1.1.1-alpha.1",
    "app-icon-badge": "^0.1.2",
    "axios": "^1.7.5",
    "better-sqlite3": "^12.2.0",
    "clsx": "^2.1.1",
    "expo": "53.0.23",
    "expo-constants": "~17.1.6",
    "expo-crypto": "^14.1.5",
    "expo-dev-client": "~5.2.4",
    "expo-font": "~13.3.1",
    "expo-image": "~2.4.0",
    "expo-linear-gradient": "~14.1.5",
    "expo-linking": "~7.1.7",
    "expo-localization": "~16.1.6",
    "expo-router": "~5.1.6",
    "expo-splash-screen": "~0.30.10",
    "expo-sqlite": "^15.2.14",
    "expo-status-bar": "~2.2.3",
    "expo-system-ui": "~5.0.11",
    "expo-updates": "^0.28.17",
    "i18next": "^23.14.0",
    "lodash.memoize": "^4.1.2",
    "lottie-react-native": "7.2.2",
    "lucide-react-native": "^0.541.0",
    "moti": "^0.29.0",
    "nativewind": "^4.1.23",
    "next": "^15.5.0",
    "react": "19.0.0",
    "react-dom": "19.0.0",
    "react-error-boundary": "^4.0.13",
    "react-hook-form": "^7.53.0",
    "react-i18next": "^15.0.1",
    "react-icons": "^5.5.0",
    "react-native": "0.79.6",
    "react-native-chart-kit": "^6.12.0",
    "react-native-datatable-component": "^2.1.14",
    "react-native-edge-to-edge": "1.6.0",
    "react-native-flash-message": "^0.4.2",
    "react-native-gesture-handler": "~2.24.0",
    "react-native-gifted-charts": "^1.4.64",
    "react-native-keyboard-controller": "^1.17.4",
    "react-native-mmkv": "^2.12.2",
    "react-native-paper": "^5.14.5",
    "react-native-reanimated": "~3.17.5",
    "react-native-reanimated-table": "^0.0.2",
    "react-native-restart": "0.0.27",
    "react-native-safe-area-context": "5.4.0",
    "react-native-screens": "~4.11.1",
    "react-native-svg": "15.11.2",
    "react-native-table-component": "^1.2.2",
    "react-native-tableview-simple": "^4.4.1",
    "react-native-url-polyfill": "^2.0.0",
    "react-native-web": "~0.20.0",
    "react-query": "^3.39.3",
    "react-query-kit": "^3.3.0",
    "tailwind-rn": "^4.2.0",
    "tailwind-variants": "^0.2.1",
    "uuid": "^13.0.0",
    "zod": "^3.23.8",
    "zustand": "^5.0.5"
  },
  "devDependencies": {
    "@babel/core": "^7.26.0",
    "@babel/helper-validator-identifier": "^7.27.1",
    "@commitlint/cli": "^19.2.2",
    "@commitlint/config-conventional": "^19.2.2",
    "@dev-plugins/react-query": "^0.0.7",
    "@eslint/eslintrc": "^3.3.1",
    "@eslint/js": "^9.28.0",
    "@expo/config": "~11.0.10",
    "@react-native-community/cli": "^20.0.2",
    "@testing-library/jest-dom": "^6.5.0",
    "@testing-library/react-native": "^12.7.2",
    "@types/i18n-js": "^3.8.9",
    "@types/invariant": "^2.2.37",
    "@types/jest": "^29.5.12",
    "@types/lodash.memoize": "^4.1.9",
    "@types/react": "~19.0.14",
    "@typescript-eslint/eslint-plugin": "^8.34.0",
    "@typescript-eslint/parser": "^8.34.0",
    "babel-plugin-module-resolver": "^5.0.2",
    "cross-env": "^7.0.3",
    "dotenv": "^16.4.5",
    "eslint": "^9.28.0",
    "eslint-config-expo": "^9.2.0",
    "eslint-config-prettier": "^10.1.5",
    "eslint-import-resolver-typescript": "^4.4.3",
    "eslint-plugin-i18n-json": "^4.0.1",
    "eslint-plugin-import": "^2.31.0",
    "eslint-plugin-prettier": "^5.4.1",
    "eslint-plugin-react-compiler": "19.1.0-rc.2",
    "eslint-plugin-simple-import-sort": "^12.1.1",
    "eslint-plugin-tailwindcss": "^3.18.0",
    "eslint-plugin-testing-library": "^7.5.2",
    "eslint-plugin-unicorn": "^59.0.1",
    "eslint-plugin-unused-imports": "^4.1.4",
    "husky": "^9.1.5",
    "jest": "^29.7.0",
    "jest-environment-jsdom": "^29.7.0",
    "jest-expo": "~53.0.10",
    "jest-junit": "^16.0.0",
    "lint-staged": "^15.2.9",
    "np": "^10.0.7",
    "prettier": "^3.3.3",
    "tailwindcss": "3.4.4",
    "ts-jest": "^29.1.2",
    "typescript": "~5.8.3",
    "typescript-eslint": "^8.34.0"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/user/repo-name.git"
  },
  "expo": {
    "doctor": {
      "reactNativeDirectoryCheck": {
        "listUnknownPackages": false,
        "exclude": [
          "react-native-restart",
          "@nozbe/watermelondb",
          "react-native-chart-kit",
          "react-native-table-component"
        ]
      }
    },
    "install": {
      "exclude": [
        "eslint-config-expo"
      ]
    }
  },
  "osMetadata": {
    "initVersion": "8.0.0"
  }
}

eas.json

{
  "cli": {
    "version": ">= 3.8.1",
    "appVersionSource": "remote"
  },
  "build": {
    "production": {
      "autoIncrement": true,
      "channel": "production",
      "distribution": "store",
      "pnpm": "9.12.3",
      "ios": {
        "image": "latest"
      },
      "android": {
        "buildType": "app-bundle",
        "image": "latest"
      },
      "env": {
        "EXPO_NO_DOTENV": "1",
        "APP_ENV": "production",
        "FLIPPER_DISABLE": "1"
      }
    },
    "staging": {
      "channel": "staging",
      "distribution": "internal",
      "pnpm": "9.12.3",
      "ios": {
        "image": "latest"
      },
      "android": {
        "buildType": "apk",
        "image": "latest"
      },
      "env": {
        "APP_ENV": "staging",
        "EXPO_NO_DOTENV": "1",
        "FLIPPER_DISABLE": "1"
      }
    },
    "development": {
      "autoIncrement": true,
      "developmentClient": true,
      "distribution": "internal",
      "pnpm": "9.12.3",
      "ios": {
        "image": "latest"
      },
      "android": {
        "image": "latest"
      },
      "env": {
        "APP_ENV": "development",
        "EXPO_NO_DOTENV": "1"
      }
    },
    "simulator": {
      "pnpm": "9.12.3",
      "ios": {
        "simulator": true,
        "image": "latest"
      },
      "android": {
        "image": "latest"
      },
      "env": {
        "APP_ENV": "development",
        "EXPO_NO_DOTENV": "1"
      }
    }
  },
  "submit": {
    "production": {}
  }
}

app.config.ts

import type { ConfigContext, ExpoConfig } from '@expo/config';
import type { AppIconBadgeConfig } from 'app-icon-badge/types';

import { ClientEnv, Env } from './env';

const appIconBadgeConfig: AppIconBadgeConfig = {
  enabled: Env.APP_ENV !== 'production',
  badges: [
    {
      text: Env.APP_ENV,
      type: 'banner',
      color: 'white',
    },
    {
      text: Env.VERSION.toString(),
      type: 'ribbon',
      color: 'white',
    },
  ],
};

const getBaseConfig = (config: any) => ({
  ...config,
  name: Env.NAME,
  description: `${Env.NAME} Mobile App for time tracking on projects`,
  owner: Env.EXPO_ACCOUNT_OWNER,
  scheme: Env.SCHEME,
  slug: Env.SLUG,
  version: Env.VERSION.toString(),
  orientation: 'portrait',
  icon: './assets/icon-new.png',
  userInterfaceStyle: 'automatic',
  newArchEnabled: false,
  experiments: {
    typedRoutes: true,
  },
  updates: {
    fallbackToCacheTimeout: 0,
  },
  assetBundlePatterns: ['**/*'],
});

const getPlatformConfig = () => ({
  ios: {
    supportsTablet: true,
    bundleIdentifier: Env.BUNDLE_ID,
    infoPlist: {
      ITSAppUsesNonExemptEncryption: false,
    },
  },
  android: {
    adaptiveIcon: {
      foregroundImage: './assets/adaptive-icon-new.png',
      backgroundColor: '#FFFFFF',
    },
    package: Env.PACKAGE,
  },
  web: {
    favicon: './assets/favicon-new.png',
    bundler: 'metro',
  },
});

const getPlugins = () => [
  [
    'expo-splash-screen',
    {
      backgroundColor: '#FFFFFF',
      image: './assets/splash-icon-new.png',
      imageWidth: 150,
    },
  ],
  [
    'expo-font',
    {
      fonts: ['./assets/fonts/Inter.ttf'],
    },
  ],
  'expo-localization',
  'expo-router',
  ['app-icon-badge', appIconBadgeConfig],
  ['react-native-edge-to-edge'],
];

export default ({ config }: ConfigContext): ExpoConfig => ({
  ...getBaseConfig(config),
  ...getPlatformConfig(),
  plugins: getPlugins(),
  extra: {
    ...ClientEnv,
    eas: {
      projectId: Env.EAS_PROJECT_ID,
    },
  },
});

storage.ts

import { MMKV } from 'react-native-mmkv';

export const storage = new MMKV({
  id: `user-time-tracker-storage`,
});

/*
import { MMKV, Mode } from 'react-native-mmkv'

export const storage = new MMKV({
  id: `user-${userId}-storage`,
  path: `${USER_DIRECTORY}/storage`,
  encryptionKey: 'hunter2',
  mode: Mode.MULTI_PROCESS,
  readOnly: false
})
 */
export function getItem<T>(key: string): T | null {
  const value = storage.getString(key);
  return value ? JSON.parse(value) || null : null;
}

export async function setItem<T>(key: string, value: T) {
  storage.set(key, JSON.stringify(value));
}

export async function removeItem(key: string) {
  storage.delete(key);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions