Android开发环境问题集锦

[来源] 达内    [编辑] 达内   [时间]2012-11-12

和iOS开发相比,Android的开发环境的版本比较多,随之而来的问题也多

工欲善其事,必先利其器。

< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 和iOS开发相比,Android的开发环境的版本比较多,随之而来的问题也多。显然,我们不应该浪费宝贵的时间在解决开发环境带来的问题上,为此本文总结了常见的开发环境问题和解决方法,供大家查询和随时补充。

< h2 style="margin: 15px auto 2px; padding: 5px; font-size: 20px; font-weight: bold; background-color: rgb(102, 102, 102); color: white; font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">Debug certificate expired < p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> Android SDK生成的用于调试的证书文件debug.keystore有效期是365天,当使用超过一年后控制台就会报这个错误。

< div style="margin: 5px 0px; padding: 5px; background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 12px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(68, 68, 68); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " class="cnblogs_code">
Error generating final archive: Debug Certificate expired on 10
/09/18
 16:30
< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 解决方法是手工删除debug.keystore文件,Windows系统下位于"C:\Documents and Settings\username\.android"目录,Linux和Mac系统下位于"~/.android/"目录。下次启动应用时,Eclipse会自动新建一个debug.keystore文件。最好"Project->Clean"一下项目以便触发编译器重新编译。

< h2 style="margin: 15px auto 2px; padding: 5px; font-size: 20px; font-weight: bold; background-color: rgb(102, 102, 102); color: white; font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">Failed to install apk on device: timeout < p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">导致这个问题的确切原因不清楚,可能是由于不正确关闭adb连接。

< div style="margin: 5px 0px; padding: 5px; background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 12px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(68, 68, 68); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " class="cnblogs_code">
Failed to install helloworld.apk on device '
emulator-5554': timeout
< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">解决方法1:更换电脑usb口(不使用 前置usb口)或重装手机驱动,将手机关机后再开机。

< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 解决方法2:在Eclipse里选择"Window->Preferences->Android->DDMS->ADB connection time out",将缺省的5000ms改为更大的值,例如20000ms。

< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">解决方法3:在命令行窗口里依次输入如下命令:

< div style="margin: 5px 0px; padding: 5px; background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 12px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(68, 68, 68); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " class="cnblogs_code">
adb kill-server adb start-server
< h2 style="margin: 15px auto 2px; padding: 5px; font-size: 20px; font-weight: bold; background-color: rgb(102, 102, 102); color: white; font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">invalid command-line parameter < p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">这是由于Eclipse开发环境无法找到所需的可执行文件造成的。

< div style="margin: 5px 0px; padding: 5px; background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 12px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(68, 68, 68); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " class="cnblogs_code">
[2011-07-10 07:10:22 - demo] Android Launch! [
2011-07-10 07:10:24 - demo] adb is running normally. [
2011-07-10 07:10:24 - demo] Performing com.demo.DemoActivity activity launch [

2011-07-10 07:10:25 - demo] Automatic Target Mode: launching new emulator with compatible AVD 'xxx' [
2011-07-10 07:10:25 - demo] Launching a new emulator with Virtual Device 'xxx' [
2011-07-10 07:11:06 - Emulator] invalid command-line parameter: Files\Android\android-sdk\tools/emulator-arm.exe.
< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 解决方法是在Eclipse里选择"Window->Preferences->Android"选项,检查"SDK Location"的路径是否包含了空格,如果是"c:\Program Files\android"这种,改为"c:\Progra~1\android",这样命令行就可以正常调用到了。

< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">小提示:在命令行窗口里输入"dir /x"命令就可以列出8.3格式的文件名,看下面的结果:

< div style="margin: 5px 0px; padding: 5px; background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 12px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(68, 68, 68); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " class="cnblogs_code">
2012-09-25  23:52    <DIR>          WATCHD~1     WatchData 
2012-09-01  11:01    <DIR>                       Winamp 
2012-07-24  22:22    <DIR>          WINDOW~4     Windows Live 

2012-07-24  22:21    <DIR>          WI3957~1     Windows Live SkyDrive
< h2 style="margin: 15px auto 2px; padding: 5px; font-size: 20px; font-weight: bold; background-color: rgb(102, 102, 102); color: white; font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">INSTALL_FAILED_INSUFFICIENT_STORAGE < p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">安装应用程序时遇到存储容量不足时会报这个错误:

< div style="margin: 5px 0px; padding: 5px; background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 12px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(68, 68, 68); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " class="cnblogs_code">

Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE Please check logcat output for more details. Launch canceled!
< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">如果是在模拟器上运行应用,可以扩大AVD的内存容量。

< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">如果是在真机上运行,可以在AndroidManifest.xml里修改安装偏好,让应用直接安装到SD卡上解决。

< div style="margin: 5px 0px; padding: 5px; background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 12px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(68, 68, 68); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " class="cnblogs_code">
<
manifest xmlns:android
="http://schemas.android.com/apk/res/android"
     package

="com.example"
     android:installLocation
="preferExternal"

 > ... 
</manifest
>
< h2 style="margin: 15px auto 2px; padding: 5px; font-size: 20px; font-weight: bold; background-color: rgb(102, 102, 102); color: white; font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">Unable to open sync connection < p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">虽然很多人遇到这个问题,但问题的根源并不确切,可能有多种原因造成adb报这个错误:

< div style="margin: 5px 0px; padding: 5px; background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 12px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(68, 68, 68); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " class="cnblogs_code">
[
2010-10-12 09:36:48 - myapp


] Android Launch! 
[
2010-10-12 09:36:48 - myapp

]
 adb is running normally. 

[
2010-10-12 09:36:48 - myapp

]
 Performing com.mycompany.myapp.MyActivity activity launch 

[
2010-10-12 09:36:48 - myapp

]
 Automatic Target Mode: using device 'xxx' 

[
2010-10-12 09:36:48 - myapp]


 Uploading myapp.apk onto device 'xxx' [
2010-10-12 09:36:48 - myapp
]

 Failed to upload myapp.apk on device 'xxx' 
[

2010-10-12 09:36:48 - myapp
]

 java.io.IOException: Unable to open sync connection! 


[2010-10-12 09:36:48 - myapp
] Launch canceled!
< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">解决方法1:拔掉手机连接线再重新连上;

< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 解决方法2:在手机上关闭Debug选项再重新打开,这个选项在手机的"设置->应用程序->开发->USB调试"里。

< h2 style="margin: 15px auto 2px; padding: 5px; font-size: 20px; font-weight: bold; background-color: rgb(102, 102, 102); color: white; font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">Too many open files < p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 这个问题与系统可同时打开文件数量设置有关,但一般不需要修改相关设置,用上一个问题(Unable to open sync connection)的方法即可解决。

< h2 style="margin: 15px auto 2px; padding: 5px; font-size: 20px; font-weight: bold; background-color: rgb(102, 102, 102); color: white; font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">第三方Jar包,NoClassDefFoundError < p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 升级ADT版本以后容易出现这个问题:本来一切正常的Android项目,升级以后所有的第三方Jar包里的类都提示NoClassDefFoundError了。

< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">原因可能出现在不同版本ADT使用的编译ant脚本的区别,可能的解决方法有两个:

< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 方法1:在Eclipse里右键点击你的Android工程,选择"Properties->Java Build Path->Order and Export",在这里把所有第三方Jar包前面的复选框都勾上。

< p style="margin: 15px 0px; padding: 0px; text-indent: 0px; font-size: 14px; line-height: 20px; color: rgb(68, 68, 68); font-family: tahoma, arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">方法2:检查你的第三方Jar包文件是否放在工程目录下的"libs"目录,如果不是,改过来。

资源下载