tensorflow: TensorFlow Lite in Play Services issue: Cannot initialize interpreter: Error loading TFLite native library
System information
- Android Device information (use
adb shell getprop ro.build.fingerprintif possible): Redmi/thunder_global/thunder:13/TP1A.220624.014/V0.0.0.0.XXXXXXX:user/test-keys - TensorFlow Lite in Play Services SDK version (found in
build.gradle):com.google.android.gms:play-services-tflite-java:16.1.0 - Google Play Services version
(
Settings>Apps>Google Play Services>App details):23.43.13(190400-577232161)
Standalone code to reproduce the issue
`
Task<Void> initializeTask = TfLite.initialize(GlobalHolder.getApplicationContext());
ByteBuffer buffer = ModelManager.getInstance().getModelBuffer();
initializeTask
.addOnSuccessListener(a -> {
interpreter = InterpreterApi.create(buffer,
new InterpreterApi.Options().setRuntime(InterpreterApi.Options.TfLiteRuntime.FROM_SYSTEM_ONLY));
MLog.i(TAG, "load model success");
})
.addOnFailureListener(e -> {
e.printStackTrace();
MLog.e("Interpreter", String.format("Cannot initialize interpreter: %s",
e.getMessage()));
});
` Any other info / logs 11-16 09:18:59.020 15532 16133 W DynamiteModule: Local module descriptor class for com.google.android.gms.tflite_dynamite not found. 11-16 09:18:59.046 15532 16133 I DynamiteModule: Considering local module com.google.android.gms.tflite_dynamite:0 and remote module com.google.android.gms.tflite_dynamite:231810005 11-16 09:18:59.046 15532 16133 I DynamiteModule: Selected remote version of com.google.android.gms.tflite_dynamite, version >= 231810005 11-16 09:18:59.047 15532 16133 V DynamiteModule: Dynamite loader version >= 2, using loadModule2NoCrashUtils 11-16 09:18:59.085 15532 15532 W TFLiteClient-0: type=1400 audit(0.0:2479): avc: denied { execute } for path=“/data/user_de/0/com.google.android.gms/app_chimera/m/00000016/dl-TfliteDynamiteDynamite.integ_231810005100400.apk” dev=“dm-41” ino=20657 scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:privapp_data_file:s0:c512,c768 tclass=file permissive=0 app=xxxxxxx 11-16 09:18:59.147 15532 15716 I AD-PLUGIN-OnDeviceIntelligenceCore: OnDeviceIntelligence calculate failed, model load failed 11-16 09:18:59.148 15532 15532 W System.err: android.os.RemoteException: Error loading TFLite native library 11-16 09:18:59.148 15532 15532 W System.err: at qb.a(:com.google.android.gms.policy_tflite_dynamite_dynamite@231810011@231810005065.544055685.544055685:0) 11-16 09:18:59.149 15532 15532 W System.err: at com.google.android.gms.tflite.dynamite.TfLiteDynamiteLoaderImpl.b(:com.google.android.gms.policy_tflite_dynamite_dynamite@231810011@231810005065.544055685.544055685:3) 11-16 09:18:59.149 15532 15532 W System.err: at com.google.android.gms.tflite.dynamite.TfLiteDynamiteLoaderImpl.getInternalNativeInitializationHandleWithParams(:com.google.android.gms.policy_tflite_dynamite_dynamite@231810011@231810005065.544055685.544055685:0) 11-16 09:18:59.149 15532 15532 W System.err: at om.w(:com.google.android.gms.policy_tflite_dynamite_dynamite@231810011@231810005065.544055685.544055685:6) 11-16 09:18:59.149 15532 15532 W System.err: at bs.onTransact(:com.google.android.gms.policy_tflite_dynamite_dynamite@231810011@231810005065.544055685.544055685:4) 11-16 09:18:59.149 15532 15532 W System.err: at android.os.Binder.transact(Binder.java:1169) 11-16 09:18:59.149 15532 15532 W System.err: at com.google.android.gms.internal.tflite.zza.zzb(com.google.android.gms:play-services-tflite-impl@@16.1.0:2) 11-16 09:18:59.150 15532 15532 W System.err: at com.google.android.gms.tflite.dynamite.zza.zzf(com.google.android.gms:play-services-tflite-impl@@16.1.0:4) 11-16 09:18:59.150 15532 15532 W System.err: at com.google.android.gms.tflite.dynamite.internal.zzk.zzc(com.google.android.gms:play-services-tflite-impl@@16.1.0:11) 11-16 09:18:59.150 15532 15532 W System.err: at com.google.android.gms.tflite.dynamite.internal.zzi.zza(com.google.android.gms:play-services-tflite-impl@@16.1.0:9) 11-16 09:18:59.150 15532 15532 W System.err: at com.google.android.gms.tflite.dynamite.internal.zzf.then(Unknown Source:6) 11-16 09:18:59.150 15532 15532 W System.err: at com.google.android.gms.tasks.zzo.run(com.google.android.gms:play-services-tasks@@18.0.2:1) 11-16 09:18:59.151 15532 15532 W System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137) 11-16 09:18:59.151 15532 15532 W System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637) 11-16 09:18:59.151 15532 15532 W System.err: at java.lang.Thread.run(Thread.java:1012) 11-16 09:18:59.152 15532 15532 W System.err: Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: couldn’t map “/data/user_de/0/com.google.android.gms/app_chimera/m/00000016/dl-TfliteDynamiteDynamite.integ_231810005100400.apk!/lib/arm64-v8a/libtflite_gmscore_jni.so” segment 1: Permission denied 11-16 09:18:59.152 15532 15532 W System.err: at java.lang.Runtime.loadLibrary0(Runtime.java:1077) 11-16 09:18:59.152 15532 15532 W System.err: at java.lang.Runtime.loadLibrary0(Runtime.java:998) 11-16 09:18:59.152 15532 15532 W System.err: at java.lang.System.loadLibrary(System.java:1661) 11-16 09:18:59.152 15532 15532 W System.err: at com.google.android.gms.tflite.dynamite.TfLiteNativeApi.b(:com.google.android.gms.policy_tflite_dynamite_dynamite@231810011@231810005065.544055685.544055685:2) 11-16 09:18:59.153 15532 15532 W System.err: at com.google.android.gms.tflite.dynamite.TfLiteNativeApi.a(:com.google.android.gms.policy_tflite_dynamite_dynamite@231810011@231810005065.544055685.544055685:0) 11-16 09:18:59.153 15532 15532 W System.err: at com.google.android.gms.tflite.dynamite.TfLiteDynamiteLoaderImpl.b(:com.google.android.gms.policy_tflite_dynamite_dynamite@231810011@231810005065.544055685.544055685:2) 11-16 09:18:59.153 15532 15532 W System.err: … 13 more
About this issue
- Original URL
- State: closed
- Created 8 months ago
- Comments: 23 (3 by maintainers)
The relevant error messages seem to be these ones:
and
and
Basically the issue is that the SELinux security policy in your phone’s OS is denying your app execute permission to the “TF Lite in Play services” APK file
/data/user_de/0/com.google.android.gms/app_chimera/m/00000016/dl-TfliteDynamiteDynamite.integ_231810005100400.apkwhich contains the native code shared library filelib/arm64-v8a/libtflite_gmscore_jni.soembedded within it. The file descriptor for that file is opened by the “TF Lite in Play services” module of Play services, and then passed back to your app, and then passed toandroid_dlopen_extby the “TF Lite in Play services” client library.I suspect this is likely due to a misconfiguration of the SELinux policy for the device?
If my diagnosis is correct, a proper fix would require updating the SELinux policy configuration files that the OS provides.
A likely work-around is to run the following command (requires root):
It may be worth raising this issue with the OEM that supplies the OS for your device. Your device was
Redmi/thunder_global/thunder:13/TP1A.220624.014/V0.0.0.0.XXXXXXX:user/test-keys, so I guess that would be Redmi.