0

Ok, I know there's lots of tutorials about Android NDK on the net, but I've yet to find ONE that works. I allways run into problems which I cannot find any working solution to - usually when trying to run javah to create the header file.

So, does anyone have a link to a tutorial on how to create a simple test project where you create a c header and source file, call native code from the main activity (or any other java class), which you KNOW works and doesn't contain important outdated info? And then be able to help me a bit when (not if) I run into problems, and the instructions simply won't work?

It can be one of those which I've tried and couldn't get to work, as long as someone can help me find what I'm doing wrong. I usually copy everthing from the examples, including file locations, package names etc., but I've yet to get it to work.

1 Answers1

0

Check this

http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/

and

http://mobile.tutsplus.com/tutorials/android/ndk-tutorial/

both worked great for me.

You can always check the samples that come with ndk (http://developer.android.com/tools/sdk/ndk/index.html#Downloads)

Miguel Teixeira
  • 783
  • 1
  • 10
  • 29
  • Thanks for the tips. However, both of those examples does not include using javah to create the header files - they don't use header files at all. I've actually gotten that to work, but what I want to get working is the "whole package" with source and header files. –  Dec 19 '12 at 11:58
  • However, that last one is pretty good except the missing header stuff :-) –  Dec 19 '12 at 11:59
  • Check this ones then: http://stackoverflow.com/questions/9985336/javah-cant-find-class-android-ndk http://stackoverflow.com/questions/3020927/how-to-create-c-header-file-using-javah-tool – Miguel Teixeira Dec 19 '12 at 12:03
  • Yes. However, that's the problem; That command returns "Error: cannot access android.app.Activity" and "class file for android.app.Activity not found" no matter what I do, and which examples I try. And it's absurd, because all the paths I use are correct. That's why I need an example tutorial inclluding this, so I can ask some guru to look at what I'm doing and hopefully spot the idiot error I'm making all the way (but which is not that obvious). :) –  Dec 19 '12 at 12:12
  • Hm. There is no android.jar anywhere on my system. How is that possible? I DO have the android-ndk installed (else I wouldn't be able to use ndk-build)... –  Dec 19 '12 at 12:22
  • What OS and IDE are using? – Miguel Teixeira Dec 19 '12 at 12:30
  • Ah, that would be important info, yes :-) I'm using Windows 7 64-bit, and Eclipse Indigo. –  Dec 19 '12 at 12:56
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/21387/discussion-between-miguel-teixeira-and-kakemonsteret) – Miguel Teixeira Dec 19 '12 at 13:05
  • 1
    I found my problem: It seems that the class in which you implement the native functions cannot be the Activity class, or apparently cannot implement or excend anything (didn't work with an AsyncActivity either). When I created a clean class, and implemented the native functions there, I was able to create the JNI header file. However, you can implement and use native functions from the main activity class, but you won't be able to create a header file for it, or so it seems. –  Dec 19 '12 at 14:27