Commit 14ce6561 by Fear1ess

4/2

parent 0dfcd92b
...@@ -14,14 +14,6 @@ android { ...@@ -14,14 +14,6 @@ android {
versionName "1.0" versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
} }
buildTypes { buildTypes {
...@@ -30,12 +22,7 @@ android { ...@@ -30,12 +22,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }
} }
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
......
# 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.
cmake_minimum_required(VERSION 3.10.2)
# Declares and names the project.
project("sdktestdemo")
# 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.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.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.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
\ No newline at end of file
#include <jni.h>
#include <string>
extern "C" JNIEXPORT jstring JNICALL
Java_com_reyun_sdktestdemo_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
\ No newline at end of file
...@@ -19,12 +19,11 @@ public class MainActivity extends AppCompatActivity { ...@@ -19,12 +19,11 @@ public class MainActivity extends AppCompatActivity {
// Example of a call to a native method // Example of a call to a native method
TextView tv = findViewById(R.id.sample_text); TextView tv = findViewById(R.id.sample_text);
tv.setText(stringFromJNI()); tv.setText("hello world!");
} }
/** /**
* A native method that is implemented by the 'native-lib' native library, * A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application. * which is packaged with this application.
*/ */
public native String stringFromJNI();
} }
\ No newline at end of file
...@@ -22,7 +22,6 @@ public class MyApplication extends Application { ...@@ -22,7 +22,6 @@ public class MyApplication extends Application {
public void onWdId(String wdId) { public void onWdId(String wdId) {
Log.d(TAG, "onWdId: " + wdId); Log.d(TAG, "onWdId: " + wdId);
} }
/* /*
@Override @Override
public void onError(String errorMsg) { public void onError(String errorMsg) {
......
...@@ -9,18 +9,18 @@ if(${CMAKE_ANDROID_ARCH_ABI} STREQUAL "arm64-v8a") ...@@ -9,18 +9,18 @@ if(${CMAKE_ANDROID_ARCH_ABI} STREQUAL "arm64-v8a")
wd_syscall64.s) wd_syscall64.s)
elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi-v7a") elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi-v7a")
set(ARCH_DEPENDED1_SRC set(ARCH_DEPENDED_SRC
wd_syscall32.s) wd_syscall32.s)
endif() endif()
set(CMAKE_CXX_FLAGS_RELEASE "-fvisibility=hidden -O3 -fno-unwind-tables") set(CMAKE_CXX_FLAGS_RELEASE "-fvisibility=hidden -O3 -fno-unwind-tables -flto")
add_library( add_library(
wdun wdun
SHARED SHARED
core.cpp core.c
wd_syscall.cpp wd_syscall.c
jni_helper.cpp jni_helper.c
${ARCH_DEPENDED_SRC} ${ARCH_DEPENDED_SRC}
) )
......
...@@ -15,15 +15,16 @@ IMPORTWDSYSCALL ...@@ -15,15 +15,16 @@ IMPORTWDSYSCALL
#define WDMAIN_GETWDID_METHOD_SIG "()Ljava/lang/String;" #define WDMAIN_GETWDID_METHOD_SIG "()Ljava/lang/String;"
jstring jni_get_wdid(JNIEnv* env, jobject thiz) { jstring jni_get_wdid(JNIEnv* env, jobject thiz) {
} }
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
int pid = WDSYSCALL(SYS_getpid); int pid = WDSYSCALL(SYS_getpid);
JNIEnv* env = NULL; JNIEnv* env = NULL;
if(vm->GetEnv((void**)&env, JNI_VERSION_1_6) == JNI_TRUE) { if((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) == JNI_TRUE) {
jclass cls = env->FindClass(WDMAIN_CLASS_NAME); jclass cls = (*env)->FindClass(env, WDMAIN_CLASS_NAME);
JNINativeMethod methods[] = {{WDMAIN_GETWDID_METHOD_NAME, WDMAIN_GETWDID_METHOD_SIG, (void*)jni_get_wdid}}; JNINativeMethod methods[] = {{WDMAIN_GETWDID_METHOD_NAME, WDMAIN_GETWDID_METHOD_SIG, (void*)jni_get_wdid}};
env->RegisterNatives(cls, methods, sizeof(methods)/sizeof(JNINativeMethod)); (*env)->RegisterNatives(env, cls, methods, sizeof(methods)/sizeof(JNINativeMethod));
} }
cJSON* json = cJSON_CreateObject(); cJSON* json = cJSON_CreateObject();
cJSON_AddStringToObject(json, "name", "zhanglei"); cJSON_AddStringToObject(json, "name", "zhanglei");
......
...@@ -9,14 +9,14 @@ ...@@ -9,14 +9,14 @@
void wdCheckException(JNIEnv* env); void wdCheckException(JNIEnv* env);
char wdGetMethodRetType(const char* sig); char wdGetMethodRetType(const char* sig);
inline char wdGetFieldType(const char* sig) { return *sig; } char wdGetFieldType(const char* sig) { return *sig; }
jvalue wdGetStaticField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig); jvalue wdGetStaticField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig);
jvalue wdGetField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig); jvalue wdGetField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig);
void wdSetStaticField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jvalue value); void wdSetStaticField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jvalue value);
void wdSetField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jvalue value); void wdSetField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jvalue value);
jobject wdNewObject(JNIEnv* env, const char* clsName, const char* methodSig, ...); jobject wdNewObject(JNIEnv* env, const char* clsName, const char* methodSig, ...);
jvalue wdCallStaticMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, ...); jvalue wdCallStaticMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, va_list args);
jvalue wdCallMethod(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, ...); jvalue wdCallMethod(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, va_list args);
jboolean wdCallStaticBooleanMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, ...); jboolean wdCallStaticBooleanMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, ...);
jbyte wdCallStaticByteMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, ...); jbyte wdCallStaticByteMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, ...);
jchar wdCallStaticCharMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, ...); jchar wdCallStaticCharMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, ...);
......
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
#endif #endif
#define IMPORTWDSYSCALL \ #define IMPORTWDSYSCALL \
__attribute__((visibility("hidden"))) extern "C" int wd_syscall32(int cmd, ...);\ __attribute__((visibility("hidden"))) extern int wd_syscall32(int cmd, ...);\
__attribute__((visibility("hidden"))) extern "C" int wd_syscall64(int cmd, ...); __attribute__((visibility("hidden"))) extern int wd_syscall64(int cmd, ...);
extern "C" int wd_set_errno(int n); int wd_set_errno(int n);
#endif //REYUNSDK_WD_SYSCALL_H #endif //REYUNSDK_WD_SYSCALL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment