flutter 无法加载动态库"txtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtdlopen失败:未找到库"libtensorflowlite_c. so"

ilmyapht  于 2023-03-13  发布在  Flutter
关注(0)|答案(4)|浏览(71)

当我打电话给

/// runs and transforms the data 🤖
  this._interpreter.run(input, output);

this._interpreter =等待解释器.fromAsset('mobilefacenet. tflite',选项:解释器选项);

出现此错误

无法加载动态库“txtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtdlopen失败:未找到库“libtensorflowlite_c. so”

rqcrx0a6

rqcrx0a61#

对于Windows用户:
1.在记事本上复制所有这些行:

@echo off
setlocal enableextensions

cd %~dp0

set TF_VERSION=2.5
set URL=https://github.com/am15h/tflite_flutter_plugin/releases/download/
set TAG=tf_%TF_VERSION%

set ANDROID_DIR=android\app\src\main\jniLibs\
set ANDROID_LIB=libtensorflowlite_c.so

set ARM_DELEGATE=libtensorflowlite_c_arm_delegate.so
set ARM_64_DELEGATE=libtensorflowlite_c_arm64_delegate.so
set ARM=libtensorflowlite_c_arm.so
set ARM_64=libtensorflowlite_c_arm64.so
set X86=libtensorflowlite_c_x86_delegate.so
set X86_64=libtensorflowlite_c_x86_64_delegate.so

SET /A d = 0

:GETOPT
if /I "%1"=="-d" SET /A d = 1

SETLOCAL
if %d%==1 CALL :Download %ARM_DELEGATE% armeabi-v7a
if %d%==1 CALL :Download %ARM_64_DELEGATE% arm64-v8a
if %d%==0 CALL :Download %ARM% armeabi-v7a
if %d%==0 CALL :Download %ARM_64% arm64-v8a
CALL :Download %X86% x86
CALL :Download %X86_64% x86_64
EXIT /B %ERRORLEVEL%

:Download
curl -L -o %~1 %URL%%TAG%/%~1
mkdir %ANDROID_DIR%%~2\
move /-Y %~1 %ANDROID_DIR%%~2\%ANDROID_LIB%
EXIT /B 0

1.将文件保存为install.bat,并将文件放在项目的根目录下。
1.在资源管理器中打开并在其中打开一个命令窗口。
1.键入install.bat并按Enter键。如果要使用GpuDelegateV2NnApiDelegate,请改用install.bat -d(Windows)。
对于Linux/Mac用户:
1.把这些行都抄到记事本上

#!/usr/bin/env bash

cd "$(dirname "$(readlink -f "$0")")"

# Available versions
# 2.5, 2.4.1

TF_VERSION=2.5
URL="https://github.com/am15h/tflite_flutter_plugin/releases/download/"
TAG="tf_$TF_VERSION"

ANDROID_DIR="android/app/src/main/jniLibs/"
ANDROID_LIB="libtensorflowlite_c.so"

ARM_DELEGATE="libtensorflowlite_c_arm_delegate.so"
ARM_64_DELEGATE="libtensorflowlite_c_arm64_delegate.so"
ARM="libtensorflowlite_c_arm.so"
ARM_64="libtensorflowlite_c_arm64.so"
X86="libtensorflowlite_c_x86_delegate.so"
X86_64="libtensorflowlite_c_x86_64_delegate.so"

delegate=0

while getopts "d" OPTION
do
     case $OPTION in
         d)  delegate=1;;
    esac
done

download () {
    wget "${URL}${TAG}/$1" -O "$1"
    mkdir -p "${ANDROID_DIR}$2/"
    mv $1 "${ANDROID_DIR}$2/${ANDROID_LIB}"
}

if [ ${delegate} -eq 1 ]
then

download ${ARM_DELEGATE} "armeabi-v7a"
download ${ARM_64_DELEGATE} "arm64-v8a"

else

download ${ARM} "armeabi-v7a"
download ${ARM_64} "arm64-v8a"

fi

download ${X86} "x86"
download ${X86_64} "x86_64"

1.将文件保存为install.sh名称,并将文件放在项目的根目录中。
1.在那里打开一个命令窗口。
1.键入sh install.sh并按Enter键。如果要使用GpuDelegateV2NnApiDelegate,请使用sh install.sh -d

hxzsmxv2

hxzsmxv22#

我也犯了同样的错误。希望这对某人有帮助。
在使用install.sh文件后,那个错误显示了(只在Android上,iOS工作正常)。但是我已经在安装文件中把wget改成了curl,而且它下载了一个重定向HTML页面。
对我有效的替代品是:

# wget "${URL}${TAG}/$1" -O "$1" # Replaced with the below line          
curl -L "${URL}${TAG}/$1" -o "$1"

尝试确认您下载的文件是正确的文件。您可以在<projectdirectory>/android/app/src/main/jniLibs中检查这些文件。它们应该是以^?ELF开始的二进制文件,而不是像我拥有的那样的html文件。

5fjcxozz

5fjcxozz3#

您需要在tflite_flutterpackage. tflite_flutter中找到的应用的根目录中添加一个文件。您也可以在here中找到该文件。只需下载该文件并将其放置到应用的根目录中,然后双击以安装所需的信息。(适用于Windows)

zengzsys

zengzsys4#

对于Android平台:
将脚本install.sh(Linux/Mac)或install.bat(Windows)放置在项目的根目录下。
执行此.sh:
install.sh〈=(Linux/Mac)
install.bat〈=(Windows)
文件,以自动下载二进制文件并将其放置在相应的文件夹中。
注:安装的二进制文件不支持GpuDelegateV 2和NnApiDelegate,但仍可使用InterpreterOptions().useNnApiForAndroid

如何使用.sh

  • Linux/苹果电脑 *
install.sh -d
  • Windows *
install.bat -d

如果您希望使用这些GpuDelegateV 2和NnApiDelegate,则可以使用。
阅读更多:https://pub.dev/packages/tflite_flutter

相关问题