【问题标题】:Android Monkey: "No activities found to run, monkey aborted"Android Monkey:“没有找到运行的活动,猴子中止”
【发布时间】:2020-04-09 16:38:09
【问题描述】:

我的包名为 com.mywebsite.banana。

  • 我想要一个种子,所以测试是可重复的:-s 13
  • 我想要一个相当低级别的冗长:-v
  • 我想运行 500 条伪随机命令:500

我这样叫猴子

adb shell monkey -s 13 -p com.mywebsite.banana -v 500

我的输出

:Monkey: seed=13 count=500
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
No activities found to run, monkey aborted

我的 AndroidManifest.xml 中有这个:

<categoy android:name="android.intent.category.LAUNCHER"/>

我做错了什么?在运行猴子之前,我需要在我的应用程序中添加什么吗?主要活动位于 com.mywebsite.banana - 是要传入的正确路径,还是应该一直到这样的活动:com.mywebsite.banana.activityName?

从我读到的内容看来,我的做法似乎是正确的:


编辑

尝试 1:

adb shell monkey -p com.mywebsite.banana -c intent.CATEGORY_LAUNCHER -v 500

结果 1:

:Monkey: seed=13 count=500
:AllowPackage: com.mywebsite.banana
:IncludeCategory: intent.CATEGORY_LAUNCHER  
// Warning: no activities found for category intent.CATEGORY_LAUNCHER
** No activities found to run, monkey aborted

尝试 2:

adb shell monkey -p com.mywebsite.banana -c android.intent.category.MONKEY -v 500

结果 2:

:Monkey: seed=13 count=500
:AllowPackage: com.mywebsite.banana
:IncludeCategory: android.intent.category.MONKEY 
No activities found to run, monkey aborted

尝试 3:

adb shell monkey -p com.mywebsite.banana -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -v 500

结果 3:

:Monkey: seed=13 count=500
:AllowPackage: com.mywebsite.banana
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY 
No activities found to run, monkey aborted

一些清单:

<activity
        android:name="com.mywebsite.banana.FRCActivity"
        android:launchMode="singleTask"
        android:configChanges="orientation|screenSize"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="none" />
            <category android:name="android.intent.category.MONKEY"/>
        </intent-filter>
</activity>

也尝试了这个版本的清单,没有任何变化:

    <activity
        android:name="com.mywebsite.banana.FRCActivity"
        android:launchMode="singleTask"
        android:configChanges="orientation|screenSize"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.MONKEY"/>
        </intent-filter>
</activity>

【问题讨论】:

  • "Monkey aborted" - 现在听起来很明显是错误的......

标签: android android-monkey


【解决方案1】:

好的!我想通了。显示的错误确实是正确的:

** No activities found to run, monkey aborted

这意味着我使用的包名不正确。我看了又看,最后我的同事提到我们的构建系统在将包推送到设备之前会更改包的名称

因此,如果您遇到此错误,请确保您确实知道您的包的名称是什么

所以,最后的命令是这样的:

$ adb shell monkey -p com.mywebsite.banana.newname -v 5

顺便说一下,这个猴子命令的正确输出如下所示:

:Monkey: seed=1418671144561 count=5
:AllowPackage: com.mywebsite.banana.newname
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
//   0: 15.0%
//   1: 10.0%
//   2: 2.0%
//   3: 15.0%
//   4: -0.0%
//   5: 25.0%
//   6: 15.0%
//   7: 2.0%
//   8: 2.0%
//   9: 1.0%
//   10: 13.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.mywebsite.banana.newname/com.mywebsite.banana.MyActivity;end
// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.mywebsite.banana.newname/com.mywebsite.banana.MyActivity } in package com.mywebsite.banana.newname
Events injected: 5
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=175ms (0ms mobile, 0ms wifi, 175ms not connected)
// Monkey finished

最后一点:我不需要将android.intent.category.MONKEY 添加到我的 AndroidManifest.xml 文件中!

【讨论】:

  • 在我的情况下,我错过了以下行:清单中的
  • 作为提示,您可以使用:adb shell pm list packages -3(-3 将列表限制为第三方应用程序,除非您为 Google/Android 工作)查找设备上应用程序的包名称/设备制造商,您的可能是第三方应用程序 :)
【解决方案2】:

要添加到@ncrypticus 的答案,我认为找出最终包名称的最简单方法是在模拟器上打开应用程序,然后在 Android Studio 中转到 Tools -> Layout Inspector。这将显示该应用程序的包名称。

【讨论】:

    【解决方案3】:

    为了让我找到一个包的名称(也已更改),我试试这个:

    $ adb shell monkey --ignore-crashes -c android.intent.category.LAUNCHER -v 10000 > text_logs.txt
    

    记录了很多意图,所有意图都指向中间的包名称也是我的。

    【讨论】:

    • 警告:在我的手机上随机运行这个会打开大量的应用程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多