/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_kissdream_androidjnitest_myJNIUtils */
#ifndef _Included_com_kissdream_androidjnitest_myJNIUtils
#define _Included_com_kissdream_androidjnitest_myJNIUtils
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_kissdream_androidjnitest_myJNIUtils
* Method: getName
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_kissdream_androidjnitest_myJNIUtils_getName
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
#include "com_kissdream_androidjnitest_myJNIUtils.h"
JNIEXPORT jstring JNICALL Java_com_kissdream_androidjnitest_myJNIUtils_getName
(JNIEnv * env, jobject obj){
//如果是用C语言格式就用这种方式
// return (*env)->NewStringUTF(env,"Kiss dream");
//如果是用C语言格式就用这种方式
return env->NewStringUTF((char *)"Kiss dream");
}
public class myJNIUtils {
static {
//名字注意,需要跟你的build.gradle ndk节点下面的名字一样
System.loadLibrary("NameProvider");
}
//JNI接口需要用native关键字修饰
public native String getName();
}
ndk {
moduleName "NameProvider"
}
Error:Execution failed for task ':app:compileDebugNdk'. > Error: Flag android.useDeprecatedNdk is no longer supported and will be removed in the next version of Android Studio. Please switch to a supported build system. Consider using CMake or ndk-build integration. For more information, go to: https://d.android.com/r/studio-ui/add-native-code.html#ndkCompile To get started, you can use the sample ndk-build script the Android plugin generated for you at: /Users/apple/Desktop/AndroidJNITest/app/build/intermediates/ndk/debug/Android.mk Alternatively, you can use the experimental plugin: https://developer.android.com/r/tools/experimental-plugin.html To continue using the deprecated NDK compile for another 60 days, set android.deprecatedNdkCompileLease=1512283120054 in gradle.properties
// 使用Cmake工具
externalNativeBuild {
cmake {
cppFlags ""
//生成多个版本的so文件
abiFilters 'arm64-v8a','armeabi-v7a','x86','x86_64'
}
}
// 配置CMakeLists.txt路径
externalNativeBuild {
cmake {
path "CMakeLists.txt" // 设置所要编写的c源码位置,以及编译后so文件的名字
}
}
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
#CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)
# 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.
add_library( # Sets the name of the library.
# 设置so文件名称.
NameProvider
# Sets the library as a shared library.
SHARED
# 设置这个so文件为共享.
# Provides a relative path to your source file(s).
# 设置这个so文件为共享.
src/main/jni/getName.cpp)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
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 )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
# 制定目标库.
NameProvider
# Links the target library to the log library
# included in the NDK.
${log-lib} )
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有