首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何解析Android ndk build命令faild?

如何解析Android ndk build命令faild?
EN

Stack Overflow用户
提问于 2018-06-29 18:54:25
回答 2查看 2.4K关注 0票数 1

我正在android studio中使用android ndk开发简单的ndk示例。在运行我的app studio时,显示了以下错误。

Build command failed.
Error while executing process D:\Sdk\cmake\3.6.4111459\bin\cmake.exe with 
arguments {--build D:\Android Studio\Workspace\NDKSample\app\.externalNativeBuild\cmake\debug\arm64-v8a --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.oFAILED: D:\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe  --target=aarch64-none-linux-android --gcc-toolchain=D:/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=D:/Sdk/ndk-bundle/sysroot  -Dnative_lib_EXPORTS -isystem D:/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem D:/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/include -isystem D:/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -isystem D:/Sdk/ndk-bundle/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security  -frtti -fexceptions -O0 -fno-limit-debug-info  -fPIC -MD -MT CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -MF CMakeFiles\native-lib.dir\src\main\cpp\native-lib.cpp.o.d -o CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -c "D:\Android Studio\Workspace\NDKSample\app\src\main\cpp\native-lib.cpp"
error: error reading 'D:\Android Studio\Workspace\NDKSample\app\src\main\cpp\native-lib.cpp'
1 error generated.ninja: build stopped: subcommand failed.

我已经搜索了很多,但无法找到正确的答案,这就是为什么我在这里问。我还解开了所有的组件,并在我的工作室中重新安装,但错误仍然存在。

另外,如果我将文件扩展名从.CPP改为.C,则整个项目都可以编译,甚至可以正常运行。我不知道为什么它对.CPP文件不起作用。

我正在使用的组件。

Android Stuido - 3.1.3

gradle - 3.1.0

cmake - 3.6.4111459

Android ndk - 17.1.4828580

lldb -3.1

native-lib.cpp

#include <jni.h>#include <string>extern "C" JNIEXPORT jstringJNICALLJava_com_mastek_ndksample_MainActivity_stringFromJNI(
    JNIEnv *env,
    jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());}

build.gradle

apply plugin: 'com.android.application'android {    compileSdkVersion 27
defaultConfig {
    applicationId "com.example.ndksample"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    externalNativeBuild {
        cmake {
            cppFlags "-frtti -fexceptions"
        }
    }

}

sourceSets {
    main {
        jniLibs.srcDirs = ['src/main/jniLibs']
    }
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
externalNativeBuild {
    cmake {
        path "CMakeLists.txt"
    }
}}dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'}

有谁知道请帮我解决这个问题。提前谢谢。

EN

回答 2

Stack Overflow用户

发布于 2018-07-04 03:49:15

当项目文件的路径包含空格时,NDK构建会失败。要修复构建,请将项目复制到不带空格的路径。

票数 1
EN

Stack Overflow用户

发布于 2018-07-09 17:58:02

经过很多尝试和github google家伙的帮助,我终于能够解决问题了。为了解决这个问题,我遵循了下面的步骤。

1.进入项目目录。

2.删除了.gradle、app/.exteralNativeBuild和app/build。

3.将local.properties ndk路径更改为外部ndk-r16b。

4.通过Android studio运行。

5.最终生成apk。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51100111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档