首页 > 解决方案 > 错误:未找到默认活动,但已声明

问题描述

我有两次发生在我身上的奇怪情况。

我的主模块中有清单 - igs_main

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

    <application
            android:name=".CommonApplication"
            android:allowBackup="false"
            android:label="@string/app_name"
            android:hardwareAccelerated="true"
            android:networkSecurityConfig="@xml/network_security_config"
            android:theme="@style/AppTheme"
            android:supportsRtl="false"
            tools:replace="android:supportsRtl,android:allowBackup"
            tools:ignore="GoogleAppIndexingWarning, UnusedAttribute, RtlSupport">

        <activity android:name=".auth.view.SplashScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

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

</manifest>

当我尝试启动我的应用程序时,它看起来像

在此处输入图像描述

我得到一个错误:

在此处输入图像描述

我尝试直接指定我的默认 Activity,但 AS 表示此 Activity 未在 Manifest 中声明。

在此处输入图像描述

然后我尝试了Invalidate Caches and RestartAS 和Rebuild项目,但它也没有帮助我。

所以,我浪费了所有可能的解决方案。谁知道如何修复?

标签: androidandroid-studiokotlin

解决方案


不知道为什么会和这个问题联系起来,但是这个问题的原因来自 Kotlin Compiler。当我启动 Kotlin 编译器选项时,我看到了警告,经过几秒钟的谷歌搜索后,我找到了此处描述的答案 - https://stackoverflow.com/a/50912853/4969827

改成一切useProjectSettings正常后true

为防止信息丢失,我将原始片段复制粘贴到此处。

<facet type="kotlin-language" name="Kotlin">
  <configuration version="3" platform="JVM 1.6" useProjectSettings="true">
    <compilerSettings />
    <compilerArguments>
      <option name="destination" value="$MODULE_DIR$/build/tmp/kotlin-classes/debug" />
      <option name="noStdlib" value="true" />
      <option name="noReflect" value="true" />
      <option name="moduleName" value="app_debug" />
      <option name="addCompilerBuiltIns" value="true" />
      <option name="loadBuiltInsFromDependencies" value="true" />
      <option name="languageVersion" value="1.2" />
      <option name="apiVersion" value="1.2" />
      ...
    </compilerArguments>
  </configuration>
</facet>

您必须阅读以下文字

然而问题不断出现。很少,但来了。有一天我在编辑 xml 文件时发现了损坏的 APPT。所以问题出在 SDK 中,我将其删除并再次安装。在此之后一切正常。


推荐阅读