summaryrefslogtreecommitdiffstats
path: root/docs/html/training
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-11-25 11:18:43 -0800
committerElliott Hughes <enh@google.com>2014-11-27 10:28:11 -0800
commit85e21bd534d38f8de12e8229865a863f32c30e7a (patch)
tree562ed834f5648245cfaa4fb0ccb9e9794d693af0 /docs/html/training
parentfc793074063ee40b0bc4b4cbf710802123f84251 (diff)
downloadframeworks_base-85e21bd534d38f8de12e8229865a863f32c30e7a.zip
frameworks_base-85e21bd534d38f8de12e8229865a863f32c30e7a.tar.gz
frameworks_base-85e21bd534d38f8de12e8229865a863f32c30e7a.tar.bz2
Mention ProGuard in the JNI documentation.
(cherry picked from commit 8e1bbfe0f1e4dac35b20972a71656e4c9bf437a1) Change-Id: I22731dfb94dcc1271b987ed52914e665704dd378
Diffstat (limited to 'docs/html/training')
-rw-r--r--docs/html/training/articles/perf-jni.jd26
1 files changed, 17 insertions, 9 deletions
diff --git a/docs/html/training/articles/perf-jni.jd b/docs/html/training/articles/perf-jni.jd
index 1a40f62..5a9fa1e 100644
--- a/docs/html/training/articles/perf-jni.jd
+++ b/docs/html/training/articles/perf-jni.jd
@@ -635,20 +635,31 @@ avoid some problems.
<a name="faq_FindClass" id="faq_FindClass"></a>
<h2>FAQ: Why didn't <code>FindClass</code> find my class?</h2>
+<p>(Most of this advice applies equally well to failures to find methods
+with <code>GetMethodID</code> or <code>GetStaticMethodID</code>, or fields
+with <code>GetFieldID</code> or <code>GetStaticFieldID</code>.)</p>
+
<p>Make sure that the class name string has the correct format. JNI class
names start with the package name and are separated with slashes,
such as <code>java/lang/String</code>. If you're looking up an array class,
you need to start with the appropriate number of square brackets and
must also wrap the class with 'L' and ';', so a one-dimensional array of
-<code>String</code> would be <code>[Ljava/lang/String;</code>.</p>
+<code>String</code> would be <code>[Ljava/lang/String;</code>.
+If you're looking up an inner class, use '$' rather than '.'. In general,
+using <code>javap</code> on the .class file is a good way to find out the
+internal name of your class.</p>
+
+<p>If you're using ProGuard, make sure that
+<a href="{@docRoot}tools/help/proguard.html#configuring">ProGuard didn't
+strip out your class</a>. This can happen if your class/method/field is only
+used from JNI.
<p>If the class name looks right, you could be running into a class loader
issue. <code>FindClass</code> wants to start the class search in the
class loader associated with your code. It examines the call stack,
which will look something like:
<pre> Foo.myfunc(Native Method)
- Foo.main(Foo.java:10)
- dalvik.system.NativeStart.main(Native Method)</pre>
+ Foo.main(Foo.java:10)</pre>
<p>The topmost method is <code>Foo.myfunc</code>. <code>FindClass</code>
finds the <code>ClassLoader</code> object associated with the <code>Foo</code>
@@ -656,12 +667,9 @@ class and uses that.</p>
<p>This usually does what you want. You can get into trouble if you
create a thread yourself (perhaps by calling <code>pthread_create</code>
-and then attaching it with <code>AttachCurrentThread</code>).
-Now the stack trace looks like this:</p>
-<pre> dalvik.system.NativeStart.run(Native Method)</pre>
-
-<p>The topmost method is <code>NativeStart.run</code>, which isn't part of
-your application. If you call <code>FindClass</code> from this thread, the
+and then attaching it with <code>AttachCurrentThread</code>). Now there
+are no stack frames from your application.
+If you call <code>FindClass</code> from this thread, the
JavaVM will start in the "system" class loader instead of the one associated
with your application, so attempts to find app-specific classes will fail.</p>