mirror of
https://github.com/android/ndk-samples
synced 2025-11-08 09:06:14 +08:00
Migrate orderfile to RegisterNatives.
This commit is contained in:
@@ -26,11 +26,13 @@ android {
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
prefab true
|
||||
viewBinding true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(":base")
|
||||
implementation libs.appcompat
|
||||
implementation libs.material
|
||||
implementation libs.androidx.constraintlayout
|
||||
|
||||
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.22.1)
|
||||
project(OrderfileDemo CXX)
|
||||
|
||||
include(AppLibrary)
|
||||
find_package(base CONFIG REQUIRED)
|
||||
|
||||
# We have setup build variables that you can just comment or uncomment to use.
|
||||
# Make sure to have only one build variable uncommented at a time.
|
||||
@@ -13,7 +14,7 @@ set(GENERATE_PROFILES ON)
|
||||
#set(USE_PROFILE "${CMAKE_SOURCE_DIR}/demo.orderfile")
|
||||
|
||||
add_app_library(orderfiledemo SHARED orderfile.cpp)
|
||||
target_link_libraries(orderfiledemo log)
|
||||
target_link_libraries(orderfiledemo PRIVATE base::base log)
|
||||
|
||||
if(GENERATE_PROFILES)
|
||||
# Generating profiles requires any optimization flag aside from -O0.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <android/log.h>
|
||||
#include <base/macros.h>
|
||||
#include <errno.h>
|
||||
#include <jni.h>
|
||||
#include <linux/limits.h>
|
||||
@@ -46,9 +47,26 @@ void DumpProfileDataIfNeeded(const char* temp_dir) {
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_example_orderfiledemo_MainActivity_runWorkload(JNIEnv* env,
|
||||
jobject /* this */,
|
||||
jstring temp_dir) {
|
||||
void RunWorkload(JNIEnv* env, jobject /* this */, jstring temp_dir) {
|
||||
DumpProfileDataIfNeeded(env->GetStringUTFChars(temp_dir, 0));
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* _Nonnull vm,
|
||||
void* _Nullable) {
|
||||
JNIEnv* env;
|
||||
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
jclass c = env->FindClass("com/example/orderfiledemo/MainActivity");
|
||||
if (c == nullptr) return JNI_ERR;
|
||||
|
||||
static const JNINativeMethod methods[] = {
|
||||
{"runWorkload", "(Ljava/lang/String;)V",
|
||||
reinterpret_cast<void*>(RunWorkload)},
|
||||
};
|
||||
int rc = env->RegisterNatives(c, methods, arraysize(methods));
|
||||
if (rc != JNI_OK) return rc;
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user