赞
踩
图示如下:
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html.
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.
# Sets the minimum CMake version required for this project.
cmake_minimum_required(VERSION 3.22.1)
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
# Since this is the top level CMakeLists.txt, the project name is also accessible
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
# build script scope).
# 备注:如直接采用AS创建的JNI项目,会将project name作为so库的名字
project("TvSettings")
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
#
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
# is preferred for the same purpose.
#
# In order to load a library into your app from Java/Kotlin, you must call
# System.loadLibrary() and pass the name of the library defined here;
# for GameActivity/NativeActivity derived applications, the same library name must be
# used in the AndroidManifest.xml file.
# 备注:此处罗列你的 c / cpp 文件
add_library(jnimotor SHARED
# List C/C++ source files with relative paths to this CMakeLists.txt.
JniMotor.c)
# Specifies libraries CMake should link to your target library. You
# can link libraries from various origins, such as libraries defined in this
# build script, prebuilt third-party libraries, or Android system libraries.
# 备注:此处第一个参数jnimotor,就是生产的库的名字:libjnimotor.so
target_link_libraries(jnimotor
# List libraries link to the target library
android
log)
//略……
#include <jni.h>
#include <android/log.h>
#define TAG "JniMonitor"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
//略……
static int motorioctl(int des, int step)
{
//略……
}
JNIEXPORT jint JNICALL Java_com_android_tv_settings_device_displaysound_aw_1displaysound_JniMotor_ioctl
(JNIEnv *env, jclass clas, jint des, jint step){
int i = des;
int j = step;
return motorioctl(i, j);
}
android {
…… 略 ……
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.22.1'
}
}
…… 略 ……
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。