0

I tried to build android app with JNI and NDK by using tess-two but i keep getting this error. i'm using Android Studo 2.0, i've installed android ndk r11c. gradle build successfully but keep getting failed to build APK.

this is my android.mk file :

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
IMAGE_PROCESSING_PATH := $(LOCAL_PATH)/../../../../Test/src
IMAGE_PROCESSING_JNI_PATH := $(LOCAL_PATH)/image_processing
TESS_TWO_PATH := $(LOCAL_PATH)/../../../../tess-two/tess-two
LEPTONICA_SRC_PATH := $(TESS_TWO_PATH)/jni/com_googlecode_leptonica_android/src
include $(IMAGE_PROCESSING_JNI_PATH)/Android.mk

This is the error message :

https://i.stack.imgur.com/yZATt.png

rmtheis
  • 5,992
  • 12
  • 61
  • 78
ranxrose
  • 245
  • 1
  • 2
  • 10

3 Answers3

0

After taking a look onto your gradle build log: Source cannot be found. You need to define the NDK_PROJECT_PATH to let it shop to the root folder of your project path.

As far as I know you can specify this in your gradle.build:

android {  
    sourceSets.main.jni.srcDirs = "src"
}
KimKulling
  • 2,654
  • 1
  • 15
  • 26
  • i added NDK_PROJECT_PATH to Environment Variables but nothing changed. keep getting error :( – ranxrose May 19 '16 at 11:42
  • i got this error after added it to build.gradle : Error:(11, 0) Cannot cast object 'src' with class 'java.lang.String' to class 'java.lang.Iterable' – ranxrose May 19 '16 at 12:06
0

You can try to disable automatic ndk-build. For this, update build.graddle file

android {
// ..... defaultConfig / buildTypes / etc ...

// SPECIFIC ROUTINE for NATIVE BUILD
sourceSets.main {
    jniLibs.srcDir 'src/main/libs'  //set .so files location to libs
    jni.srcDirs = []                //disable automatic ndk-build call
}
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        commandLine 'ndk-build.cmd', 'NDK_DEBUG=0', '-C', file('src/main/jni').absolutePath
    } else {
        commandLine 'ndk-build', 'NDK_DEBUG=0', '-C', file('src/main/jni').absolutePath
    }
}
tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}
}

You may need to update graddle.properties

android.useDeprecatedNdk=true
JMC
  • 31
  • 6
  • on this example, native code is under 'src/main/jni' folder and libs compiled under 'src/main/libs'. You should create the folder OR change source/libs location – JMC May 19 '16 at 14:07
0

I solved this by giving it a full path :

task ndkBuild(type: Exec,description: 'run ndk-build') {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
    commandLine 'D:\\Application\\android-ndk-r10e\\ndk-build.cmd', '-C', 'D:\\ransel\\Citeks\\app\\src\\main\\jni'

} else {
    workingDir 'src/main/jni'
    commandLine 'D:\\Application\\android-ndk-r10e\\ndk-build', '-C', 'D:\\ransel\\Citeks\\app\\src\\main\\jni'
}

}

Thank you :)

ranxrose
  • 245
  • 1
  • 2
  • 10