Issue
I've been trying to get an OpenAL port for Android 2.2 working via the NDK, but I get an error along the way that I can't seem to solve on my own. I've declared several native methods in my Java class:
/**
* Creates a native OpenAL Audio player.
* @return An int value according to if the action was a success or not.
*/
private native int initALPlayer();
/**
* Writes raw PCM data to the OpenAL Audio player.
* @param data
* @return An int value according to if the action was a success or not.
*/
private native int writeAudio(byte[] data);
/**
* Closes the native OpenAL Audio player.
* @return An int value according to if the action was a success or not.
*/
private native int closeALPlayer();
I load the correct libraries via System.loadLibrary():
static{
System.loadLibrary("openal");
System.loadLibrary("audio");
}
After this, I created the header file with the javah command
javah -classpath bin -d jni org.rohill.privatemobileradio.utilities.AudioProcessor
The header file:
/*
* Class: org_rohill_privatemobileradio_utilities_AudioProcessor
* Method: initALPlayer
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_rohill_privatemobileradio_utilities_AudioProcessor_initALPlayer
(JNIEnv *, jobject);
/*
* Class: org_rohill_privatemobileradio_utilities_AudioProcessor
* Method: writeAudio
* Signature: ([B)I
*/
JNIEXPORT jint JNICALL Java_org_rohill_privatemobileradio_utilities_AudioProcessor_writeAudio
(JNIEnv *, jobject, jbyteArray);
/*
* Class: org_rohill_privatemobileradio_utilities_AudioProcessor
* Method: closeALPlayer
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_rohill_privatemobileradio_utilities_AudioProcessor_closeALPlayer
(JNIEnv *, jobject);
I use this created header file in a C file.
My C implementation:
JNIEXPORT jint JNICALL
Java_org_rohill_privatemobileradio_utilities_AudioProcessor_initALPlayer(JNIEnv * env, jobject object)
{
return 42;
}
JNIEXPORT jint JNICALL
Java_org_rohill_privatemobileradio_utilities_AudioProcessor_writeAudio(JNIEnv * env, jobject object, jbyteArray byteData)
{
return 43;
}
JNIEXPORT jint JNICALL
Java_org_rohill_privatemobileradio_utilities_AudioProcessor_closeALPlayer(JNIEnv * env, jobject object)
{
return 44;
}
When I build the library next, all goes well. But it goes wrong when I try to call a native method:
if(initALPlayer() == 1){
Log.i(TAG, "AL Audio Player initialized");
} else {
Log.e(TAG, "Failed to initialize AL Audio Player");
}
Whenever I try to run this method, I get an error in my logs saying:
04-27 08:03:11.072: ERROR/AndroidRuntime(25017): java.lang.UnsatisfiedLinkError: initALPlayer
However, I have not been able to track down where this goes wrong. I've used the method name declarations from the header file javah created for me. I've checked for typo's but there don't seem to be any...
What really boggles me is that when I use a simpler and easier method, which only returns a string, it works...
If anybody has an idea on how to solve this... please feel free to elaborate...
Solution
Apparently, it was some naming convention error with the name of my C file. When I changed that to a simple, one word descriptor of what the file is supposed to do (no special tokens like _ or so), it works... >.< Sigh...
Answered By - ThaMe90
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.