android 相关

android 相关

Posted by nomadli on January 4, 2016

Gradle

  • 执行:Settings.gradle->config app.gradle->config 依赖.gradle->afterEvaluate 注册afterEvaluate顺序.gradle->执行任务
  • buildscript 模块gradle 自己本身的配置

已知问题

  • 单dex 65535方法数限制,使用MultiDex
  • 线性内存分配LinearAlloc 2.3以下5M,2.3以上8M,dalvik LinearAlloc 16M, art后无限制

ART

  1. 实现Davik虚拟机全部运行时接口

ADB 命令

  • 开启USB调试
  • 发现不了机器 system_profiler SPUSBDataType grep Vendor ID -> .android/adb_usb.ini -> adb kill-server -> adb start-server
  • 音量+ 电影, recover fastboot normal选择, 音量-确定, 无命令(电源+音量-)
  • adb kill-server 终止 adb 服务进程
  • adb start-server 重启 adb 服务进程
  • adb root 以 root 权限重启 adb 服务
  • adb get-state 判断设备状态
  • adb devices 显示连接到计算机的设备
  • adb get-serialno 获取设备的序列号
  • adb reboot 重启设备
  • adb reboot bootloader 重启设备进入fastboot模式
  • adb reboot recovery 重启设备进入recovery模式
  • adb [-d -e -s ] 发送命令到指定设备
  • adb get-serialno
  • adb -s xxxx shell
  • cat /system/build.prop grep “product”
  • cat /sys/class/net/wlan0/address 获取 wifi mac 地址
  • cat /proc/cpuinfo 获取 cpu 信息
  • cat /system/build.prop 获取设备编译属性(手机属性和手机配置信息)
  • cat /data/misc/wifi/*.conf 获取 wifi 配置信息

native 内存分析

  • adb shell getprop ro.build.type –>user 否则使用模拟器
  • 需要旧版ndk 高版本整合了ddms
  • 将android sdk 目录下的tools 替换为 旧版
  • 直接运行ddms,提示端口占用错误,修改端口(Preferences->port of select vm)
  • /User/name/.android/ddms.cfg 添加 native=true
  • adb root
  • adb shell setprop libc.debug.malloc 1 (1检测内存泄漏 5new用0xeb填充,free用0xef填充 10new前后不可写,检测overruns 20 SDK模拟器上检测内存)
  • adb shell getprop libc.debug.malloc 检测是否成功
  • adb shell stop
  • adb shell start
  • adb shell ps grep 进程名称 获取pdi

gitlab runner

#!/bin/bash

function useage() {
    echo "-r install gitlab-runner"
    echo "-a install android build system"
    exit 1
}

while getopts ":a" opt
do
    case $opt in
        r)
            curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash
            yum install -y gitlab-runner
            gitlab-runner register
            #vi /etc/gitlab-runner/config.toml
            ;;
        a)
            rpm -ivh xxx.jdk8.rpm
            https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip?utm_source=androiddevtools&utm_medium=website
            https://downloads.gradle-dn.com/distributions/gradle-7.0-all.zip
            #https://services.gradle.org/distributions/ 5.x版本ANDROID_NDK_HOME需要直接指向ndk-bundle
            cat >> "/etc/profile" <<EOF
#android
export JAVA_HOME=/usr/lib/jvm/java-openjdk
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

export GRADLE_HOME=/xxx/android/gradle
export ANDROID_HOME=/xxx/android
export ANDROID_NDK_HOME=/xxx/android/ndk
export PATH=$PATH:${GRADLE_HOME}/bin:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platforms
EOF
            source /etc/profile

            mkdir -p /home/user/.android
            touch /home/user/.android/repositories.cfg
            sdkmanager --list --verbose
            sdkmanager "add-ons;addon-google_apis-google-24"
            sdkmanager "build-tools;29.0.3"
            sdkmanager "build-tools;28.0.3"
            sdkmanager "cmdline-tools;latest"
            sdkmanager "cmake;3.10.2.4988404"
            sdkmanager "extras;google;m2repository"
            sdkmanager "extras;google;webdriver"
            sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2"
            sdkmanager "platforms;android-30"
            sdkmanager "ndk-bundle"

            #https://docs.sonarqube.org/latest/analyzing-source-code/scanners/sonarscanner/
            wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.7.0.2747-linux.zip
            #sonar 8.9 支持java8 sonar9只支持java11
            unzip sonar-scanner-cli-xxx.zip
            mv sonar-scanner-cli-xxx sonar-scanner-cli
            vi sonar-scanner-cli/conf/sonar-scanner.properties
                sonar.host.url=http://xxxx:9000
                sonar.sourceEncoding=UTF-8
                sonar.verbose=true
            cat >> "/etc/profile" <<EOF
#sonar
export SONAR_HOME=/xxx/sonar-scanner-cli
export PATH=$PATH:${SONAR_HOME}/bin
EOF
            source /etc/profile
            sonar-scanner -h
            sonar-scanner -Dsonar.login=token

            git clone androidproject.git
            cat >> "androidproject/sonar-project.properties" <<EOF
sonar.projectKey=my:sonar项目提示的key
sonar.projectName=指定项目名称,不设置使用projectKey
sonar.projectVersion=项目版本可以不设置
sonar.sources=sonar-project.properties文件在项目工程文件的相对位置,默认是 `.`
sonar.sourceEncoding=UTF-8 默认系统编码
EOF
            ;;
        ?)
            useage
            ;;
    esac
done

docker export android -o /vdb/android_image.tar
cat android_image.tar | docker import - android:1

useage

#.gitlab-ci.yml
#stages:
#    - build
#    - deploy
#
#release_build:
#    stage: build
#    when: manual
#    tags:
#        - 10-228-130-189
#    script:
#        - ./gradlew assembleRelease
#
#debug_build:
#    stage: build
#    when: manual
#    tags:
#        - 10-228-130-189
#    script:
#        - ./gradlew assembleDebug
#        - cd x/build/outputs/apk/x/debug
#        - curl -k -X POST -b 'Token=xxxx' -F 'file=@portal-xx-debug.apk' https://xxx/api/v1/app/upload


#index=0
#for i in $@
#do
#    let index+=1
#    if [ ${index} -eq 1 ]; then
#        continue
#    fi
#    echo $i
#done

#docker run -itd -p 23:22 -v /vdb/android/sdk:/root/android -v /vdb/android/cache:/root/.android -v /vdb/android/bin:/tools --name centos7_android centos:7