android kotin支持jni,android上 kotlin 和jni的混合使用

本文介绍了如何在Android应用中结合Kotlin和JNI,通过Java编写JNI入口函数,Kotlin处理业务逻辑。示例展示了控制LED的UI布局和Activity实现,并详细讲解了JNI部分的Java及C代码。最后,讨论了编译SO文件并将其整合到Android项目中的步骤。
摘要由CSDN通过智能技术生成

前言

本文探讨一下kotlin和jni的混合使用,综合考虑,jni的入口函数采用java编程,其他的android业务逻辑采用kotlin编程。c程序内容是自己在ubuntu环境下编译so文件导入工程实现代码安全。

这个ui是用来控制开发板的led的,这里把控制led的代码改为普通的日志输出,不影响普通的使用

1、 UI布局

直接把xml文件贴出来,只是测试demo,写的比较随便

布局里面 就是按钮和checkbox

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context="com.example.act64.myapplication.MainActivity"

tools:layout_editor_absoluteX="0dp"

tools:layout_editor_absoluteY="81dp">

android:id="@+id/sample_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="8dp"

android:text="Hello World!"

app:layout_constraintBottom_toTopOf="@+id/button"

app:layout_constraintHorizontal_bias="0.097"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.0" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:id="@+id/all_btn"

android:text="All ON/OFF" />

android:id="@+id/led1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginBottom="5dp"

android:text="LED1" />

android:id="@+id/led2"

android:layout_width="match_p

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值