Hello everyone,
I am currently developing my own game boy color emulator in c and I would like to port it to android.
Before trying to port my emulator core, i wanted to get a proof of concept running:
I copied the jar-file into my additional libraries folder. I created a matching xml file. I tried various locations for my .so-file. I used the SLC to generate the java library for B4A. I used NLG to create the entire thing. I even tried loading the .so-file by calling System.load(absPath). Unfortunately, I am constantly getting a "UnsatisfiedLinkError".
(Loading the library via absolute Path seems to work at first (at least it doesn't crash), but subsequent calls to lib-functions yield the same error.)
At first, I used the commands (and variations thereof) seen in the code comments to compile the files and generate the .so- and .jar-files, but now I attached the output of the NLG, simply because that was my latest attempt.
Please note: for NLG i changed the function "foo" to "int foo(int a, int b){ return a+b; }" because NLG didn't compile my use of "snprintf" for some reason. Either way, this also didn't work so I must resort to asking the community ...
I read so many threads on related topics, but i couldn't find out, how to get it to work. I am still very much a novice when it comes to B4A and Android (and Java for that matter). I dabbled with it a few years ago for a graduation project but in my day job i am an embedded systems developer. So working in c is more my wheelhouse.
Therefore, I am hoping that someone out there understands my problem and is willing to help.
Of course, I am willing to give up as much info as possible, so if there is anything unclear or even against the etiquette, please let me know!
B4A Version 9.50 (I bought B4A a couple of years ago ...)
Target: Samsung Galaxy S23 (arm64-v8a)
android-ndk-r27d
Thank you in advance!
I am currently developing my own game boy color emulator in c and I would like to port it to android.
Before trying to port my emulator core, i wanted to get a proof of concept running:
JniTest.c:
/* aarch64-linux-android21-clang -shared -fPIC -o libJniTest.so JniTest.c */
/* cp libJniTest.so ../Files/lib/arm64-v8a/libJniTest.so */
#include <stdlib.h>
#include <stdio.h>
#include "jni.h"
void foo(int x, char *buf, size_t size)
{
snprintf(buf, size, "Hello from C! x = %d :)", x);
}
JNIEXPORT jstring JNICALL
Java_com_example_test_JniTest_foo(JNIEnv *env, jobject obj, jint x)
{
char buffer[128];
foo((int)x, buffer, sizeof(buffer));
return (*env)->NewStringUTF(env, buffer);
}
JniTest.java:
/* javac -d . JniTest.java */
/* jar cf JniTest.jar com/ */
/* cp JniTest.jar /d/B4A/additionalLibraries/JniTest.jar */
package com.example.test;
public class JniTest {
static
{
System.loadLibrary("JniTest");
}
public JniTest()
{
}
public native String foo(int x);
}
I copied the jar-file into my additional libraries folder. I created a matching xml file. I tried various locations for my .so-file. I used the SLC to generate the java library for B4A. I used NLG to create the entire thing. I even tried loading the .so-file by calling System.load(absPath). Unfortunately, I am constantly getting a "UnsatisfiedLinkError".
(Loading the library via absolute Path seems to work at first (at least it doesn't crash), but subsequent calls to lib-functions yield the same error.)
At first, I used the commands (and variations thereof) seen in the code comments to compile the files and generate the .so- and .jar-files, but now I attached the output of the NLG, simply because that was my latest attempt.
Please note: for NLG i changed the function "foo" to "int foo(int a, int b){ return a+b; }" because NLG didn't compile my use of "snprintf" for some reason. Either way, this also didn't work so I must resort to asking the community ...
I read so many threads on related topics, but i couldn't find out, how to get it to work. I am still very much a novice when it comes to B4A and Android (and Java for that matter). I dabbled with it a few years ago for a graduation project but in my day job i am an embedded systems developer. So working in c is more my wheelhouse.
Therefore, I am hoping that someone out there understands my problem and is willing to help.
Of course, I am willing to give up as much info as possible, so if there is anything unclear or even against the etiquette, please let me know!
B4A Version 9.50 (I bought B4A a couple of years ago ...)
Target: Samsung Galaxy S23 (arm64-v8a)
android-ndk-r27d
Thank you in advance!