如何解决 Android ndk 构建命令失败? [英] How to resolve Android ndk build command faild?

查看:16
本文介绍了如何解决 Android ndk 构建命令失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 android studio 中使用 android ndk 开发简单的 ndk 示例示例.运行我的应用工作室时显示以下错误.

I am developing simple ndk sample example using android ndk in android studio. While running my app studio shows below errors.

Build command failed.
Error while executing process D:Sdkcmake3.6.4111459incmake.exe with 
arguments {--build D:Android StudioWorkspaceNDKSampleapp.externalNativeBuildcmakedebugarm64-v8a --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.oFAILED: D:Sdk
dk-bundle	oolchainsllvmprebuiltwindows-x86_64inclang++.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
ative-lib.dirsrcmaincpp
ative-lib.cpp.o.d -o CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -c "D:Android StudioWorkspaceNDKSampleappsrcmaincpp
ative-lib.cpp"
error: error reading 'D:Android StudioWorkspaceNDKSampleappsrcmaincpp
ative-lib.cpp'
1 error generated.ninja: build stopped: subcommand failed.

我有很多搜索,但无法找到我在这里问的正确答案.我还卸载了所有组件并在我的工作室重新安装仍然存在错误.

I have search lot but not able to find proper answer that why I am asking here. I have also unintsall all the components and re-install on my studio still error is there.

另一件事如果我将文件扩展名从 .CPP 更改为 .C,则整个项目都会得到编译,甚至可以正常运行.我不知道为什么它不适用于 .CPP 文件.

Another thing If I change file extension to .C from .CPP whole project gets complied and even runs properly. I don't know why Its not working for .CPP file.

我正在使用的组件.

Android 工作室 - 3.1.3

Android Stuido - 3.1.3

gradle - 3.1.0

gradle - 3.1.0

cmake - 3.6.4111459

cmake - 3.6.4111459

Android ndk - 17.1.4828580

Android ndk - 17.1.4828580

lldb -3.1

native-lib.cpp

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

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'}

任何知道的人请帮我解决这个问题.提前致谢.

Anyone know please help me to solve this problem. Thanks in advance.

推荐答案

经过大量试验和 github google guy 的帮助,我能够解决.为了解决问题,我按照以下步骤操作.

After lot of trials and help from github google guy I am able to solve. To resolve problem I have follow below steps.

1.进入项目目录.

2.删除了.gradle、app/.externalNativeBuild和app/build.

2.deleted .gradle ,app/.externalNativeBuild and app/build.

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

3.changed local.properties ndk path to external ndk-r16b.

4.通过Android studio运行.

4.Run through Android studio.

5.最后生成apk.

这篇关于如何解决 Android ndk 构建命令失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆