JNI笔记

1 java数据类型
boolean 1bit
byte 1字节
char 2字节
short 2字节
int 4字节
float 4字节
long 8字节
double 8字节

2 c语言数据类型
char 1字节
short 2字节
int 4字节
float 4字节
long 4字节
double 8字节
unsigned 无符号 0~255 (2的8次方=256)
signed 有符号 -128~127
void 无类型,任意类型

3

4 JNI - C

  1. build.gradle:
    添加ndk{
    moduleName "Hello"
    abiFilters "armeabi" "armeabi-v7a" "x86"
    }
  2. java文件夹下:
    创建java class
    定义native方法:
    '''
    package org.tensorflow.lite.examples.classification;

public class JNI {
{
System.loadLibrary("Hello");
}
// 定义native方法,调用c代码
public native String sayHello();
}
}
'''
3.main文件夹下创建与java同级的目录:jni,存放c代码,并新建.c文件
写c代码

原文地址:https://www.cnblogs.com/shendaw/p/13607360.html