I am trying to integrate an SDK from the company TUYA (Smart Life App SDK) into a Flutter project as a native SDK using Java. I followed the steps that are posted on the official website, with some adaptations to make it work in a Flutter project. When all the integration is done, build of the app is ok and I try to Initialize the SDK it shows a FATAL EXCEPTION: main

Launching lib\main.dart on sdk gphone64 x86 64 in debug mode... lib\main.dart:1

√ Built build\app\outputs\flutter-apk\app-debug.apk.

E/AndroidRuntime(12996): FATAL EXCEPTION: main E/AndroidRuntime(12996): Process: com.example.project, PID: 12996 E/AndroidRuntime(12996): java.lang.UnsatisfiedLinkError: No implementation found for java.lang.Object com.tuya.smart.security.jni.SecureNativeApi.doCommandNative(android.content.Context, int, byte[], byte[], boolean, boolean) (tried Java_com_tuya_smart_security_jni_SecureNativeApi_doCommandNative and Java_com_tuya_smart_security_jni_SecureNativeApi_doCommandNative__Landroid_content_Context_2I_3B_3BZZ) E/AndroidRuntime(12996): at com.tuya.smart.security.jni.SecureNativeApi.doCommandNative(Native Method) E/AndroidRuntime(12996): at com.tuya.smart.security.jni.JNICLibrary.doCommandNative(JNICLibrary.java:55) E/AndroidRuntime(12996): at com.tuya.sdk.network.TuyaNetworkSecurity.initJNI(TuyaNetworkSecurity.java:9) E/AndroidRuntime(12996): at com.tuya.smart.android.network.TuyaSmartNetWork.initialize(TuyaSmartNetWork.java:35) E/AndroidRuntime(12996): at com.tuya.smart.sdk.TuyaSdk.initTuyaData(TuyaSdk.java:81) E/AndroidRuntime(12996): at com.tuya.smart.sdk.TuyaSdk.init(TuyaSdk.java:220) E/AndroidRuntime(12996): at com.tuya.smart.sdk.TuyaSdk.init(TuyaSdk.java:60) E/AndroidRuntime(12996): at com.tuya.smart.home.sdk.TuyaHomeSdk.init(TuyaHomeSdk.java:107) E/AndroidRuntime(12996): at com.example.project.FTuyaSmartApp.onCreate(FTuyaSmartApp.java:14) E/AndroidRuntime(12996): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1211) E/AndroidRuntime(12996): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6725) E/AndroidRuntime(12996): at android.app.ActivityThread.access$1500(ActivityThread.java:247) E/AndroidRuntime(12996): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053) E/AndroidRuntime(12996): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime(12996): at android.os.Looper.loopOnce(Looper.java:201) E/AndroidRuntime(12996): at android.os.Looper.loop(Looper.java:288) E/AndroidRuntime(12996): at android.app.ActivityThread.main(ActivityThread.java:7839) E/AndroidRuntime(12996): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(12996): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) E/AndroidRuntime(12996): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

If anyone has had a similar problem, please let me know, because I really don't know how to solve this problem.

1

There are 1 best solutions below

2
On

The Tuya Smart Life SDK doesn't work on x86 android, as they call platform specific native libraries that they don't package for x86.

From the fast integration document:

App SDK v3.10.0 and earlier only support armeabi-v7a. App SDK v3.11.0 and later have integrated armeabi-v7a and arm64-v8a. If you have added .so libraries to the project, you must remove them and only use the library included in the SDK.

So you'll need to set up an emulated ARM device in AVD manager using an arm64 image.

However, note the normal QEMU2 based emulator only runs ARM images where the API < 27 (i.e. nougat), and very slowly.

Thankfully - Google have added partial arm emulation (i.e. most of the OS runs under x86, but apps compiled for arm run under emulation) to x86_64 versions >= 11. Source: Google blog

Tested it out, and the Tuya API works OK on Android 11.0 x86_64.

Getting flutter to build for arm rather than x86_64 as part of regular tooling is harder - I've only tried manually forcing it so far:

flutter build apk --debug --split-per-abi
adb -e install .\build\app\outputs\flutter-apk\app-armeabi-v7a-debug.apk