如果我避免使用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):
重新调整“我的环境”规格以反映最新的测试结果。