android studio中NDK配置出现:NDK does not contain any platforms

0 背景

最近在整android studio的环境,再配置下载好NDK之后,打开Project Structure配置NDK的路径,结果配置好出现 “NDK does not contain any platforms”, 如下图所示

在网上求助别人,给了一种解决办法,如下

也就是我在要添加的NDK路径下面,新建立了一个空文件夹platforms便解决了这个问题

 但是接着往下编译出现 ABIs [arm64-v8a] are not supported for platform. Supported ABIs are [armeabi-v7a, x86] 的问题

于是找到了这篇,按照其中降低了下NDK的版本, 便解决了第二个报错问题。

但是又出现一个NDK unknown的问题,这里参考这篇解决了

  • 11
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Android Studio配置NDK的步骤如下: 1.下载NDK:打开Android Studio,依次点击File -> Project Structure -> SDK Location,在SDK Location窗口找到Android NDK location,点击Download按钮下载NDK。 2.配置NDK路径:下载完成后,回到SDK Location窗口,将下载好的NDK路径复制到Android NDK location。 3.配置build.gradle文件:在app目录下的build.gradle文件添加以下代码: ```gradle android { ... defaultConfig { ... externalNativeBuild { cmake { cppFlags "" abiFilters "" } } } ... externalNativeBuild { cmake { path "CMakeLists.txt" } } } ``` 4.配置CMakeLists.txt文件:在项目根目录下创建CMakeLists.txt文件,并添加以下代码: ```cmake cmake_minimum_required(VERSION 3.4.1) 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 ) # Searches for a specified prebuilt library and stores the path as a # variable. Because system libraries are included in the search path by # default, you only need to specify the name of the public NDK library # you want to add. CMake verifies that the library exists before # completing its build. find_library( # Sets the name of the path variable. log-lib # Specifies the name of the NDK library that # you want CMake to locate. log ) # Specifies libraries CMake should link to your target library. You # can link multiple libraries, such as libraries you define in the # build script, prebuilt third-party libraries, or system libraries. target_link_libraries( # Specifies the target library. native-lib # Links the target library to the log library # included in the NDK. ${log-lib} ) ``` 5.编写C++代码:在app/src/main/cpp目录下创建native-lib.cpp文件,并添加以下代码: ```c++ #include <jni.h> #include <string> extern "C" JNIEXPORT jstring JNICALL Java_com_example_ndkdemo_MainActivity_stringFromJNI( JNIEnv* env, jobject /* this */) { std::string hello = "Hello from C++"; return env->NewStringUTF(hello.c_str()); } ``` 6.运行程序:点击Android Studio的Run按钮,即可在模拟器或真机上运行程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

鸡啄米的时光机

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

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

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

打赏作者

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

抵扣说明:

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

余额充值