Android 常用命令行总结记录

168 阅读1分钟

1. Logcat

cls  清屏

打印日志到指定文件
adb logcat > /Users/YourUsername/Desktop/log.txt

ctrl +c 停止


拉取:ADB anr 日志
adb bugreport anr_0203.zip


2.gradle命令行

  • ./gradlew :app:dependencies 查看依赖
  • ./gradlew build --info 编译并且打印日志
  • ./gradlew clean --refresh-dependencies build 强制更新最新依赖,清除构建并构建
  • ./gradlew assembleRelease./gradlew aR 编译并打Release的包
  • ./gradlew assembleDebug debug包
  • ./gradlew assemble 所有包
  • ./gradlew app:dependencies --configuration compile 编译时依赖库

3.Git

  • git status 查看代码状态
  • git add . 添加所有
  • git commit -m '增加提交日志'
  • git push 推送
  • git pull 拉取代码
  • git fetch 拉取各个分支代码
  • git brach 列出分支
  • git checkout xxx 切换分支

adb tcpip 5555 打开555 端口

adb shell ip -f inet addr show wlan0 查看地址

adb connect 192.168.2.21:5555 连接指定端口

5. adb 安装apk

adb install xxx.apk (绝对路径)

6.查询 so 是谁引用的方法

// 在项目 build.gradle 或 app/build.gradle 中添加
tasks.whenTaskAdded { task ->
    // 匹配所有 merge<Flavor><BuildType>NativeLibs 任务
    if (task.name.matches(/merge.*NativeLibs/)) {
        task.doFirst {
            println("------- [${task.name}] start scanning so files -------")

            // 遍历所有输入文件
            it.inputs.files.each { file ->
                printSoFiles(file)
            }

            println("------- [${task.name}] end scanning so files -------")
        }
    }
}

// 递归查找 .so 文件
def printSoFiles(File file) {
    if (file == null || !file.exists()) return

    if (file.isDirectory()) {
        file.listFiles()?.each { printSoFiles(it) }
    } else if (file.name.endsWith(".so")) {
        println("Found .so: ${file.absolutePath}")
    }
}