Replugin
调试运行插件时,有时候会遇到插件没有安装成功,也没有运行起来,查 log 发现是因为 app 的启动时机问题,发 adb 安装命令时,插件化调试相关的框架还没有起来,导致 apk 没有被安装。可以利用脚本延时再发一次来简单解决:
放到 app 级别的 build.gradle
最后
afterEvaluate { project.tasks.getByName("rpInstallAndRunPluginDebug").doLast {
sleep(5000) def rootDir = project.rootDir def localProperties = new File(rootDir, "local.properties") if (!localProperties.exists()) { return } Properties properties = new Properties() localProperties.withInputStream { instr -> properties.load(instr) } def sdkDir = properties.getProperty('sdk.dir') def adb = "$sdkDir/platform-tools/adb" print("-----"+adb) def installOutput = new ByteArrayOutputStream() exec { def installShell="$adb shell am broadcast -a ${repluginPluginConfig.hostApplicationId}.replugin.install -e path /sdcard/app-debug.apk -e immediately true" commandLine installShell.split(" ") standardOutput = installOutput }
def startOutput = new ByteArrayOutputStream() exec { def startShell="$adb shell am broadcast -a ${repluginPluginConfig.hostApplicationId}.replugin.start_activity -e plugin $repluginPluginConfig.pluginName" commandLine startShell.split(" ") standardOutput = startOutput }
} }
|