Android Studio开发中遇到的几个问题及其解决方法

有时候见到自己用的到的知识就像收藏了,这样黏贴到自己博客里才有写安心。原作者见谅

此文来源于:https://blog.csdn.net/davidhopper/article/details/78312632?locationNum=5&fps=1

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.

解决方法:
1)重启电脑,按Enter键,再按F1键进入系统固件设置(BIOS)界面(这是ThinkPad T460p的进入方法,其他机型需查询对应品牌的用户手册),使用左右光标键移动至至“Security”页,用上下光标键移动至“Virtualization”项,按Enter键,再用上下光标键移动至“Intel (R) Virtualization Technology”项,按Enter键,选择“Enabled”选项,按F10键保存退出,重启操作系统,问题解决。
2)上述方法对我这电脑来说没有解决,我就用了一个开挂方法。我在电脑上安装了一个‘豌豆荚’,使用它后就奇迹般的发现项目可以进行测试了。推荐使用第一个方法。

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
        }
    }
保存,重启模拟器,问题解决。

你可能感兴趣的:(错误解决)