博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Android 开发日常

Posted on 2022-04-27 09:04  pencilCool  阅读(33)  评论(0编辑  收藏  举报

Android

shortcut:
https://developer.android.com/studio/intro/keyboard-shortcuts

maven 国内mirror

buildscript {
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
}
}

allprojects {
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
google()
jcenter()
}
}

命令行中打包的时候,切换java 的版本

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
./gradlew assembleRelease --stacktrace

无线控制app

adb tcpip 5555
adb connect 10.8.28.213:5555

RN android 真机调试

adb reverse tcp:8081 tcp:8081

android 模拟器连网

export ANDROID_SDK=$HOME/Library/Android/sdk
export PATH=$ANDROID_SDK/emulator:$ANDROID_SDK/tools:$PATH

emulator -list-avds
emulator @Nexus_S_API_30 -dns-server 8.8.8.8

emulator -avd NameOfYourDevice -dns-server 8.8.8.8 // 这种写法有问题

android app 抓包工具

https://techwiser.com/wireshark-alternatives-for-android/

录屏

https://github.com/Genymobile/scrcpy
brew install scrcpy

小米手机设置 proxyman (charles 代理)

#!/usr/bin/env python
import ipaddress
import uiautomator2 as u2
import subprocess


def get_ip():
    args = "ifconfig | grep 'inet.*netmask.*broadcast' | awk '{print $2}'"
    out, err = subprocess.Popen(
        args, shell=True, stdout=subprocess.PIPE).communicate()
    out = out.decode('UTF-8').strip("\n")
    return out


ip_address = get_ip()
d = u2.connect()  # connect to device
# d = u2.connect_adb_wifi("10.8.28.213")
print(d.info)

bundle_id = "com.android.settings"
d.app_stop(bundle_id)
d.app_start(bundle_id)
d(text="WLAN").click()
d(resourceId="com.android.settings:id/preference_detail").click()

d(resourceId="com.android.settings:id/proxy_settings_title").click()

d(text="手动").click()

d.swipe_ext("up", scale=0.8) 

d.set_clipboard(ip_address)

d(resourceId="com.android.settings:id/proxy_hostname").send_keys("")
d(resourceId="com.android.settings:id/proxy_hostname").long_click()
d(text="粘贴").click()

d.set_clipboard("9090")
d(resourceId="com.android.settings:id/proxy_port").send_keys("")
d(resourceId="com.android.settings:id/proxy_port").long_click()
d(text="粘贴").click()

d(resourceId="android:id/button2").long_click()

xml = d.dump_hierarchy()
print(xml)