Android管理adb命令的插件

54 阅读1分钟

先上成果,一条命令对应一个gradle task,后续只需要带点击对应的task即可执行这个命令,当然你可以动态修改文件之后执行:

image.png

其中配置文件:

    ```
// ADB Command Plugin Configuration
// 这个文件包含了ADB插件的所有配置,可以被其他模块引用

// 添加buildSrc插件的classpath
buildscript {
    dependencies {
        classpath files("buildSrc/build/libs/buildSrc.jar")
    }
}

// 应用ADB插件
apply plugin: 'AdbCommandPlugin'

// 配置ADB命令
adbCommands {
    command("installApk", "adb install -r -t XXX.apk")
    command("uninstallVacuum", "adb uninstall XXX")
    command("uninstallOs", "adb uninstall XXXr")
    command("uninstallMap", "adb uninstall XXX")
    command("forceStopVacuum", "adb shell am force-stop XXX")
    command("forceStopOs", "adb shell am force-stop XXX")
    command("forceStopMap", "adb shell am force-stop XXX")
    command("scrcpy", "scrcpy.exe")
    command("startOs", "adb shell am start -n XXX")
    command("startVacuum", "adb shell am start -n XXX")
}
//发布到本地maven仓库
// ../gradlew :publishToMavenLocal
//更新task任务
//../gradlew tasks --group=adb

在使用的时候需要在app模块的build.gradle文件中导入这个配置文件

// 引入ADB插件配置
apply from: "../buildSrc/adb-config.gradle"

项目工程地址:github.com/lycodeman/A…