这个发生在2017年,我迷上了使用一款叫做Deepin OS的国产Linux系统,基于Debian,精美华丽的UI和动画,适合国人的操作环境(QQ/微信/Tim/软件市场)

但是发现无法启动android 模拟器,报错结果是缺少so文件,在百度的结果使用无效之后,我google之,最终发现是我应该在启动模拟器的时候加上 -use-system-libs 的参数

写了一个脚本,分享之:

python文件:

import os

AVD_HOME =  os.environ['HOME']+"/.android/avd"
ANDROID_HOME = os.getenv("ANDROID_HOME")
EMULATOR_CMD = "nohup "+ANDROID_HOME+"/tools/emulator -use-system-libs -avd "
avds = []

def run():
    
    i = 1
    print "Please select a avd to start up :"
    for fname in os.listdir(AVD_HOME):
        fstr = str(fname)
        if fstr.endswith(".ini"):
            fstr = fstr.replace(".ini","")
            print i,".....",fstr
            avds.append(fstr)
            i+=1
    process()

def process():
    inval = raw_input(">")
    if inval.isdigit():
        inval = int(inval)
        if inval <= avds.__len__() and inval > 0:
            os.system(EMULATOR_CMD+avds[inval-1]+" >/dev/null 2>&1 &")
            exit(0)
        else:
            print "Please input agian."
            process()
    else:
        print "Please input agian."
        process()

if __name__ == "__main__" :
    try:
        run()
    except KeyboardInterrupt:
        print "\nBye.See you next time."
        exit(0)

为了方便调用,做了一个bash脚本

#!/bin/sh
cd ~/PyOpenAVD
/usr/bin/python  avd.py

使用chmod +x avd.sh 命令设置执行权限,我们就可以双击打开模拟器了

这里用到的主要命令是

ANDROID_HOME/tools/emulator -use-system-libs -avd 

接下来就爽歪歪的开发去了,顺便一提,深度真的好用;-)

 

第二种方式,直接使用bash:

#!/bin/bash
printf "ANROID_HOME = " 
if [ "$ANDROID_HOME" =  "" ] 
then
    printf "NULL\n Please input your ANDROID_HOME path:"
    read path 
    export ANDROID_HOME = $path
    printf "I have set ANDROID_HOME ^_^\n\n"
else
    printf "%s\n\n" $ANDROID_HOME
fi
echo "Please select a avd to launch:"
i=0
arr=()
for f in $(emulator -list-avds);do 
    printf "%d %s\n" ${i} ${f}
    arr[i]=${f}
    i+=1
done
printf ">"
read index
printf "What kind of ways do you want to execute?\n"
printf "0 Foreground.\n1 Background.\n>"
read tp
if [$tp = 1]
then
    $ANDROID_HOME/tools/emulator -use-system-libs -avd ${arr[index]}
else
    nohup $ANDROID_HOME/tools/emulator -use-system-libs -avd ${arr[index]} >/dev/null 2>&1 &
fi
printf "Launching avd: %s\n" ${arr[index]}

 

同样添加执行权限后,双击用终端打开,选择即可,会判断你是否设置ANDROID_HOME环境变量,无则添加.

Logo

更多推荐