7

I want to integrate NDK into Android studio but i am facing NDK support is an experimental feature and use cases are not yet supported error.I have downloaded NDK using the SDK manager and the NDK is palced C:\Users\The\AppData\Local\Android\Sdk\ndk-bundle. I have also created NativePanorama java class for Java and C++ interaction. Here is the code for the NativePanorama.java class

     public class NativePanorama {



     public native static void processPanorama(long[] imageAddressArray,
                                                  long outputAddress);
        {

        }
}

I used the javah command in the terminal to create the corresponding C++ header for the processPanorama method in the NativePanorama java class. Here is the created com_example_the_myapplication_NativePanorama.h c++ header file.

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>

    /* Header for class com_example_the_myapplication_NativePanorama */

    #ifndef _Included_com_example_the_myapplication_NativePanorama
    #define _Included_com_example_the_myapplication_NativePanorama
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
     * Class:     com_example_the_myapplication_NativePanorama
     * Method:    processPanorama
     * Signature: ([JJ)V
     */
    JNIEXPORT void JNICALL Java_com_example_the_myapplication_NativePanorama_processPanorama
    (JNIEnv *, jclass, jlongArray, jlong);

    #ifdef __cplusplus
    }
    #endif
    #endif

Here is also the com_example_the_myapplication_NativePanorama.cpp c++ source file.

#include "com_example_panorama_NativePanorama.h"
JNIEXPORT void JNICALL
Java_com_example_panorama_NativePanorama_processPanorama
(JNIEnv * env, jclass clazz, jlongArray imageAddressArray, jlong
outputAddress){
}  

May be the error is in the build.gradle file here is my build.gradle(app) file

import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example.the.myapplication"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    // begin NDK OPENCV
    sourceSets.main {
        jni.srcDirs = [] //disable automatic ndk-build call
    }
    task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
        def rootDir = project.rootDir
        def localProperties = new File(rootDir, "local.properties")
        Properties properties = new Properties()
        localProperties.withInputStream { instr ->
            properties.load(instr)
        }
        def ndkDir = properties.getProperty('ndk.dir')
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            commandLine "$ndkDir\\ndk-build.cmd",
                    'NDK_PROJECT_PATH=build/intermediates/ndk',
                    'NDK_LIBS_OUT=src/main/jniLibs',
                    'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
                    'NDK_APPLICATION_MK=src/main/jni/Application.mk'
        } else {
            commandLine "$ndkDir/ndk-build",
                    'NDK_PROJECT_PATH=build/intermediates/ndk',
                    'NDK_LIBS_OUT=src/main/jniLibs',
                    'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
                    'NDK_APPLICATION_MK=src/main/jni/Application.mk'
        }
    }
    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile project(":opencv-java")
}

There is also Reports native method declaration in java where no corresponding jni function is found in the project error in the NativePanorama.java class.

How can i fix those problem?

3
  • Can't see where you tell us what errors you are getting? And what version of Android Studio are you on? Oct 16, 2016 at 9:26
  • There are two error the one is NDK support is an experimental features and all use cases are not yet supported in the .cpp and .h files and the second is Reports native method declaration in java where no corresponding jni function is found in the project in the NativePanorama.java class. I am using Android Studio version 2.1.3
    – Yirga
    Oct 16, 2016 at 10:46
  • 1
    I think you should update to 2.2.x tools.android.com/recent You can parallel install stable, and beta versions, if you need too 2.2 is advertised as supporting NDK build. Oct 16, 2016 at 12:21

1 Answer 1

7
+50

Here's the solution:

Update your Android Studio to either the latest version or to the latest public pre-release version.

Android Studio 2.2.1 is currently the latest version and it has proper C++ support build in. They're still working on it and some things might still be unsupported, but using C++ is definetly working better on a newer version. Ofcourse also make sure to keep your Android SDK up to date.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.