Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling Android NDK function from Unity Script
    primarykey
    data
    text
    <p>So I'm creating an Android app that uses Unity ... I am getting some assetbundle from Unity but I do not know the url before Unity starts. Thus Unity needs to call a function on the Native (Android) side to get the url.</p> <p>I have been lost for awhile on how to do this (the Unity documentation is quite terrible imho). I decided to use the NDK to help me out. Without Unity everything about my library file works out... now the issue is calling these C functions in Unity.</p> <p>Here is my lib:</p> <pre><code> #include &lt;jni.h&gt; #include &lt;string.h&gt; #include &lt;android/log.h&gt; #define DEBUG_TAG "NDK_blahy" extern "C" { jstring Java_com_blah_blah_getURL(JNIEnv * env, jobject this); void Java_com_blah_blah_setURL(JNIEnv * env, jobject this, jstring URL); } jstring url; void Java_com_blah_blah_setURL(JNIEnv * env, jobject this, jstring URL) { url = URL; jboolean isCopy; const char * szLogThis = (*env)-&gt;GetStringUTFChars(env, URL, &amp;isCopy); __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:LC: [%s]", szLogThis); (*env)-&gt;ReleaseStringUTFChars(env, URL, szLogThis); } jstring Java_com_lyfelotto_blah_blah_getURL(JNIEnv * env, jobject this) { return url; } </code></pre> <p>My unity code loads the library just fine (using <code>[DllImport ("libname")]</code>).</p> <p>Now, if I load the function "correctly" like this <code>private static extern jstring Java_com_lyfelotto_blah_blah_getURL(JNIEnv * env, jobject this)</code> bad things happen</p> <p>Have I gone about this the wrong way? (Like I said, all I need to do is get a string). Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload