MNN编译android

docker编译:

https://github.com/hzung/build-mnn-for-android

我用的win10下的linux子系统,ndk下载:

好像21,22都可以

https://developer.android.google.cn/ndk/downloads/revision_history

不可以的版本:

1. android-ndk-r23-linux

需要升级cmake到3.19以上,否则报错:

  An old version of CMake is being used that cannot automatically detect
  compiler attributes.  Compiler identification is being bypassed.  Some
  values may be wrong or missing.  Update to CMake 3.19 or newer to use
  CMake's built-in compiler identification.

2. android-ndk-r15c-linux-x86_64

ndk15rc报错:

Neon double or quad precision register expected

这个错这次没见到:

Could NOT find Protobuf (missing: Protobuf_LIBRARIES Protobuf_INCLUDE_DIR)

下载MNN代码:

https://github.com/alibaba/MNN

MNN CMakeLists.txt
CMakelist.txt 设置MNN_ARM82为ON (低精度需要的动态库)

添加android-NDK:

vim ~/.bashrc
export ANDROID_NDK=/$(ndk电脑的路径)/android-ndk-r21
source ~/.bashrc

查看NDK路径:

echo  $ANDROID_NDK

报错:

CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_ASM_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
make: *** No targets specified and no makefile found.  Stop.

原因:

没有找到ndk,

原因1:~/.bashrc没有权限。

报错显示:

bash后,报错:

bash: /home/xxxxx/.bashrc: Permission denied

解决方法:

sudo chmod 777 ~/.bashrc

source ~/.bashrc

../build_32.sh继续报错,需要把build文件夹中的内容清空,

再编译

原因2:ndk路径写错了

再Ubuntu子系统里面,区分大小写,Windows盘符必须小写,

比如D盘,子系统中是:

/mnt/d/

修改./bashrc文件,

export ANDROID_NDK=/mnt/d/soft/android-ndk-r23-linux/android-ndk-r23
 

编译64位ok:
cd /mnt/d/third_partyMNN
./schema/generate.sh
 cd MNN/project/android
mkdir build_64 && cd build_64 && ../build_64.sh
make -j4

编译32位报错,build_32.sh

解决方法:换高版本ndk,编译ok。


使用动态库
代码设置
// 创建session需要的配置
MNN::ScheduleConfig config;
// 选择Backend
config.type = MNN_FORWARD_CPU;
// 线程数
config.numThread = 2;
// 配置相应的Backend
BackendConfig backendConfig;
// 选择低精度/一般配置计算
backendConfig.precision = BackendConfig::Precision_Low;
// 或者
// backendConfig.precision = BackendConfig::Precision_Normal;
config.backendConfig    = &backendConfig;

android添加库
public class MNNNetNative { // load libraries 
    static { 
    System.loadLibrary("MNN"); 
    System.loadLibrary("MNN_Arm82"); 
    System.loadLibrary("mnncore"); 
    }
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值