1. 程式人生 > >解決部分Linux系統中無法啟動Android模擬器的方法

解決部分Linux系統中無法啟動Android模擬器的方法

這個發生在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環境變數,無則新增.