1. 程式人生 > >Android Studio開發中遇到的幾個問題及其解決方法

Android Studio開發中遇到的幾個問題及其解決方法

1.建立虛擬機器後,執行時出現錯誤對話方塊,錯誤內容如下:
KVM is required to run this AVD.
/dev/kvm is not found.
Enable VT-x in your BIOS security settings, ensure that your Linux distro has working KVM module.

解決方法:
重啟電腦,按Enter鍵,再按F1鍵進入系統韌體設定(BIOS)介面(這是ThinkPad T460p的進入方法,其他機型需查詢對應品牌的使用者手冊),使用左右游標鍵移動至至“Security”頁,用上下游標鍵移動至“Virtualization”項,按Enter鍵,再用上下游標鍵移動至“Intel (R) Virtualization Technology”項,按Enter鍵,選擇“Enabled”選項,按F10鍵儲存退出,重啟作業系統,問題解決。


2.Gradle構建出現如下錯誤資訊:
Error:Execution failed for task ':app:buildNative'.
> A problem occurred starting process 'command '/home/davidhopper/Android/Sdk/ndk-bundle/ndk-build''
更為詳細的錯誤資訊如下:
Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory.  It is currently set to /home/davidhopper/Android/Sdk/ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.

Incremental java compilation is an incubating feature.
:app:buildInfoDebugLoader
:app:buildNative FAILED
:app:buildInfoGeneratorDebug

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:buildNative'.
> A problem occurred starting process 'command '/home/davidhopper/Android/Sdk/ndk-bundle/ndk-build''

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 6.369 secs

解決方法:
該錯誤資訊說明在“/home/davidhopper/Android/Sdk/ndk-bundle/”資料夾下找不到“ndk-build”檔案,因為Android Studio未自帶NDK開發工具,因此會出現此錯誤。
到“https://developer.android.google.cn/ndk/downloads/index.html”下載Linux 64 位 (x86)版本,我下載的時候,版本號為:android-ndk-r14b-linux-x86_64,下載完畢後將其解壓,得到一個“android-ndk-r14b”資料夾,將其內部的所有檔案全部移動至“/home/davidhopper/Android/Sdk/ndk-bundle/”資料夾下,重啟Android Studio,問題解決。


3.使用Android studio啟動模擬器時,狀態列一直停在“waiting for target device to come online”提示介面,無法彈出模擬器介面。

解決方法:
該問題源自SDK自帶的庫檔案版本問題,將本機相關庫更新後對映過來即可,具體步驟如下:
a).更新安裝庫:
$ sudo apt-get install lib64stdc++6:i386
$ sudo apt-get install mesa-utils


b).Android sdk存放目錄下的資料夾如:
$ cd ~/Android/Sdk/emulator/lib64 


c).備份原有libstdc++目錄:
$ mv libstdc++/ libstdc++.bak


d)將本機庫連結過來:
$ ln -s /usr/lib64/libstdc++.so.6 libstdc++


e)重啟Android Studio,問題解決。


4.模擬器啟動後,彈出錯誤提示對話方塊,內容如下:
Installation failed with message Failed to finalize session : INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113.
It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing.


WARNING: Uninstalling will remove the application data!


Do you want to uninstall the existing application?


解決方法:
這是由於使用了native libraries,而native libraries不支援當前的cpu的體系結構,可以使用修改配置檔案的方法加以解決。
開啟工程“app”目錄中的“build.gradle”檔案,找到如下位置:
android {
    compileSdkVersion 23
    buildToolsVersion '25.0.0'
在下面新增如下語句:
    splits {
        abi {
            enable true
            reset()
            include 'x86', 'armeabi-v7a','x86_64'
            universalApk true
        }
    }
儲存,重啟模擬器,問題解決。