Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, you can use the same JNI signature in many applications. Your class may not belong to the default package of the application, as defined in AndroidManifest.xml. So what? <hr /> <strong>Example:</strong></p> <p>Start with HelloJni sample from NDK (in Eclipse, use Import -> Android -> existing Android Code, and point to the ${android-ndk-root}/samples/hello-jni).</p> <p>Build it and run on device or emulator.</p> <p>Open a new Android Application project, call it TestCrossJni. The package name for our app will be: test.cross.jni - no relation to <code>com.example.hellojni</code>!</p> <p>Choose "Create Activity" -> create Blank Activity.</p> <p>Add new Java class to this project (<code>src/com/example/hellojni/HelloJni.java</code>): </p> <pre><code>package com.example.hellojni; public class HelloJni { public static String gets() { return stringFromJNI(); } /* A native method that is implemented by the * 'hello-jni' native library, which is packaged * with this application. */ private native String stringFromJNI(); /* this is used to load the 'hello-jni' library on application * startup. The library has already been unpacked into * /data/data/com.example.hellojni/lib/libhello-jni.so at * installation time by the package manager. */ static { System.load("/data/data/com.example.hellojni/lib/libhello-jni.so"); } } </code></pre> <p>Edit <code>res/layout/activity_main.xml</code>: replace </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;line 12 <code>android:text="@string/hello_world" /&gt;</code></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;with <code>android:id="@+id/hello_world" /&gt;</code></p> <p>In <code>src/test/cross/jni/MainActivity.java</code>, add the following after </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;line 12 <code>setContentView(R.layout.activity_main);</code></p> <pre><code>((android.widget.TextView)findViewById(R.id.hello_world)).setText(com.example.hellojni.HelloJni.gets()); </code></pre> <p>Profit!</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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