[英]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")
}
}
I just encountered same problem and I think it is a bug. 我刚刚遇到了同样的问题,我认为这是一个错误。 But I managed to make it work with the following workaround: 但是我设法使其与以下变通办法一起工作:
First be sure you both install the api and also build-tools (see figure below) 首先,请确保您同时安装了api和构建工具(请参见下图)
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 }
} }
Sync gradle successfully 成功同步gradle
Change versions back 改回版本
I also restarted android studio several times but not sure whether it is required or not. 我还多次重启了android studio,但不确定是否需要。
This worked for me: 这为我工作:
I removed the application I was working on in home directory under AndroidStudioProjects 我删除了在AndroidStudioProjects下主目录中正在处理的应用程序
Restarted Android Studio 重新启动Android Studio
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.