由于模拟器超时,安装失败

32
当我尝试通过Eclipse将.apk安装到android模拟器或物理设备(通过USB)时,我会收到“在设备'*'上安装*.apk失败:超时”错误。在模拟器和实体设备(Samsung Galaxy S2,已root)中都找不到.apk文件。
如果我避免使用Eclipse,只使用命令行,我也无法安装.apk文件。
为什么要发布这篇新文章?
有几篇stackoverflow文章提到了“安装失败...”错误。我创建了一个新的文章有以下几个原因:
1.大多数其他帖子都没有详细说明。
2.突出的相关帖子Android error: Failed to install *.apk on device *: timeout,适用于原始作者的物理设备连接。所以这是一个不同的情况,尽管症状相似。
3.我尝试了那篇文章中的所有候选解决方案,以及其他几篇文章。这些列在下面的“我尝试过的候选解决方案”中。

这篇文章很长,因为我需要详细描述我所采取的步骤,以解决这个问题。如果您不想阅读或至少浏览此文章,请不要评论。

我的环境

操作系统:Windows XP SP3

JAVA:Java SDK 版本 1.6.0_32

WINDOWS 环境变量:

JAVA_HOME=C:\Program Files\Java\jdk1.6.0_33;

PATH=...;%JAVA_HOME%\bin\;C:\android\android-sdk\tools;C:\android\android-sdk\platform-tools\;...;C:\Program Files\apache-ant-1.8.2\bin;...;

IDE:Eclipse(安装了经典版)Indigo。版本号为 3.7.2

ANDROID SDK

  • Android SDK工具版本:20。(主要测试版本为19)。
  • Android SDK平台工具:11。
  • ADT插件(“Android开发工具包”,Eclipse插件)版本:20.0.0.v201206010423-369331(也适用于先前版本18.0.0.v201203301501-306762)。
  • 项目所针对的平台及模拟器中运行的平台版本。尝试了以下每个版本:
    • Android 4.0.3(API 15)
    • Android 2.2(API 8)
    • Andorid 2.1(API 7)

移动设备:三星Galaxy S2运行Android冰淇淋三明治(ICS)4.0.3

ANT:1.8.2

我进行错误处理的步骤。

使用Eclipse尝试将.apk安装到模拟器中:

  • 打开Eclipse(它会加载我的工作区,其中只有一个Android应用程序)。
  • 使用之前配置好的运行配置运行我的Android应用程序。
  • “Android设备选择器”启动(我已将我的运行配置设置为手动启动此选项)。
  • 在Android设备选择器中,我选择我的AVD(目标为Android 2.2),然后单击“确定”。
  • 模拟器将打开,并显示“5554:jlbavd2_2”。我的AVD名称是“jlbavd2_2”。
  • 我保持模拟器处于打开状态。在Eclipse中,我打开DDMS视图。在“设备”窗格中,单击白色三角形并选择“重置adb”。

在Eclipse控制台中,Android视图中,我得到:

[2012-06-19 19:20:52 - MyApp] Starting full Post Compiler.
[2012-06-19 19:20:52 - MyApp] ------------------------------
[2012-06-19 19:20:52 - MyApp] Android Launch!
[2012-06-19 19:20:52 - MyApp] adb is running normally.
[2012-06-19 19:20:52 - MyApp] Performing au.com.myorg.myapp.MyAppActivity activity launch
[2012-06-19 19:20:52 - MyApp] Refreshing resource folders.
[2012-06-19 19:20:52 - MyApp] Starting incremental Pre Compiler: Checking resource changes.
[2012-06-19 19:20:52 - MyApp] Nothing to pre compile!
[2012-06-19 19:20:53 - MyApp] Starting incremental Package build: Checking resource changes.
[2012-06-19 19:20:53 - MyApp] Skipping over Post Compiler.
[2012-06-19 19:20:59 - MyApp] Launching a new emulator with Virtual Device 'jlbavd'
[2012-06-19 19:22:29 - MyApp] New emulator found: emulator-5554
[2012-06-19 19:22:29 - MyApp] Waiting for HOME ('android.process.acore') to be launched...
[2012-06-19 19:22:44 - MyApp] HOME is up on device 'emulator-5554'
[2012-06-19 19:22:44 - MyApp] Uploading MyApp.apk onto device 'emulator-5554'
[2012-06-19 19:22:49 - MyApp] Failed to install MyApp.apk on device 'emulator-5554': timeout
[2012-06-19 19:22:49 - MyApp] Launch canceled!

在Eclipse控制台、DDMS输出中,我得到了以下信息:
...
[2012-06-19 19:22:44 - ddm-hello] handling HELO
[2012-06-19 19:22:44 - ddm-hello] HELO: v=1, pid=150, vm='Dalvik v1.2.0', app='android.process.acore'
[2012-06-19 19:22:44 - MyApp.apk] Uploading MyApp.apk onto device 'emulator-5554'
[2012-06-19 19:22:44 - Device] Uploading file onto device 'emulator-5554'
[2012-06-19 19:22:49 - ddms] write: timeout
[2012-06-19 19:22:49 - Device] Error during Sync: timeout.
[2012-06-19 19:22:49 - ddms] Removing req 0x4000002d from set

有时候(可能我会稍微做一些不同的步骤),我会出现以下情况:
[2012-06-16 14:20:02 - MyFirstApp02] Starting full Post Compiler.
[2012-06-16 14:20:02 - MyFirstApp02] ------------------------------
[2012-06-16 14:20:02 - MyFirstApp02] Android Launch!
[2012-06-16 14:20:02 - MyFirstApp02] adb is running normally.
[2012-06-16 14:20:02 - MyFirstApp02] Performing au.com.myorg.MyFirstApp02Activity activity launch
[2012-06-16 14:20:08 - MyFirstApp02] Launching a new emulator with Virtual Device 'jlbavd2_2'
[2012-06-16 14:20:17 - Emulator] bind: Unknown error
[2012-06-16 14:20:17 - MyFirstApp02] New emulator found: emulator-5556
[2012-06-16 14:20:17 - MyFirstApp02] Waiting for HOME ('android.process.acore') to be launched...
[2012-06-16 14:20:38 - MyFirstApp02] HOME is up on device 'emulator-5556'
[2012-06-16 14:20:38 - MyFirstApp02] Uploading MyFirstApp02.apk onto device 'emulator-5556'
[2012-06-16 14:20:50 - MyFirstApp02] Failed to install MyFirstApp02.apk on device 'emulator-5556': timeout
[2012-06-16 14:20:50 - MyFirstApp02] Launch canceled!

请注意"bind: Unknown error"。有时会出现此错误,有时不会。
如果我拔掉硬件路由器的以太网电缆,我会得到以下信息:
[2012-06-19 23:27:29 - MyApp] Android Launch!
[2012-06-19 23:27:29 - MyApp] adb is running normally.
[2012-06-19 23:27:29 - MyApp] Performing au.com.softmake.myapp.MyAppActivity activity launch
[2012-06-19 23:27:29 - MyApp] Refreshing resource folders.
[2012-06-19 23:27:29 - MyApp] Starting incremental Pre Compiler: Checking resource changes.
[2012-06-19 23:27:29 - MyApp] Nothing to pre compile!
[2012-06-19 23:27:33 - MyApp] Launching a new emulator with Virtual Device 'jlbavd'
[2012-06-19 23:27:40 - Emulator] Warning: No DNS servers found
[2012-06-19 23:27:44 - Emulator] emulator: emulator window was out of view and was recentered
[2012-06-19 23:27:44 - Emulator]
[2012-06-19 23:28:29 - MyApp] New emulator found: emulator-5554
[2012-06-19 23:28:29 - MyApp] Waiting for HOME ('android.process.acore') to be launched...
[2012-06-19 23:28:36 - MyApp] HOME is up on device 'emulator-5554'
[2012-06-19 23:28:36 - MyApp] Uploading MyApp.apk onto device 'emulator-5554'
[2012-06-19 23:28:42 - MyApp] Failed to install MyApp.apk on device 'emulator-5554': timeout
[2012-06-19 23:28:42 - MyApp] Launch canceled!

请注意 "警告:未找到DNS服务器"。
使用Eclipse尝试将.apk安装到物理设备(已root的三星Galaxy S2,4.0.3版本,启用USB调试),在经过类似上述步骤后,我在Eclipse控制台中获得了Android输出。
[2012-06-15 22:40:34 - MyFirstApp] Starting full Post Compiler.
[2012-06-15 22:40:34 - MyFirstApp] ------------------------------
[2012-06-15 22:40:34 - MyFirstApp] Android Launch!
[2012-06-15 22:40:34 - MyFirstApp] adb is running normally.
[2012-06-15 22:40:34 - MyFirstApp] Performing
    au.com.myorg.myfirstapp.MyFirstAppActivity activity launch
[2012-06-15 22:40:39 - MyFirstApp] Uploading MyFirstApp.apk onto device '0019adf659f24e'
[2012-06-15 22:40:51 - MyFirstApp] Failed to install MyFirstApp.apk on device '0019adf659f24e': timeout
[2012-06-15 22:40:51 - MyFirstApp] Launch canceled!

这是一种类似于安装到模拟器时出现的错误。

当仅使用命令行而避免使用Eclipse时,我需要按照以下步骤进行:

  • Open a windows command prompt in my working directory (I'm using C:\Data\Sda\Code\Mobile\Android\Examples>").

    android list targets.

  • I obtain my target id (I choose Android 2.2).

    android create project --target 3 --name MyAppCmd --path ./MyAppCmd --activity MyAppCmdActivity --package au.com.myorg.myappcmd

  • I get a series of healthy looking output "Created project directory ...", "Added file ..."

  • In windows I double click "AVD Manager.exe".
  • I launch my avd (which targets Android 2.2)
  • Back to my command window

    cd MyAppCmd

    ant debug

  • After a list of output I get "BUILD SUCCESSFUL ..." (On a prior occasion I had to edit C:\android\android-sdk\platform-tools\dx.bat to change "set defaultXmx=-Xmx1024M" to "set defaultMx=-Xmx512M" to make the build successful ). I observe that bin/MyAppCmd-debug.apk exists.

  • I attempt an install with

    adb install bin/MyAppCmd-debug.apk

  • Output:

    * daemon not running. starting it now on port 5037 *
    * daemon started successfully *
    error: device offline
    

    adb devices

    List of devices attached
    emulator-5554   device
    

    adb install bin/MyAppCmd-debug.apk

  • There is no further output in the command window. No error message. Just a blinking cursor, no error or success message, and no return to the command prompt ">".

  • I shut down the command line and open a new one.

  • I get the same result (a blinking cursor, etc.) if I try a push command (temp.txt has been previously created on my windows system) ...

    adb push temp.txt /sdcard/temp.txt

我尝试过的解决方案

Eclipse相关:

  • 按照Eclipse无法与模拟器通信中的步骤进行操作。
  • 增加ADB连接超时时间。Eclipse > Window > Preferences > Android > DDMS > " ADB connection time out(ms):" = 10000 (我还尝试了60000)。
  • 再次运行应用程序(并选择当前正在运行的模拟器或手机)。
  • 清理项目:Eclipse > Project > Clean ...
  • 重启Eclipse。
  • 将Eclipse从Indigo(2.7.x)降级到Helios(2.6.x)。

Android相关:

  • Reset the adb in several ways: "Reset ADB" command from the Eclipse DDMS perspective (from the Devices window triangle); command line with "adb kill-server" and "adb start-server"; and using the Windows Task manager to kill adb.exe.
  • Reinstalling my Samsung OEM USB drivers (By using KIES > Tools > Troubleshoot connection error).
  • Installing my Android SDK to a directory without spaces anywhere in the paths. Namely C:\Android\android-sdk. This entailed a reinstall of the SDK, formerly located at C:\Program files\Android\android-sdk
  • My Android Project is installed in a directory without spaces anywhere in the the path.
  • Deleting and recreating the avd (both from the Android AVD Manager and using Windows Explorer).
  • Using different AVDs that target different platfroms (Android 2.2 and Android 4.0.3).
  • Just after the Emulator opens but before it times out: unlocking the phone V waiting till it times out with the phone locked (in the emulator).
  • Verified I have in my AndroidManifest.xml:

      <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" /> 
    

与环境相关(PC和手机):

  • 重启了我的手机。
  • 重启了我的开发PC。
  • 关闭了我的软件和硬件防火墙。
  • 关闭了MS Security Essentials实时保护。
  • 禁用了我的主机列表。
  • 重新安装了Java。
  • 引导进入Windows安全模式并运行Eclipse。
  • 通过查看Sysinternals TCPView中可用的内容手动终止大多数其他应用程序TCP/IP进程(例如GoogleDesk.exe,Apache Server PunkBuster等)。
  • 从我的PC断开以太网电缆。

其他信息

一些adb命令有效。

例如,以下命令会使模拟器屏幕上下跳动(如预期)。

adb shell monkey -v 100

我可以列出设备,并使用以下命令正确地检索其状态

adb devices。

因此,在adb客户端和adb守护程序之间(通过adb服务器)存在部分通信。

我相对于Android开发比较新手。然而,大约6个月前(从我现在尝试让其工作的WinXP PC上),我成功地将.apk文件安装到模拟器和我的设备上。自那以后我一直忽略了Android。最近回来时,我在构建我的.apk文件时遇到了一些问题,通过删除我的debug.key并允许eclipse生成一个新的解决了这个问题。
在过去的6个月中,我的开发机器在各种方面都发生了变化。安装新的服务器和应用程序,更改防火墙设置等等。因此,可能有一些我忽视的变化。
我还有一台Win7笔记本电脑,我已经成功地将.apk文件安装到模拟器和USB连接的物理设备上。也就是说,我在Win7机器上安装了Android SDK、Eclipse、JAVA等等。所以我知道如何正确地设置全部内容的一般步骤。
我可以通过ES文件浏览器手动双击文件,在我的手机上安装.apk文件(它通过无线方式连接到我的开发机器)。
最后想法:
看起来adb客户端、adb服务器或adb守护进程之间存在某些问题。我有三个假设:
  • 这是我的错。存在某种TCP/IP冲突,导致adb客户端、adb服务器或adb守护进程之间的某些连接中断。这是由于我的PC上的一些奇怪设置(像任何开发人员一样,我经常改变系统的各种设置)造成的。但是,我已经尝试禁用安全性和其他可能产生冲突的TCP/IP进程了(据我所知)。
  • 我一直忽视的一些简单问题。
  • 这是谷歌/Android的错。也就是说,Android adb中存在一个错误,需要更新android SDK平台工具。我认为这种可能性较小,因为我认为它应该已经浮出水面了。

帖子更新

2012-06-22 18:55 (UTC):

完全重新安装Java、Eclipse和Android SDK,并在安装过程中进行了一些变化(例如将Java安装到根目录;将Android SDK安装到默认的“Program Files\”;并在安装过程中关闭所有安全软件)。

我注意到在通过管理器安装各个部分的平台/工具时,在Android SDK管理器日志中出现了错误“停止ADB服务器失败(代码-1)”。

2012-06-30 06:15 (UTC):

重新调整“我的环境”规格以反映最新的测试结果。


1
请查看此问题:https://dev59.com/MWTWa4cB1Zd3GeqPCVvO - idiottiger
Idiottiger。那里没有我上面没有列出的候选解决方案。 - John Bentley
1
这对我来说是第一次,但请缩小你的问题,因为它太长了,很难阅读。 - HotHeadMartin
同样,我遇到了类似的问题,但是它是间歇性的。我启动了 Ubuntu,重新安装了所有 Android 工具,然后尝试了一下,一切都正常工作了。我从来没有弄清楚我的 Windows 设置出了什么问题导致了间歇性的超时,但是在 Ubuntu 中,我没有遇到这个问题。 - Michael Celey
@JonO 感谢您抽出时间尝试解决它。幸运的是,我现在已经通过一种解决方法解决了它:升级到运行Windows 8的新机器。 - John Bentley
显示剩余10条评论
13个回答

3
如果超时,可能需要将ADB连接与Eclipse的超时限制增加。因此,请尝试以下操作:打开“首选项 > Android > DDMS”,您将看到ADB连接超时时间,将其调整为20000。请注意保留HTML标记。

你可能漏掉了我先前写的:“增加ADB连接超时时间。Eclipse > Window > Preferences > Android > DDMS > ADB connection time out(ms):” = 10000(我也尝试过60000)。 - John Bentley
尝试执行 adb kill-server 然后 adb start-server 然后 adb install package name ... 如果在模拟器中无法工作,则您说您已经 root 设备,请在其中尝试相同的操作... - Vipin Sahu
Vipin Sahu。是的,我已经尝试过这两件事情了。也就是说,通过我列出的任意一种方法重置adb。检查模拟器或设备是否被识别(在eclipse DDMS视图>设备面板中:观察模拟器或设备列表。或者从命令行“adb devices”)。然后通过eclipse或命令行将.apk安装到模拟器或物理设备上。 - John Bentley

2

我曾经遇到过同样的问题。将*.apk复制到手机内存中,然后通过Myfiles并选择*.apk文件直接在设备上安装,这样就可以正常运行了。我怀疑这是由于USB连接出现问题(错误太多,Eclipse因其他进程使用USB而变得太慢等)。


2

请确保您正在使用管理员帐户。这个问题也曾让我感到沮丧,但当我切换到管理员帐户(在Windows Vista上),adb似乎可以正确地将apk安装到设备上。


感谢您提供了一个我没有提到的可能解决方案。我曾经尝试过这个(不经思考)。幸运的是,我通过升级到运行Windows 8的新机器来解决了这个问题。 - John Bentley

2

当这种情况发生在我们的物理设备上时,通常会尝试通过拔掉插头、切换设备上的“Android调试模式”并重新连接来修复它。


不需要拔插,切换标志就足够了。 - Giulio Piancastelli
对我有用 - 拔掉插头,切换一下,重新插上,立即就可以工作了 - 真是太愚蠢了。 - Simon

1

我的简单方法是只重启模拟器(而不是eclipse)。这样就可以正常工作,而无需发送任何adb命令。虽然在物理设备上很少发生这种情况。


1
尝试更改ADB连接超时时间。我认为默认设置为5000毫秒,我将我的更改为10000毫秒以解决该问题。
如果您在使用Eclipse,则可以通过以下步骤进行更改:
Window-> Preferences -> Android -> DDMS -> ADB Connection Timeout (ms)

增加了ADB连接超时时间。Eclipse > Window > Preferences > Android > DDMS > "ADB connection time out(ms):" = 10000 (我也尝试过60000)。 - John Bentley

1
我通过升级到全新的环境,几个月后解决了这个问题。具体来说,是使用一个全新的机器,并安装了Windows 8。我也避免安装Comodo套件(我不知道这是否导致了问题)。因此,虽然这不是直接解决问题的方法(仍然不清楚问题的根本原因),但也许可以作为另一个示例,说明解决问题的曲线救国或横向解决方案有时是一个不错的最后手段选择。

0

当这种情况发生时,以下是我在Win7 64位系统上所做的操作:

  1. 关闭Eclipse
  2. 从任务管理器中结束adb.exe和所有emulator-arm.exe的副本
  3. 打开Eclipse
  4. 切换到DDMS视图,确保您可以看到设备
  5. 打开“窗口”/“ADV Manager”
  6. 选择所需的模拟器并按“启动”
  7. 观察DDMS中的设备面板,以查看模拟器是否显示。 如果它没有在启动窗口进度条完成之前显示,则此次不会加载模拟器,因此请关闭模拟器。
  8. 然后从第6步重新开始。

对我而言,模拟器从未第一次启动,但是10次尝试中有9次成功启动。

希望他们能修复这个问题! Mark


0

只需拔下并重新插入手机(物理)即可解决问题。当手机连接时间过长且未进行任何操作时,这种情况也会发生在我身上(太多次了)。


谢谢。当出现这些症状时,需要注意这一点。然而,在我的情况下并不适用(该问题也发生在模拟器中)。 - John Bentley

0

如果您不是管理员账户,请确保家长控制已关闭。这对我有用。


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