adb devices连接设备

Android数据线要用好一点的线,有的劣质线只能充电,不能传输数据。

 手机上找到系统版本,触摸5下打开开发者选项

打开usb调试,手机上确认连接fingerprint

>adb devices
List of devices attached
R9HT1078KEJ     unauthorized

如果 adb devices出现unauthorized

先点 "撤销USB调试授权"。手机上再次弹出 "允许USB调试吗?" 确认RSA指纹,点允许。

adb kill-server

adb start-server
adb devices
List of devices attached
R9HT1078KEJ     device

 OK 已授权

安装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();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public 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: 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.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 %%i
	adb shell input tap 269 707
	timeout /T 2 /NOBREAK
	adb shell input tap 584 2099
	timeout /T 2 /NOBREAK
	adb shell input keyevent 4
	timeout /T 2 /NOBREAK
)


Add C and C++ code to your project

vultr云主机

gradle 路径设置

gradle-7.2

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐