ndk-samples: Execution failed for task ':app:externalNativeBuildDebug'
Hi, I’m learning to use NDK,
- I’ve created a new project
- check the c++ support
- use c++ 11 option The generated project run fine and show the “hello from c++”. Then I tried to change the code at native-lib.cpp from sample code of bitmap plasma:
#include <jni.h>
#include <string>
#include <android/bitmap.h>
#include <android/log.h>
#define LOG_TAG "cardscanner"
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
extern "C"
jstring
Java_com_aprisma_cardscanner_cardscanner_MainActivity_stringFromJNI( JNIEnv *env, jobject /* this */, jobject bitmap) {
AndroidBitmapInfo info;
void* pixels;
int ret;
static int init;
if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret);
return NULL;
}
if (info.format != ANDROID_BITMAP_FORMAT_RGB_565) {
LOGE("Bitmap format is not RGB_565 !");
return NULL;
}
if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
}
std::string hello = "Hello sjfosfosjf";
return env->NewStringUTF(hello.c_str());
}
and change MainActivity.java :
package com.aprisma.cardscanner.cardscanner;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.graphics.Bitmap;
public class MainActivity extends AppCompatActivity {
static {System.loadLibrary("native-lib");}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView) findViewById(R.id.sample_text);
tv.setText(stringFromJNI(null));
}
public native String stringFromJNI(Bitmap bitmap);
}
Got error:
Error:FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing 'C:\Users\admin\AppData\Local\Android\sdk\cmake\3.6.3155560\bin\cmake.exe' with arguments {--build D:\Frank\workspace\CardScanner\app\.externalNativeBuild\cmake\debug\mips64 --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ..\obj\mips64\libnative-lib.so
FAILED: cmd.exe /C "cd . && C:\Users\admin\AppData\Local\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe -target mips64el-none-linux-android -gcc-toolchain C:/Users/admin/AppData/Local/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/admin/AppData/Local/Android/sdk/ndk-bundle/platforms/android-21/arch-mips64 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -std=c++11 -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\obj\mips64\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog -lm "C:/Users/admin/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/mips64/libgnustl_static.a" && cd ."
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function `Java_com_aprisma_cardscanner_cardscanner_MainActivity_stringFromJNI':
D:\Frank\workspace\CardScanner\app\src\main\cpp/native-lib.cpp:19: undefined reference to `AndroidBitmap_getInfo'
D:\Frank\workspace\CardScanner\app\src\main\cpp/native-lib.cpp:29: undefined reference to `AndroidBitmap_lockPixels'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
please help, thank you
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (8 by maintainers)
Thanks you so much Gerry for your help. After lot of try and error we are able to solve. To resolve problem I have follow below steps.
@ggfan I appreciate all the effort given buy you. Thanks again.