安卓模拟器无警告关闭

3
我正在使用Linux Pop!OS 19.04,并尝试安装Android模拟器。它确实启动了,但每次在大约30秒后关闭。
我通过“OpenJDK-8-JDK”安装了Java 8,并且可以成功构建Android软件包并将其侧载到我的手机上,没有任何问题。
在将Android SDK安装到/usr/local/android后,我做了以下操作:
  1. Change into the tools bin dir

    cd /usr/local/android/sdk/tools/bin
    sudo chmod +x
    
  2. Install system images (must be done as root)

    sudo ./sdkmanager "system-images;android-25;google_apis;x86"
    sudo ./sdkmanager --licenses
    

    Say 'y' to all sudo touch ~/.android/repositories.cfg

  3. List available Android Virtual Devices to install (done as user)

    ./avdmanager list
    
  4. Create a test Android Virtual Device (AVD)

    ./avdmanager create avd -n test -k "system-images;android-25;google_apis;x86"
    

    custom hardware profile: no

  5. List AVDs

    Now I get the following when I list through avdmanager

    ./avdmanager list avd
    Available Android Virtual Devices:
        Name: test
        Path: /root/.android/avd/test.avd
      Target: Google APIs (Google Inc.)
              Based on: Android 7.1.1 (Nougat) Tag/ABI: google_apis/x86
    
  6. Start emulator

    cd /usr/local/android/sdk/emulator
    ./emulator -avd test
    

它会加载模拟器,然后我可以启动应用程序并浏览到它崩溃/关闭程序。

我尝试通过安装Android Studio并设置AVD进行解决,但是出现了同样的问题。我尝试了不同的AVD模型和Android版本,但结果相同。

更新:记录错误

我设法使用以下方法记录崩溃:

$ANDROID_HOME/emulator/emulator -avd test -gpu guest -logcat v

日志

08-22 13:50:03.169  2703  2839 V NativeCrypto: Read error: ssl=0xb0a32640: I/O error during system call, Connection reset by peer
08-22 13:50:03.170  2703  2839 V NativeCrypto: SSL shutdown failed: ssl=0xb0a32640: I/O error during system call, Broken pipe
08-22 13:50:03.195  3551  3551 W dex2oat : Unexpected CPU variant for X86 using defaults: x86
08-22 13:50:03.195  3551  3551 W dex2oat : Mismatch between dex2oat instruction set features (ISA: X86 Feature string: smp,-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-lock_add,-popcnt) and those of dex2oat executable (ISA: X86 Feature string: smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2,-lock_add,-popcnt) for the command line:
08-22 13:50:03.195  3551  3551 W dex2oat : /system/bin/dex2oat --runtime-arg -classpath --runtime-arg & --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2,-lock_add,-popcnt --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/user/0/com.google.android.gms/app_fb/f.apk --oat-fd=44 --oat-location=/data/user/0/com.google.android.gms/app_fb/f.dex --compiler-filter=speed
08-22 13:50:03.195  3551  3551 I dex2oat : /system/bin/dex2oat --dex-file=/data/user/0/com.google.android.gms/app_fb/f.apk --oat-fd=44 --oat-location=/data/user/0/com.google.android.gms/app_fb/f.dex --compiler-filter=speed
08-22 13:50:03.232  3551  3551 I dex2oat : dex2oat took 36.457ms (threads: 2) arena alloc=323KB (331648B) java alloc=76KB (78168B) native alloc=966KB (989744B) free=2MB (2155984B)
08-22 13:50:03.234  2703  2839 W System  : ClassLoader referenced unknown path: 
08-22 13:50:03.253  2022  3550 I GoogleURLConnFactory: Using platform SSLCertificateSocketFactory
08-22 13:50:03.262  2022  3550 I GoogleURLConnFactory: Using platform SSLCertificateSocketFactory
08-22 13:50:03.387  2022  2716 W ConfigurationChimeraPro: Got null configs for com.google.android.gms.auth.account.base
08-22 13:50:03.415  2022  2716 W Conscrypt: Could not set socket write timeout:
08-22 13:50:03.416  2022  2716 W Conscrypt:    java.lang.reflect.Method.invoke(Native Method)
08-22 13:50:03.416  2022  2716 W Conscrypt:    com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@11743470:13)
08-22 13:50:03.552  2022  2716 W Conscrypt: Could not set socket write timeout:
08-22 13:50:03.552  2022  2716 W Conscrypt:    java.lang.reflect.Method.invoke(Native Method)
08-22 13:50:03.552  2022  2716 W Conscrypt:    com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@11743470:13)
08-22 13:50:03.678  2022  2716 W GLSUser : [AppCertManager] IOException while requesting key: 
08-22 13:50:03.678  2022  2716 W GLSUser : java.io.IOException: Invalid device key response.
08-22 13:50:03.678  2022  2716 W GLSUser :  at eyw.a(:com.google.android.gms@11743470:14)
08-22 13:50:03.678  2022  2716 W GLSUser :  at eyw.a(:com.google.android.gms@11743470:65)
08-22 13:50:03.678  2022  2716 W GLSUser :  at eyu.a(:com.google.android.gms@11743470:8)
08-22 13:50:03.678  2022  2716 W GLSUser :  at eyq.a(:com.google.android.gms@11743470:1)
08-22 13:50:03.678  2022  2716 W GLSUser :  at eyp.a(:com.google.android.gms@11743470:10)
08-22 13:50:03.678  2022  2716 W GLSUser :  at com.google.android.gms.auth.account.be.legacy.AuthCronChimeraService.b(:com.google.android.gms@11743470:7)
08-22 13:50:03.678  2022  2716 W GLSUser :  at edr.call(:com.google.android.gms@11743470:3)
08-22 13:50:03.678  2022  2716 W GLSUser :  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-22 13:50:03.678  2022  2716 W GLSUser :  at mmu.run(:com.google.android.gms@11743470:26)
08-22 13:50:03.678  2022  2716 W GLSUser :  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
08-22 13:50:03.678  2022  2716 W GLSUser :  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
08-22 13:50:03.678  2022  2716 W GLSUser :  at mse.run(:com.google.android.gms@11743470)
08-22 13:50:03.678  2022  2716 W GLSUser :  at java.lang.Thread.run(Thread.java:761)
08-22 13:50:07.717  1603  1634 W ActivityManager: Unable to start service Intent { act=com.google.android.gms.drive.ApiService.RESET_AFTER_BOOT flg=0x4 cmp=com.google.android.gms/.drive.api.ApiService (has extras) } U=0: not found
emulator: Saving state on exit with session uptime 119964 ms

更新:config.ini

以下是我的config.ini文件:

PlayStore.enabled = false
abi.type = x86
avd.ini.encoding = UTF-8
hw.accelerometer = yes
hw.audioInput = yes
hw.battery = yes
hw.cpu.arch = x86
hw.dPad = no
hw.device.hash2 = MD5:fc85b2d34337b54227366eb43de4cfef
hw.device.manufacturer = Generic
hw.device.name = 5.4in FWVGA
hw.gps = yes
hw.lcd.density = 160
hw.lcd.height = 854
hw.lcd.width = 480
hw.mainKeys = yes
hw.sdCard = yes
hw.sensors.orientation = yes
hw.sensors.proximity = yes
hw.trackBall = no
image.sysdir.1 = system-images/android-24/google_apis_playstore/x86/
sdcard.size = 2048M
tag.display = Google Play
tag.id = google_apis_playstore
disk.dataPartition.size = 6442450944
hw.ramSize=3072

更新:另一个崩溃日志

这次它没有抱怨缺少关键字。

08-28 09:48:58.109 12476 12476 W art     : Unexpected CPU variant for X86 using defaults: x86
08-28 09:48:58.114 12476 12476 D ICU     : No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
08-28 09:48:58.129 12476 12476 E memtrack: Couldn't load memtrack module (No such file or directory)
08-28 09:48:58.129 12476 12476 E android.os.Debug: failed to load memtrack module: -2
08-28 09:48:58.130 12476 12476 I Radio-JNI: register_android_hardware_Radio DONE
08-28 09:48:58.139 12476 12476 D AndroidRuntime: Calling main entry com.android.commands.settings.SettingsCmd
08-28 09:48:58.144 12476 12476 D AndroidRuntime: Shutting down VM
emulator: emulator_window_fb_update

emulator: emulator_window_fb_update

emulator: emulator_window_fb_update

emulator: emulator_window_fb_update

08-28 09:49:03.851  1602  2032 D AlarmManagerService: Kernel timezone updated to -600 minutes west of GMT
08-28 09:49:03.852  1602  2030 D AlarmManagerService: Setting time of day to sec=1566949744
08-28 09:49:04.002  1602  2030 W AlarmManagerService: Unable to set rtc to 1566949744: No such device
[ 8042.781849] healthd: battery l=100 v=0 t=0.0 h=2 st=2 chg=a
emulator: emulator_window_fb_update

emulator: emulator_window_fb_update

emulator: emulator_window_fb_update

emulator: emulator_window_fb_update

emulator: Saving state on exit with session uptime 73706 ms

解决方法

创建一个别名,每当模拟器崩溃时重新启动它。

alias tnsa="tns run android --device emulator-5554"   # Run in emulator
alias em="$ANDROID_HOME/emulator/emulator -avd samsung_galaxy_s8 -gpu guest -no-audio -verbose" 
alias eml="while true; do pkill -f android; sleep 2; tnsa &; em &> ~/emulator.log; done"

这很糟糕,但这是我目前正在处理的内容。

@Mohsinkazi 不,我没有使用即时运行。它不会在相同的应用程序或时间崩溃。到目前为止我还没有找到规律。 - map7
可能是IOException while requesting key: Invalid device key response的重复问题。 - Martin Zeitler
4个回答

1

尝试将图形设置为Software-GLES。它可能被设置为默认使用硬件的自动模式。

您可以在Android虚拟设备管理器 > 虚拟设备配置 > 模拟性能 > Software-GLES中找到此设置...


我已经使用命令行标志“-gpu guest”来运行软件图形。 - map7
你可以帮忙检查一下虚拟设备的配置吗?我不了解这个标志。事实是,以前当我遇到这种问题时,更改图形为software-gles后,我的问题就得到了解决。 - Samrat
我在这台机器上没有运行完整的Android Studio,只运行sdk命令行工具。参考:https://developer.android.com/studio/run/emulator-acceleration#command-gpu 我尝试了所有其他选项,唯一在这台电脑上有效的是“guest”。在我的笔记本电脑上,我使用“auto”,但它也会崩溃。 - map7
检查这个链接: https://www.bram.us/2017/05/12/fix-for-the-android-emulator-crashing-during-launch/ 此外,你可能需要更新你的驱动程序... 还有一个方法是,清除模拟器中的数据并尝试运行它...这可能不是解决方案,但既然你已经尝试了很多东西,那么也可以尝试一下。 - Samrat
这对我很有效。那些关于GLES的烦人警告也消失了。但是我决定使用硬件而不是软件,因为软件有点慢。硬件效果非常好 :D - chitgoks

1
原因是您在桌面安装了带有模拟器的工作室,但磁盘空间不足。请清理一些空间并重新运行设备,如果这没有帮助,请尝试创建一个新的模拟器。希望能帮到您。

我有551GB的可用空间,这不是问题。 - map7
我尝试创建了Nexus9 AVD以及Pixel、Pixel2和Pixel 3 AVD,但它们都有相同的问题。它们启动后大约30秒就会崩溃。 - map7

1
您的BIOS可能已禁用虚拟化,您可以手动进入BIOS并打开它,不同设备的BIOS不同。此外,问题可能是存储问题,没有空间,文件损坏或存储受某些程序限制。通常情况下,这将是BIOS问题。

我已经在BIOS中启用了VT-d,我的硬盘没有损坏,并且有足够的空间(剩余551GB)。 - map7
VT-x必须启用以进行虚拟化。 - Ashok Kumar

0

尝试以下几种方法,它们可能会对您有所帮助:

  • 模拟器通常会消耗更多的RAM。也许您没有足够的内存来运行。
  • 其他原因可能是:1)过时的显卡驱动程序。2)旧的显卡。

  • 出现了一个错误:

    08-28 09:48:58.129 12476 12476 E memtrack: Couldn't load memtrack module (No such file or directory)

无法加载memtrack模块错误可能是由于模拟器配置问题引起的,并且由于您的项目包含许多组织问题,因此重新设计可能会有所帮助。


我已经将模拟器的RAM配置为3GB。关于重新设计,即使我没有运行我的应用程序,这个问题仍然会发生。 - map7
如果目标模拟器中有相同应用程序的更新版本(与您在manifest.xml中定义的版本代码进行比较),则会出现您提到的错误。无法加载memtrack模块(没有这样的文件或目录) 无法加载memtrack模块:-2 - rushabh sojitra

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接