Android aar 文件到底是什么 August 11, 2023 6 - Android 打包编译, 6.2 - 简单好用的 gradle 云编译设置 本文总阅读量次 作者: 朕小猫与GPT4 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107task downloadApk { doLast { def remoteApkPath = "/home/jason/AndroidStudioProjects/ncmusic/app/build/outputs/apk/debug/app-debug.apk" def localApkDir = System.getProperty("user.home") + "/Downloads/" def localApkPath = localApkDir + "app-debug.apk" // 创建本地目录 new File(localApkDir).mkdirs() // 使用 scp 下载远程 APK 文件到本地 def command = "sshpass -p 'password' scp jason@192.168.1.100:${remoteApkPath} ${localApkPath}" println "Executing command: ${command}" exec { commandLine 'bash', '-c', command } }}task installAndStart { dependsOn downloadApk doLast { def localApkPath = System.getProperty("user.home") + "/Downloads/app-debug.apk" // 确保 adb 可用 def adbPath = '/Users/jason/Library/Android/sdk/platform-tools/adb' if (!new File(adbPath).exists()) { throw new GradleException("adb command not found at ${adbPath}! Please ensure Android SDK is properly installed.") } // 安装 APK def installCommand = "${adbPath} install -r ${localApkPath}" try { exec { commandLine 'bash', '-c', installCommand } } catch (Exception e) { throw new GradleException("Failed to install APK: ${e.message}") } // 提取包名 def manifestFile = file("${rootProject.projectDir}/app/src/main/AndroidManifest.xml") def packageName = "" if (manifestFile.exists()) { manifestFile.eachLine { line -> if (line.contains("package=")) { packageName = line.split('package=')[1].split('"')[1] } } if (packageName == "") { throw new GradleException("Failed to extract package name from AndroidManifest.xml") } } else { throw new GradleException("AndroidManifest.xml file not found!") } // 启动应用 def launchCommand = "${adbPath} shell monkey -p ${packageName} -c android.intent.category.LAUNCHER 1" println "Executing command: ${launchCommand}" try { exec { commandLine 'bash', '-c', launchCommand } } catch (Exception e) { throw new GradleException("Failed to launch application: ${e.message}") } }}task downloadBuild { doLast { subprojects.each { subproject -> def remoteRootPath = "/home/jason/AndroidStudioProjects/" def remoteDirPath = remoteRootPath + "${rootProject.name}/${subproject.name}/build" def localDirPath = "${subproject.projectDir}" // 创建本地目录 new File(localDirPath).mkdirs() // 使用 rsync 同步远程文件到本地 def command = "sshpass -p 'password' rsync -avz --delete jason@192.168.1.100:${remoteDirPath} ${localDirPath}" println "Executing command: ${command}" exec { commandLine 'bash', '-c', command } } }}task remoteBuild { doLast { // 远程构建命令 def command = "sshpass -p 'password' ssh jason@192.168.1.100 'cd /home/jason/AndroidStudioProjects/ncmusic/ && ./gradlew assembleDebug'" exec { commandLine 'bash', '-c', command } }}// 定义一个任务来执行远程构建、下载 APK、安装并启动应用,然后同步构建产物task buildDownloadInstallAndStart { dependsOn remoteBuild finalizedBy installAndStart, downloadBuild} Newer Android aar 文件到底是什么 Older 协程核心概念的理解与应用(一)--翻译翻译什么是 CoroutineScope