Android Studio 编写JNI程序遇到的一些问题

本文详细介绍了在Android开发中遇到的CPP编译错误及解决方案,包括修改Gradle配置、设置SO库路径、更新NDK/CMake等,帮助开发者快速定位并解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 编译一直提示error configuration

    解决:修改build.gradle文件                

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

2. 有多个cpp文件

     复制下面代码,修改native-lib为自身cpp名称

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/cpp/native-lib.cpp )

复制下面代码,修改native-lib为自身cpp名称
target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

3. 设置so库生成路径

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/./libs/${ANDROID_ABI})

4. 更新最新版本的NDK或者Cmake

5. 查看CPP文件存储格式是否是UTF-8

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值