通过adb连接手机或者模拟器进行python开发

adb remote control

sl4a 可以开启python-server,通过远程adb进行开发、调试,然后发布到手机

在pc上通过adb, 连接手机上的python-server

public server开启不了
只能usb开始private server,但是连着usb后,手机自动卸载sdcard

期间一直找不到设备,后来发现是usb驱动没装好

usb连接手机,开启模拟器

  1. 查看当前连接的手机或模拟器

    c:/>adb devices
    List of devices attached
    015EF45B0D01200F        device
    emulator-5554   device
    
  2. 连接指定机器安装 sl4a,已经下载 sl4a_r6.apk

    c:/>adb -s <name> install sl4a_r6.apk
    
  3. 进入机器shell

    c:/>adb -s <name> shell
    $
    
  4. 开启private server

    手机的话su切换到高级用户

    $ su  
    #
    

    Start a private server.

    # am start -a com.googlecode.android_scripting.action.LAUNCH_SERVER -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher
    

    Start a private server on a particular port (in this case, 45001)

    # am start -a com.googlecode.android_scripting.action.LAUNCH_SERVER -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher --ei com.googlecode.android_scripting.extra.USE_SERVICE_PORT 45001
    

    Start a public server.

    # am start -a com.googlecode.android_scripting.action.LAUNCH_SERVER -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher --ez com.googlecode.android_scripting.extra.USE_PUBLIC_IP true
    
  5. 退出shell

    # exit
    $ exit
    c:/>
    
  6. 连接手机/模拟器python-server

    c:/> adb -s <name> forward tcp:9999 tcp:45001
    c:/> set AP_PORT=9999
    
  7. 开始编写python代码

    c:/> edit hello.py
    import android
    droid=android.Android()
    droid.makeToast("hello")
    
  8. 执行python

    c:/> python hello.py
    

模拟器加载sdcard

  1. 创建sdcard文件

    mksdcard -l e 512M mysdcard.img
    
  2. 带sdcard启动avd

    emulator -avd QVGA_2.7 -sdcard mysdcard.img
    
  3. 上传文件

    adb -s emulator-5554 push proxy.py /mnt/sdcard/sl4a/scripts
    

启动模拟器脚本(start avd.bat)

emulator -avd QVGA_2.7

建立adb连接脚本(start adb.bat)

adb devices

adb -s emulator-5554 shell am start -a com.googlecode.android_scripting.action.LAUNCH_SERVER -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher --ei com.googlecode.android_scripting.extra.USE_SERVICE_PORT 45001

adb -s emulator-5554 forward tcp:9999 tcp:45001
set AP_PORT=9999

start echo Adb connected!
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值