方法调用"/>
android native方法调用
adb devices连接设备
Android数据线要用好一点的线,有的劣质线只能充电,不能传输数据。
手机上找到系统版本,触摸5下打开开发者选项,打开usb调试,手机上确认连接fingerprint
安装ndk support插件
* MainActivity.java
package com.example.mysdkdemo;import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;public class MainActivity extends AppCompatActivity {static {System.loadLibrary("mysdkdemo");}public native String getStringFromNative();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}@Overridepublic boolean onTouchEvent(MotionEvent event) {boolean shouldClose = super.onTouchEvent(event);System.out.printf("(%f,%f), keycode=%d", event.getRawX(), event.getRawY(), event.getActionIndex());System.out.println(this.getStringFromNative());return shouldClose;}
}
*mysdkdemo.cpp
#include <jni.h>
#include <string>extern "C"
JNIEXPORT jstring JNICALL
Java_com_example_mysdkdemo_MainActivity_getStringFromNative(JNIEnv *env, jobject thiz) {std::string hello = "Hello from C++";return env->NewStringUTF(hello.c_str());
}
运行,手机上触摸屏幕
* CMakeList.txt
# For more information about using CMake with Android Studio, read the
# documentation: .html# Sets the minimum version of CMake required to build the native library.cmake_minimum_required(VERSION 3.22.1)# Declares and names the project.project("mysdkdemo")# 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.mysdkdemo# Sets the library as a shared library.SHARED# Provides a relative path to your source file(s).mysdkdemo.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.mysdkdemo# Links the target library to the log library# included in the NDK.${log-lib} )
* sim.bat
for /l %%i in (1,1,1048576) do (echo %%iadb shell input tap 269 707timeout /T 2 /NOBREAKadb shell input tap 584 2099timeout /T 2 /NOBREAKadb shell input keyevent 4timeout /T 2 /NOBREAK
)
更多推荐
android native方法调用
发布评论