简体   繁体   English

我开始找不到清单中列出的主要活动

[英]am start cannot find main activity listed in manifest

I am trying to start an activity for an app (which I did not write in case you were wondering) through the adb shell. 我正在尝试通过adb shell启动一个应用程序的活动(如果您想知道的话,我没有写过)。 The manifest has the lines: 清单包含以下行:

    <activity android:label="@string/app_name" android:name="MainActivity$mainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

I have tried using the the commands 我尝试使用命令

adb shell am start -W com.pkg.name/MainActivity$mainActivity
adb shell am start -W com.pkg.name/.MainActivity$mainActivity
adb shell am start -W com.pkg.name/.MainActivity
adb shell am start -a android.intent.action.MAIN -n com.pkg.name/MainActivity$mainActivity
adb shell am start -n com.pkg.name/MainActivity$mainActivity
etc...

and each and every one gives me the error: 每一个给我的错误:

Error type 3
Error: Activity class {com.pkg.name/com.pkg.name.MainActivity}
does not exist.

It does however work when clicking on the app icon in the emulator, and by grepping the logcat output I find that the activity being launched is called .MainActivity$mainActivit or .MainActivity , they both show up in the output. 但是,当单击仿真器中的应用程序图标时,它确实起作用,并且通过glogping logcat输出我发现正在启动的活动称为.MainActivity$mainActivit.MainActivity ,它们都显示在输出中。 Can someone tell me why am start is not working and how to in fact start this activity without manually clicking the icon? 有人可以告诉我为什么am start无法正常进行,实际上如何在不手动单击图标的情况下启动此活动?

UPDATE: The solution given by laalto is almost right. 更新: laalto提供的解决方案几乎是正确的。 It turns out it was a problem with the $ getting resolved as an environment variable, however the command he suggested doesn't quite do it. 事实证明,将$解析为环境变量是一个问题,但是他建议的命令并没有做到这一点。 You need to put single quotes around to <pkgname/activityname> in addition to escaping the $ . 除了转义$之外,还需要在<pkgname/activityname>周围加上单引号。

In unix-like shells, $ is a shell metacharacter so the $mainActivity expands to whatever value the environment variable mainActivity holds, likely an empty value in your case. 在类unix的shell中, $是一个shell元字符,因此$mainActivity会扩展为环境变量mainActivity拥有的任何值,在您的情况下可能是空值。

To escape it, use a backslash: 要转义它,请使用反斜杠:

adb shell am start -W com.pkg.name/.MainActivity\$mainActivity

However, having an inner class as an entry point is sort of a code smell. 但是,将内部类作为入口点有点像代码的味道。 Consider making the outer class your entry point. 考虑将外部类作为您的切入点。 Then you wouldn't need $ in any form. 然后,您将不需要任何形式的$

am start -n com.pkg.name/com.package.name.MainActivity$mainActivity

祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM