Error: Default activity not found, but it is decla

2019-05-12 00:06发布

问题:

I have strange situation that has hapenned with me twice.

I have manifest inside my main module - 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>

When I'm trying to launch my app it looks like

And I getting an error :

I tried specify directly my default Activity, but AS said that this activity is not declared in Manifest.

Then I tried to Invalidate Caches and Restart AS and Rebuild the project, but it also didn't help me.

So, I waste all possible solutions. Who knows how it can be fixed?

回答1:

I don't know why it can be linked to this problem, but the reason of this problem comes from Kotlin Compiler. When I launched Kotlin compiler options I saw warning and after few seconds of googling I found an answer which described here - https://stackoverflow.com/a/50912853/4969827.

After changing useProjectSettings to true all became work properly!

To prevent information loss I copy-paste original snippet to here.

<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>

YOU MUST READ TEXT BELOW

However problems continue came up. More seldom, but came. Some day I was editing xml files and I found broken APPT. So the problem was in SDK, which I deleted and installed again. After this all works fine.



回答2:

That usually happens when your Activity class is not public but default (when you don't specify any access modifiers), have a look that it is public class SplashScreen? If you don't make all activity class as public if you don't then on some devices it might crash.



回答3:

In your question you clearly mentioned that "I have manifest inside main module" but you're using igs_main like this:

You need to change it to app module like below

And then try to run the code.