这个项目包含了一个 React Native 应用和一个 Android 原生模块 RPAServiceModule
,
用于执行 UI 自动化任务。
RPAApp/
├── android/
│ └── app/src/main/java/com/rpaapp/
│ ├── RPAServiceModule.kt # 原生模块实现
│ ├── RPAServicePackage.kt # 模块包注册
│ └── MainApplication.kt # 应用入口(已注册模块)
├── src/
│ ├── modules/
│ │ └── RPAServiceModule.ts # JS 端模块接口
│ └── types/
│ └── RPAServiceModule.ts # TypeScript 类型定义
├── App.tsx # 主应用界面
└── package.json
RPAServiceModule
start()
方法,初始化 RPA 服务launchSettings()
launchWifiSettings()
launchBluetoothSettings()
launchAppByPackage(packageName)
cd auto-rpa-app
npm install
npm start
npm run android
在应用中点击各种按钮测试功能:
查看 Android 日志输出:
adb logcat | grep -E "(RPAServiceModule|UIAutomatorHelper)"
RPAServiceModule.kt
中添加新方法:@ReactMethod
fun newMethod(param: String, promise: Promise) {
try {
Log.d(TAG, "New method called with: $param")
// 执行你的逻辑
promise.resolve("Method executed successfully")
} catch (e: Exception) {
promise.reject("METHOD_ERROR", "Method failed: ${e.message}", e)
}
}
src/types/RPAServiceModule.ts
中添加类型定义:export interface RPAServiceModuleInterface {
start(): void;
launchSettings(): Promise<string>;
launchWifiSettings(): Promise<string>;
launchBluetoothSettings(): Promise<string>;
launchAppByPackage(packageName: string): Promise<string>;
newMethod(param: string): Promise<string>;
}
import RPAServiceModule from './src/modules/RPAServiceModule';
const handleNewMethod = async () => {
try {
const result = await RPAServiceModule.newMethod('test parameter');
console.log(result);
} catch (error) {
console.error('Method failed:', error);
}
};
adb logcat | grep "RPAServiceModule"
cd android
./gradlew clean
cd ..
npm run android
npm start -- --reset-cache
adb logcat
命令