简体   繁体   English

无法编译NDK android项目

[英]Can't compile NDK android project

I am using android studio and openning the hello-jni sample project. 我正在使用android studio并打开hello-jni示例项目。 However when I trying to compile the project,it prompts: 但是,当我尝试编译项目时,它提示:

Error:Cause: failed to find target with hash string 'android-23' in: 

/Users/xx/opensource/android-sdk-macosx
<a href="openAndroidSdkManager">Open Android SDK Manager</a>

I had installed the android 6.0 (api 23).Why still prompts failed to find? 我已经安装了android 6.0(api 23)。为什么仍然提示找不到? I looked up in the preference in android stuido ,in android SDK tab it seems android 6.0 (api level 23 revision 1) can be found. 我在android stuido中的首选项中查找,在android SDK选项卡中似乎可以找到android 6.0(api级别23修订版1)。

Belows is my gradle file: 以下是我的gradle文件:

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.0"

        defaultConfig.with {
            applicationId = "com.example.hellojni"
            minSdkVersion.apiLevel      = 3
            targetSdkVersion.apiLevel = 23
        }
    }
    /*
     * native build settings
     */
    android.ndk {
        moduleName = "hello-jni"
        /*
         * Other ndk flags configurable here are
         * cppFlags += "-fno-rtti"
         * cppFlags += "-fno-exceptions"
         * ldLibs    = ["android", "log"]
         * stl       = "system"
         */
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.productFlavors {
        // for detailed abiFilter descriptions, refer to "Supported ABIs" @
        // https://developer.android.com/ndk/guides/abis.html#sa
        create("arm") {
            ndk.abiFilters += "armeabi"
        }
        create("arm7") {
            ndk.abiFilters += "armeabi-v7a"
        }
        create("arm8") {
            ndk.abiFilters += "arm64-v8a"
        }
        create("x86") {
            ndk.abiFilters += "x86"
        }
        create("x86-64") {
            ndk.abiFilters += "x86_64"
        }
        create("mips") {
            ndk.abiFilters += "mips"
        }
        create("mips-64") {
            ndk.abiFilters += "mips64"
        }
        // To include all cpu architectures, leaves abiFilters empty
        create("all")
    }
}

Android SDK

I just encountered same problem and I think it is a bug. 我刚刚遇到了同样的问题,我认为这是一个错误。 But I managed to make it work with the following workaround: 但是我设法使其与以下变通办法一起工作:

  1. First be sure you both install the api and also build-tools (see figure below) 首先,请确保您同时安装了api和构建工具(请参见下图)

  2. Than in build.gradle, change versions for api and build tools to previous ones: ie 比在build.gradle中,更改api的版本并将构建工具更改为以前的版本:即

      android{ compileSdkVersion = 22 buildToolsVersion = "22.0.1" defaultConfig.with { applicationId = "com.sample.teapot" minSdkVersion.apiLevel = 11 targetSdkVersion.apiLevel = 22 } 

    } }

  3. Sync gradle successfully 成功同步gradle

  4. Change versions back 改回版本

I also restarted android studio several times but not sure whether it is required or not. 我还多次重启了android studio,但不确定是否需要。

不要忘记安装Android SDK Build-tools

This worked for me: 这为我工作:

  • I removed the application I was working on in home directory under AndroidStudioProjects 我删除了在AndroidStudioProjects下主目录中正在处理的应用程序

  • Restarted Android Studio 重新启动Android Studio

  • It prompt the Android Studio Wizard, I went through the Android Studio Setup Wizard where it downloaded some SDK Build-tools for revision 23.0.1. 它提示了Android Studio向导,我经历了Android Studio安装向导,在其中下载了一些版本23.0.1的SDK Build-tools。
  • I also clicked on update link when the "Platform and Plugin Updates" message show up while downloading Android SDK Build-tools, to update some components. 下载Android SDK构建工具时,当显示“平台和插件更新”消息时,我还单击了更新链接,以更新某些组件。
  • "Welcome to Android Studio" in the Android Setup Wizard will show up, click on Configure, it will show the Android SDK Manager fetching some packages as shown in the previous answer, click on new or updates links 将显示“ Android安装向导”中的“欢迎使用Android Studio”,单击“配置”,它将显示Android SDK管理器正在获取一些软件包,如上一个答案所示,单击“新建”或“更新”链接
  • Once the packages are done loading you can go ahead and Install the available packages. 软件包加载完成后,您可以继续并安装可用的软件包。 After installing the default selected packages you may get more that are selected. 安装默认的选定软件包后,您可能会获得更多的选定内容。 Install Android SDK License. 安装Android SDK许可。 You should select each one and then click on accept license. 您应该选择每个,然后单击接受许可证。 Android Studio will the go through a gradle build process Android Studio将经历一个gradle构建过程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM