2

I am doing every single step from video: https://www.youtube.com/watch?v=kFtxo7rr2HQ but no shared libraries are generated.

Here is a version, where android-studio should generate shared libraries on his own. However when I create apropraite Makefiles and execute ndk-build, shared libraries are not generated as well.

MainActivity.java:

public native String HelloJNI();

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

Build->Make Project

[*@* main]$ javah -d jni -classpath {sdk_dir}/platforms/android-14/android.jar:../../build/intermediates/classes/debug com.example.ndker.ndkapp.MainActivity

Creating HelloJNI.c:

#include "com_example_ndker_ndkapp_MainActivity.h"
JNIEXPORT jstring JNICALL Java_com_example_ndker_ndkapp_MainActivity_HelloJNI
        (JNIEnv *, jobject) {
    return (*env)->NewStringUTF(env, "Hello from jni");
}

local.properties:

sdk.dir={sdk_dir}
ndk.dir={ndk_dir}

build.grandle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.example.ndker.ndkapp"
    minSdkVersion 14
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"

    ndk {
        moduleName "HelloJNI"
    }
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}

Thank You for replies.

galvanize
  • 537
  • 1
  • 5
  • 17

2 Answers2

2

I've created a blog post that documents setting up Android Studio, Gradle, and the NDK here: http://www.sureshjoshi.com/mobile/android-ndk-in-android-studio-with-swig/

Also, I've created a sample project in BitBucket with everything already set up for you here: https://bitbucket.org/sureshjoshi/android

Perhaps you could give those a try and see if they work for you?

The key thing is that Gradle will now automatically generate Makefiles and compile for you!

SJoshi
  • 1,866
  • 24
  • 47
0

Right. If you put the video on HD, you can then realize that to generate the native compilation, you should use ";" instead of ":". Like:

[*@* main]$ javah -d jni -classpath {sdk_dir}/platforms/android-14/android.jar;../../build/intermediates/classes/debug com.example.ndker.ndkapp.MainActivity

Here is an screenshot of the screen (taken from the video you've posted)

enter image description here

Let me know if that did the trick!

facundofarias
  • 2,973
  • 28
  • 27
  • When I do it in that way, I receive: Error: no classes specified bash: ../../build/intermediates/classes/debug: Is a directory – galvanize Dec 21 '14 at 16:41
  • The same as here: http://stackoverflow.com/questions/27252712/android-studio-ndk-i-got-an-error-when-javah-d-jni-classpath – galvanize Dec 21 '14 at 16:47