【问题标题】:Default Activity Not Found - Bug in Android Studio 3.3未找到默认活动 - Android Studio 3.3 中的错误
【发布时间】:2022-05-16 15:23:10
【问题描述】:

当我在 Android Studio 3.3 中创建一个新项目时,它会在 Run -> Edit Configurations 处显示错误提示

未找到默认活动。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>

这是我的 activity_main.xml 文件。它显示一行错误

tools:context=".MainActivity"

未解析的类 MainActivity

这是我的 AndroidManifest.xml 文件 - 这里似乎一切正常 -

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.android.myapplication">

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

</manifest>

文件 colors.xmlic_launcher_background.xmlic_launcher_foreground.xml 格式不正确,看起来像这样 -

        f

        isInitialized
        kotlin
        Boolean
        reflect

        KProperty0
        SinceKotlin
        version
        1.2
        internal

        InlineOnly0






             4"  8�H PX��     (�    �

我尝试Clean and Rebuild 项目,它给出了一个错误提示

colors.xml 格式不正确。

我尝试了File -&gt; Invalidate Caches/Restart,但仍然显示相同的错误。

此问题在将Android Studio 3.2.1 更新为Android Studio 3.3 一天后开始出现。第一天一切正常,但是当我在第二天尝试运行一个应用程序时,它开始显示此错误,说Default Activity not found

有没有办法解决这个问题并继续使用 Android Studio 3.3 版?

编辑 -

耶!正如@Andreas 建议的那样,我的 Android Studio 本身可能已经损坏,并且在卸载并重新安装相同版本后可以正常工作(我什至没有恢复到旧版本)。应该检查这个问题是否会在几天后再次出现。

编辑 2-

一年后我正在查看此内容,我很高兴它帮助了很多人。事实证明,这个问题可能由于各种问题而出现,并且没有一个完美的答案。因此,请检查所有答案,如果您遇到同样的问题,看看是否有适合您的方法:)

【问题讨论】:

  • 您当前的项目文件已损坏,我认为您应该创建一个新项目并尝试。
  • 我多次尝试创建一个新项目。文件已损坏,我每次都收到相同的错误。
  • 那么您的 Android Studio 本身可能已损坏。您可能需要对其进行全新安装
  • 然后将您的 android studio 恢复到以前的版本,即 3.2.1 或按照@Andreas 的建议重新安装 studio
  • @KaranHarshWardhan ,我在 3.2.1 中遇到了一些问题,gradle build 遇到了一些问题。我发现升级 Android Studio 作为解决方案,我的问题得到了解决。然后,一天后,这个问题开始了,但正如编辑中所建议的,Andreas 的解决方案奏效了

标签: android android-studio android-studio-3.3


【解决方案1】:

经过大量搜索,这对我有用,

转到编辑配置 -> 选择您的应用程序模块 -> 在启动选项下 -> 从启动下拉列表中选择任何内容。

(参考图片以获得更好的参考)

【讨论】:

    【解决方案2】:

    关闭项目并删除您的C:\Users\UserName\.AndroidStudio3.3 文件夹中的Cache 文件夹并构建您的项目。

    【讨论】:

    • Caches 文件夹位于我电脑的 C:\Users\UserName\.AndroidStudio3.3\system 文件夹中
    • 我有同样的问题。我将 android studio 更新到 4.0。清理项目,无效重启和同步项目对我不起作用。
    • 是的,我相信删除这个caches 目录与从 Android Studio 中选择 Invalidate Caches / Restart 是一样的
    • @String 这个答案对我有用,但 Invalidate Caches / Restart 没有。测试表明 Invalidate Caches 不会清除“system/caches”文件夹的内容。
    【解决方案3】:

    我在 3.4 版中遇到了同样的问题。转到构建 -> 编辑构建类型 -> SDK 位置并选中使用嵌入式 JDK(推荐)。 效果很好。

    【讨论】:

      【解决方案4】:

      使用 Invalidate Caches/Restart 选项重新启动您的 android studio。您可以在文件选项下找到此选项。我认为它会为你工作。

      【讨论】:

        【解决方案5】:

        Android Studio 本身有可能已损坏。卸载并重新安装 Android Studio 即可解决问题。

        【讨论】:

          【解决方案6】:

          在 Android Studio 3.5.2 中,我的自定义启动器/自定义主页应用出现此错误。我能够通过创建一个全新的空白活动应用程序来重现它,然后替换

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

               <category android:name="android.intent.category.DEFAULT" />
               <category android:name="android.intent.category.HOME" />
          

          在清单中。该单一更改会导致 Android Studio 失去对默认活动的跟踪。我可以通过在运行/调试配置中指定活动来继续调试。

          【讨论】:

          • 我没有仔细阅读这篇文章,并认为它说你需要 DEFAULTHOME 条目,但它说你现在需要 LAUNCHER
          【解决方案7】:

          我只需要删除我的 Gradle 缓存文件夹。在 Mac 上,它位于 ~/.gradle/caches

          【讨论】:

            【解决方案8】:

            运行/调试配置

            AndroidApp > 应用 > 常规

            • 模块:应用程序
            • 部署:默认 APK
            • 启动:默认活动

            GL

            【讨论】:

              【解决方案9】:

              在 Android Studio 3.6.2 中,gradle 更新可能会出现这种情况。我发现在 settings.gradle 文件中添加 rootProject.name='YourAppName' 以上 include ':app' 将解决此问题,一旦您使缓存无效并重新启动 Android Studio,或者关闭应用程序和 Android Studio 然后重新启动它们。

              【讨论】:

                【解决方案10】:

                您可能从选择器中选择了错误的模块来运行应用程序。尝试运行包含主要活动的主模块。

                【讨论】:

                  【解决方案11】:

                  我遇到了类似的问题,原因在于清单合并。出现错误,因此未正确合并。解决该错误后,一切正常。

                  要检查合并时是否有错误,请转到您的 AndroidManifest.xml 并点击 Merged Manifest 选项卡。会有“合并错误”

                  See this screenshot

                  【讨论】:

                    【解决方案12】:

                    Android Studio 花栗鼠 | 2021.2.1

                    编辑配置 ...

                    启动选项:

                    1. 将“默认活动”替换为“无”
                    2. 运行应用程序(成功!) 再次启动选项:
                    3. 将“Nothing”再次替换为“Default Activity”
                    4. 运行应用(终止正在运行的应用)

                    帮了我。

                    【讨论】:

                      【解决方案13】:

                      这里没有其他解决方案对我有用,但是在我将以下内容添加到我的应用模块的 build.gradle 文件后,此错误消失了(寻找不同的问题):

                      android {
                          compileOptions {
                              sourceCompatibility JavaVersion.VERSION_1_8
                              targetCompatibility JavaVersion.VERSION_1_8
                          }
                      }
                      

                      无论如何都值得一试。

                      【讨论】:

                        猜你喜欢
                        • 2017-07-17
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 2013-03-27
                        • 2020-01-13
                        • 2016-10-03
                        相关资源
                        最近更新 更多