Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NDK build error on android studio

I am new to NDK so i am getting error while building the project below :

Error:Execution failed for task ':app:transformNativeLibsWithStripDebugSymbolForDebug'.
java.io.IOException: Failed to delete E:\startUpCode\OpenCvDemo\NDKTest\app\build\intermediates\transforms\stripDebugSymbol\debug\folders\2000\1f\main\lib\mips

this is my cpp code

#include <com_nickworld_ndktest_NativeClass.h>


JNIEXPORT jstring JNICALL Java_com_nickworld_ndktest_NativeClass_getMessageFromJNI
    (JNIEnv *env, jclass obj){
return env->NewStringUTF("This is the message from JNI");

android.mk file

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := com_nickworld_ndktest_NativeClass.cpp

LOCAL_LDLIBS += -llog
LOCAL_MODULE := MyLib


include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-16

MainActivity.java

public class MainActivity extends AppCompatActivity {

static {
    System.loadLibrary("MyLibs");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

((TextView) findViewById(R.id.txtView)).setText(NativeClass.getMessageFromJNI());
}
}

I need help to fix this error and i am not getting where i am doing mistake. Thanks

like image 491
Nikhil Sharma Avatar asked Apr 19 '17 07:04

Nikhil Sharma


People also ask

Is ndk necessary for Android studio?

To compile and debug native code for your app, you need the following components: The Android Native Development Kit (NDK): a set of tools that allows you to use C and C++ code with Android. CMake: an external build tool that works alongside Gradle to build your native library.

What is ndk side by side in Android Studio?

I did research and learned this: https://stackoverflow.com/a/59275504 Apparently "NDK (side by side)" means in new Android Studio you can download multiple NDK versions at once, and this means you are now required to tell Gradle which NDK to use or it won't know which one to pick.

What is difference between Android ndk and sdk?

Android provides Native Development Kit (NDK) to support native development in C/C++, besides the Android Software Development Kit (Android SDK) which supports Java. [TODO] more.


2 Answers

Try deleting E:\startUpCode\OpenCvDemo\NDKTest\app\build\intermediates manually. Then try building again.

like image 142
Martin Avatar answered Oct 21 '22 09:10

Martin


i have already face this problem and there is no issue in your code so check out this point

  1. go to your project and check does it create jnilibs or whatever you named it in your gradel NDK_LIBS_OUT
  2. check your task ndkBuild in your app gradle file and its location

  3. clean your project and build it again if it does not have created yet

like image 32
Abubakar Avatar answered Oct 21 '22 11:10

Abubakar