3

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

未找到默认活动。

<?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 -> Invalidate Caches/Restart了,但它仍然显示相同的错误。

此问题在更新Android Studio 3.2.1Android Studio 3.3. 第一天一切正常,但是当我在第二天尝试运行应用程序时,它开始显示此错误消息Default Activity not found

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

编辑 -

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

编辑2-

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

4

12 回答 12

13

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

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

(参考图片以获得更好的参考) 在此处输入图像描述

于 2020-01-23T07:42:50.973 回答
12

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

于 2019-01-23T06:36:14.670 回答
4

我对 3.4 版也有同样的问题。转到 Build -> Edit Build Types -> SDK location 并选中Use embedded JDK (recommended)。它工作得很好。

于 2019-07-18T18:36:06.763 回答
2

在 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 失去对默认活动的跟踪。我可以通过在运行/调试配置中指定活动来继续调试。

于 2019-11-11T17:33:02.073 回答
2

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

于 2019-01-23T09:02:29.790 回答
2

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

于 2019-01-23T04:25:56.573 回答
1

运行/调试配置

Android应用 > 应用 > 常规

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

总帐

于 2020-02-11T20:51:35.830 回答
1

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

于 2021-01-19T09:22:21.190 回答
1

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

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

看这个截图

于 2021-01-22T07:43:49.983 回答
1

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

于 2020-01-15T14:34:56.743 回答
1

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

于 2020-04-09T21:55:39.870 回答
0

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

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

无论如何,值得一试。

于 2020-08-09T17:15:37.280 回答