工程先用eclipse生成class目录,转到class目录下执行: javap -s com.example.hellojni.MainActivity

Compiled from "MainActivity.java"
public class com.example.hellojni.MainActivity extends android.app.Activity {
  static {};
    Signature: ()V

  public com.example.hellojni.MainActivity();
    Signature: ()V

  protected void onCreate(android.os.Bundle);
    Signature: (Landroid/os/Bundle;)V

  public boolean onCreateOptionsMenu(android.view.Menu);
    Signature: (Landroid/view/Menu;)Z

  public native java.lang.String stringFromJNI(); //native 方法
    Signature: ()Ljava/lang/String;  //签名

  public native int max(int, int); //native 方法
    Signature: (II)I    //签名
}

 

最后附上com/example/hellojni/MainActivity.java代码:

 1 package com.example.hellojni;
 2 import android.os.Bundle;
 3 import android.app.Activity;
 4 import android.util.Log;
 5 import android.view.Menu;
 6 import android.widget.TextView;
 7 
 8 public class MainActivity extends Activity {
 9     @Override
10     protected void onCreate(Bundle savedInstanceState) {
11         super.onCreate(savedInstanceState);
12         setContentView(R.layout.activity_main);
13         TextView  tv = new TextView(this);
14         tv.setText( stringFromJNI() );
15         setContentView(tv);        
16         Log.d("JNI", "max = " + max(10, 100));
17     }
18     @Override
19     public boolean onCreateOptionsMenu(Menu menu) {
20         getMenuInflater().inflate(R.menu.main, menu);
21         return true;
22     }
23     
24     public native String  stringFromJNI();
25     public native int max(int a,int b); 
26     static {
27         System.loadLibrary("hellojni");
28     }
29 }

 

相关文章:

  • 2021-07-16
  • 2021-09-12
  • 2021-12-03
  • 2022-12-23
  • 2021-10-15
猜你喜欢
  • 2022-03-08
  • 2021-07-27
  • 2021-08-14
  • 2021-09-08
  • 2021-08-02
  • 2021-06-16
  • 2022-12-23
相关资源
相似解决方案