我在 Android Studio 中有一个 Android 应用程序。我想用本地语言(c 或 cpp)编写我的加密逻辑。为此,我安装了 Cmake 插件。我从这里得到了 AES 代码。
CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)
add_library( # Sets the name of the library.
aes
# Sets the library as a shared library.
SHARED
src/main/cpp/aes.c )
add_library( # Sets the name of the library.
analyze
# Sets the library as a shared library.
SHARED
src/main/cpp/analyze.c )
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 )
target_link_libraries( # Specifies the target library.
aes
# Links the target library to the log library
# included in the NDK.
${log-lib} )
target_link_libraries( # Specifies the target library.
analyze
# Links the target library to the log library
# included in the NDK.
${log-lib} )
这是我用来引用包含库并使用其中定义的函数的类。
分析.c
#include <stdint.h>
#include "aes.h"
#include <jni.h>
void AES128_ECB_encrypt(const uint8_t*,const uint8_t*,uint8_t*);
JNIEXPORT jstring JNICALL
Java_cppandroid_madhu_com_cppandroid_MainActivity_invokeAESFunction(JNIEnv *env,
jobject instance) {
unsigned char myString [] = "This is my string";
unsigned char mykey[]="this is key";
//unsigned char encryp[];
const uint8_t *input = &myString[0];
const uint8_t *key =&mykey[0];
uint8_t *output;
AES128_ECB_encrypt(input, key, output);
return output;
}
我面临的问题是,当我从 MainActivity 调用 invokeAESFunction() 时,我收到一个名为“未定义对 AES128_ECB_encrypt() 的引用”的错误。有人请帮助我。