这个sample android程序要怎样在android模拟器运行apk?

I'm trying to run the sample unit tests for the sample code that ships with the android SDK. Some of the tests run as standard unit tests, no problem. Other tests, such as com.example.android.apis.view.Focus2AndroidTest, use android classes, and therefore need to run in the emulator, that is a problem.
I can run applications just fine in my emulator. When I run tests, though, my emulator starts up, and then just sits there. The test never runs. All I see in the output window in IntelliJ is
Waiting for device.
/Users/rfzabick/android-sdk-mac_x86/tools/emulator -avd MyAvd0 -netspeed full -netdelay none
Device connected: emulator-5554
What am I doing wrong?
After @CrazyCoder's advice, I switched to android 4.0.3 (API 15). Here's what I got:
Testing started at 4:34 PM ...
Waiting for device.
/Users/rfzabick/android-sdk-mac_x86/tools/emulator -avd android4.0.3--api15 -netspeed full -netdelay none -wipe-data -no-boot-anim
Device connected: emulator-5554
Device is online: emulator-5554
Target device: emulator-5554 (android4.0.3--api15)
Uploading file
local path: /Users/rfzabick/IdeaProjects/ApiDemos/out/production/Tests/Tests.apk
remote path: /data/local/tmp/com.example.android.apis.tests
Installing com.example.android.apis.tests
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
Device is not ready. Waiting for 20 sec.
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
Device is not ready. Waiting for 20 sec.
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
Device disconnected: emulator-5554
pkg: /data/local/tmp/com.example.android.apis.tests
Running tests
Test running startedTest running failed: com.android.ddmlib.AdbCommandRejectedException: device not found
Empty test suite.
The only relevant thing I see in logcat is
01-21 16:36:22.047: WARN/ActivityManager(91): No content provider found for permission revoke: file:///data/local/tmp/com.example.android.apis.tests
解决方案 Can you run normal apps in the emulator or USB device? Try to create the new emulator device and see if helps.
I've tried it with IDEA 11.0.1, 4.0.3 Android platform on Windows and it works fine:
Waiting for device.
Target device: emulator-5554 (ICS)
Uploading file
local path: D:\dev\android-sdk-windows\samples\android-15\ApiDemos\out\production\Tests\Tests.apk
remote path: /data/local/tmp/com.example.android.apis.tests
Installing com.example.android.apis.tests
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
pkg: /data/local/tmp/com.example.android.apis.tests
Running tests
Test running startedFinish
You can also try to restart adb with adb kill-server and start the emulator manually from ***D manager.
Verify that there is no pre-installed ApiDemos application in the emulator, or the signatures will not match. Uninstall existing ApiDemos, then try to deploy and run ApiDemos from IntelliJ IDEA, then try to run the test configuration again.
UPDATE: We did some research and found the source of the problem. By default IntelliJ IDEA sets the dependency scope for the application module inside test module to Compile, so that all the production and test classes get compiled into the single Test.apk.
Instead, the scope must be set to Provided and we'll fix it in the next update. Right now you need to correct it manually as shown on the screenshot:
Rebuild the project and run the tests, again, this time 2 separate apk files will be deployed, one for the main app and the second one for the tests, then tests will run:
Waiting for device.
Target device: emulator-5554 (ICS)
Uploading file
local path: D:\dev\android-sdk-windows\samples\android-15\ApiDemos\out\production\Tests\Tests.apk
remote path: /data/local/tmp/com.example.android.apis.tests
Installing com.example.android.apis.tests
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
pkg: /data/local/tmp/com.example.android.apis.tests
Uploading file
local path: D:\dev\android-sdk-windows\samples\android-15\ApiDemos\out\production\ApiDemos\ApiDemos.apk
remote path: /data/local/tmp/com.example.android.apis
Installing com.example.android.apis
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis"
pkg: /data/local/tmp/com.example.android.apis
Running tests
Test running startedFinish
本文地址: &
我试图运行为code样品的样品单元测试附带了Android SDK。有些测试运行标准单元测试,没有问题。其他检查,如com.example.android.apis.view.Focus2AndroidTest,使用Android类,因此需要在模拟器中运行,这是一个问题。我可以运行的应用程序只是在我的模拟器的罚款。当我运行测试,虽然我的模拟器启动,然后只是坐在那里。测试从未运行。所有我在的IntelliJ输出窗口看到的是 等待设备。/用户/ rfzabick / Android的SDK-mac_x86 /工具/仿真器-avd MyAvd0 -netspeed全-netdelay无设备连接:模拟器-5554 我在做什么错了?编辑:@疯狂codeR的意见后,我切换到Android 4.0.3(API 15)。下面是我的了:测试开始于下午4点34分...
等待设备。/用户/ rfzabick / Android的SDK-mac_x86 /工具/仿真器-avd android4.0.3
api15 -netspeed全-netdelay没有-wipe数据-no-启动阿尼姆设备连接:模拟器-5554设备联机:模拟器-5554目标设备:模拟器-5554(android4.0.3
api15)上传文件
本地路径:/Users/rfzabick/IdeaProjects/ApiDemos/out/production/Tests/Tests.apk
远程路径:/data/local/tmp/com.example.android.apis.tests***com.example.android.apis.testsDEVICE shell命令:下午***-r“/data/local/tmp/com.example.android.apis.tests”设备未准备好。等待20秒。DEVICE shell命令:下午***-r“/data/local/tmp/com.example.android.apis.tests”设备未准备好。等待20秒。DEVICE shell命令:下午***-r“/data/local/tmp/com.example.android.apis.tests”设备断开连接:模拟器-5554PKG:/data/local/tmp/com.example.android.apis.tests运行测试测试运行startedTest运行失败:未找到设备:com.android.ddmlib.AdbCommandRejectedException空测试套件。 我logcat中看到的唯一相关的是
16 01-21:36:22.047:WARN / ActivityManager(91):没有内容提供商找到许可撤销:文件:///data/local/tmp/com.example .android.apis.tests 解决方案 可以运行在模拟器或USB设备正常应用程序?尝试创建新的仿真设备,看看是否有帮助。我和IDEA 11.0.1,在Windows 4.0.3 Android平台尝试过了,它工作得很好: 等待设备。目标设备:模拟器-5554(ICS)上传文件
本地路径:D:\\ dev的\\ Android的SDK-WINDOWS \\ \\样品的android-15 \\ ApiDemos \\出\\生产\\测试\\ Tests.apk
远程路径:/data/local/tmp/com.example.android.apis.tests***com.example.android.apis.testsDEVICE shell命令:下午***-r“/data/local/tmp/com.example.android.apis.tests”PKG:/data/local/tmp/com.example.android.apis.tests成功运行测试试运行startedFinish 您也可以尝试重新启动亚行杀亚行 - 服务器和***D经理手动启动仿真器。确认有在模拟器中没有pre-***ApiDemos应用程序或签名将不匹配。卸载现有ApiDemos,然后尝试部署和运行的IntelliJ IDEA ApiDemos,然后尝试再次运行测试配置。 更新::我们做了一些研究,发现了问题的根源。默认情况下的IntelliJ IDEA设置了应用模块测试模块里面的依赖范围的编译,让所有的生产和测试类编译到单个Test.apk。相反,范围必须设置为提供,我们将在下次更新修复它。现在,你需要手动校正的截图如下所示:
重建项目和运行测试,再次,这个时候2个单独的APK文件将被部署,一个主要的应用,第二个用于测试,然后将测试运行: 等待设备。目标设备:模拟器-5554(ICS)上传文件
本地路径:D:\\ dev的\\ Android的SDK-WINDOWS \\ \\样品的android-15 \\ ApiDemos \\出\\生产\\测试\\ Tests.apk
远程路径:/data/local/tmp/com.example.android.apis.tests***com.example.android.apis.testsDEVICE shell命令:下午***-r“/data/local/tmp/com.example.android.apis.tests”PKG:/data/local/tmp/com.example.android.apis.tests成功上传文件
本地路径:D:\\ dev的\\ Android的SDK-WINDOWS \\ \\样品的android-15 \\ ApiDemos \\出\\生产\\ ApiDemos \\ ApiDemos.apk
远程路径:/data/local/tmp/com.example.android.apis***com.example.android.apisDEVICE shell命令:下午***-r“/data/local/tmp/com.example.android.apis”PKG:/data/local/tmp/com.example.android.apis成功运行测试试运行startedFinish
本文地址: &
扫一扫关注官方微信匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。

参考资料

 

随机推荐