title: JNI and Gradle in Android Studio
body: <p>I'm trying to add native code to my app. I have everything in <code>../main/jni</code> as it was in my Eclipse project. I have added <code>ndk.dir=...</code> to my <code>local.properties</code>. I haven't done anything else yet (I'm not sure what else is actually required, so if I've missed something let me know). When I try and build I get this error:</p>
  
  <pre><code>Execution failed for task ':app:compileDebugNdk'.
  &gt; com.android.ide.common.internal.LoggedErrorException: Failed to run command:
      /Users/me/android-ndk-r8e/ndk-build NDK_PROJECT_PATH=null 
  APP_BUILD_SCRIPT=/Users/me/Project/app/build/ndk/debug/Android.mk APP_PLATFORM=android-19 
  NDK_OUT=/Users/me/Project/app/build/ndk/debug/obj 
  NDK_LIBS_OUT=/Users/me/Project/app/build/ndk/debug/lib APP_ABI=all
  
    Error Code:
      2
    Output:
      make: *** No rule to make target `/Users/me/Project/webapp/build/ndk/debug//Users/me/Project/app/src/main/jni/jni_part.cpp',
   needed by `/Users/me/Project/app/build/ndk/debug/obj/local/armeabi-v7a/objs/webapp//Users/me/Project/app/src/main/jni/jni_part.o'.  
  Stop.
  </code></pre>
  
  <p>What do I need to do?</p>
  
  <p><strong>Android.mk:</strong></p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  
  include $(CLEAR_VARS)
  
  # OpenCV
  OPENCV_CAMERA_MODULES:=on
  OPENCV_INSTALL_MODULES:=on
  include .../OpenCV-2.4.5-android-sdk/sdk/native/jni/OpenCV.mk
  
  LOCAL_MODULE    := native_part
  LOCAL_SRC_FILES := jni_part.cpp
  LOCAL_LDLIBS +=  -llog -ldl
  
  include $(BUILD_SHARED_LIBRARY)
  </code></pre>
  
  <p><strong>Application.mk:</strong></p>
  
  <pre><code>APP_STL := gnustl_static
  APP_CPPFLAGS := -frtti -fexceptions
  APP_ABI := armeabi armeabi-v7a
  APP_PLATFORM := android-8
  </code></pre>