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.initialize() 报 Error message:Cannot read property initialize of undefined #1456

Closed
xlg opened this issue Dec 16, 2024 · 6 comments

Comments

@xlg
Copy link

xlg commented Dec 16, 2024

1、"@tencent/mmkv": "^2.0.1"

2、onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
MMKV.initialize(this.context.getApplicationContext(), MMKVLogLevel.LevelInfo)
}

3、
Error name:TypeError
Error message:Cannot read property initialize of undefined
Stacktrace:
at initializeWithPath (oh_modules/.ohpm/@Tencent[email protected]/oh_modules/@tencent/mmkv/src/main/ets/utils/MMKV.ets:86:26)
at initialize (oh_modules/.ohpm/@Tencent[email protected]/oh_modules/@tencent/mmkv/src/main/ets/utils/MMKV.ets:70:16)
at onCreate (entry/src/main/ets/entryability/EntryAbility.ets:11:5)

@lingol
Copy link
Collaborator

lingol commented Dec 16, 2024

It's a typically NAPI error due to failing to load the native library limmkv.so.

You check out Hilog/FaultLog and find out what went wrong.

@lingol
Copy link
Collaborator

lingol commented Dec 16, 2024

Did you turn on obfuscation? Have you followed the temp solution here?

#1385 (comment)

@xlg
Copy link
Author

xlg commented Dec 16, 2024

我的步骤非常简单,新建了一个空的工程 并引用"@tencent/mmkv": "^2.0.1",在onCreate里进行初始化MMKV.initialize(),然后运行到模拟器上就报错了。混淆应该是没有开启的 "buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": false,
"files": [
"./obfuscation-rules.txt"
]
}
}
}
},
],

{
"modelVersion": "5.0.0",
"description": "Please describe the basic information.",
"dependencies": {},
"devDependencies": {
"@tencent/mmkv": "^2.0.1",
// "@ohos/hypium": "1.0.19",
// "@ohos/hamock": "1.0.0"
},
"dynamicDependencies": {}
}
所以现在就很奇怪,也不知道哪里引起的
image

@lingol
Copy link
Collaborator

lingol commented Dec 16, 2024

Does your simulator have OHOS API level 12 or above? aka HarmonyOS NEXT.

@lingol
Copy link
Collaborator

lingol commented Dec 16, 2024

One more thing, MMKV does not support x86 with 32-bit arch, only x86-64 is supported.

@xlg
Copy link
Author

xlg commented Dec 16, 2024

不好意思,是引用的放错位置,应该放置dependencies下,而不是devDependencies。

@xlg xlg closed this as completed Dec 16, 2024
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

2 participants