package com.example.myapplication
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*class MainActivity :AppCompatActivity(){overridefunonCreate(savedInstanceState: Bundle?){super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)// Example of a call to a native method// 调用Native 方法
sample_text.text =stringFromJNI()}/**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/// 声明自己的本地方法externalfunstringFromJNI(): String
companionobject{// Used to load the 'native-lib' library on application startup.init{// 导入库
System.loadLibrary("native-lib")}}}
// CMake的版本要求
cmake_minimum_required(VERSION 3.4.1)
// SHARED是动态的,STATIC是静态的C/C++文件目录
// 指定生成native-lib库,下面是C/C++文件目录
add_library(# Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp)
// 寻找库
find_library(# Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that# you want CMake to locate.
log )
// 为native-lib链接log库
target_link_libraries(# Specifies the target library.
native-lib
# Links the target library to the log library# included in the NDK.${log-lib})