首页 > 代码库 > 01_c++下jni开发说明

01_c++下jni开发说明

技术分享

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="helloincpp"
        android:text="调用C++函数" />

</RelativeLayout>
package com.itheima.cppjni;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void helloincpp(View v){
        Toast.makeText(this, hellocpp(), Toast.LENGTH_SHORT).show();
    }
    public native String hellocpp();
}

Java的代码咱们就写好了.接下来是写C++的代码.


 

技术分享

Android Tools->Add Native Support

技术分享

技术分享

技术分享

 

01_c++下jni开发说明