Android NDK开发遇到的问题总结

本文总结了Android NDK开发中遇到的几个典型问题及解决方法,包括编译SO文件报错、执行ndk-build命令失败、JNI方法调用异常以及UART串口通信异常。通过修改Gradle配置,如设置android.useDeprecatedNdk=true,调整abiFilters,以及修正so文件路径,可以解决这些问题。
摘要由CSDN通过智能技术生成
1、编译成so文件时报错问题:
Error:Execution failed for task ':app:compileDebugNdk'.
> Error: Your project contains C++ files but it is not using a supported native build system.
  Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
   https://developer.android.com/studio/projects/add-native-code.html
  or use the experimental plugin:
   https://developer.android.com/studio/build/experimental-plugin.html.
解决办法:
在项目的gradle.properties添加android.useDeprecatedNdk=true
在module的build.gradle(Module:app)的buildTypes上面添加sourceSets属性
 sourceSets {
        main {
            jni.srcDirs = ['src/main/jni', 'src/main/jni/']
            jniLibs.srcDirs 'src/main/libs'
        }
    }


最后运行gradle脚本更新build,在编译module即可。
这个问题主要是因为Android studio以前使用ndkCompile后来废弃掉了,Android-Terminal-Emulator没有最近没有更新的缘故。具体的编译最新的NDK编译方式可以看官网
https://developer.android.com/studio/projects/add-native-code.html


2、Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.process.ProcessException: Error while executing process D:\installTools\sdk\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=D:\tool\ReadUSB1\ReadUSB\app\build\intermediates\ndk\debug\Android.mk APP_PLATFORM=android-25 NDK_OUT=D:\tool\ReadUSB1\ReadUSB\app\build\intermediates\ndk\debug\obj NDK_LIBS_OUT=D:\tool\ReadUSB1\ReadUSB\app\build\intermediates\ndk\debug\lib APP_STL=stlport_shared APP_ABI=armeabi-v7a,armeabi,x86}
解决办法:修改build.gradle文件
android {
    compileSdkVersion 26
    buildToolsVersion '26.0.1'
    defaultConfig {
        applicationId "com.android.read"
        minSdkVersion 25
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值