Migrate orderfile to RegisterNatives.

This commit is contained in:
Dan Albert
2025-09-18 15:30:56 -07:00
committed by Dan Albert
parent 8055c540b6
commit 32ae6dd47a
3 changed files with 26 additions and 5 deletions

View File

@@ -26,11 +26,13 @@ android {
}
buildFeatures {
prefab true
viewBinding true
}
}
dependencies {
implementation project(":base")
implementation libs.appcompat
implementation libs.material
implementation libs.androidx.constraintlayout

View File

@@ -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.

View File

@@ -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;
}