“Default Activity Not Found” on Android Studio upgrade

后端 未结 30 1934
时光说笑
时光说笑 2020-11-22 05:08

I upgraded IntelliJ Idea from 12.0.4 to 12.10.

Now all the modules in my Android project give the error:

Error: Default Activity Not Found

相关标签:
30条回答
  • 2020-11-22 05:57

    Since Android Studio 3.5 or 3.6 I started getting the Default Activity not found and I became tired of Invalidating Caches & Restart, rebuilding project etc.

    It turned out, the way I handle multi-modules and manifests was erroneous. I had the default Activity's Manifest in library module only, but it should've been in both app modules.

    Assuming librarymodule appmodule1 appmodule2

    1. Remove HomeActivity from librarymodule Manifest whatsoever.
    2. Add:
    class AppModuleActivity1 : HomeActivity() to appmodule1
    class AppModuleActivity2 : HomeActivity() to appmodule2
    
    1. To appmodule1 Manifest inside application tag, I added:
            <activity
                android:name="com.app.name.AppModuleActivity1">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
    1. Same about appmodule2 but change 2 for 1 in naming.
    0 讨论(0)
  • 2020-11-22 05:57

    Error: Default Activity Not Found

    I solved this way
    Run>>Edit Configuration >>Android Application >> Enter the path of your default activity class in "Launch" Edit Box.

    0 讨论(0)
  • 2020-11-22 05:58

    I can't comment on why the upgrade of IntelliJ might cause this problem because I don't use it.

    However, that error: "Default Activity Not Found" seems to be telling you that you don't have an activity declared in AndroidManifest.xml that is marked as the main activity, to be launched when the application starts.

    You should have at least one activity that looks something like this:

    <activity
            android:name="com.your.package.name.YourActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
    </activity>
    

    If you don't have at least one activity with an intent filter like that, you would most likely see the error message you have included here.

    You should add that intent filter to the Activity that you wish to open when you start the application, and that should fix your problem.

    0 讨论(0)
  • 2020-11-22 05:58

    If you are working on a widget app this solution should work for you:

    1. Go to Edit Configuration
    2. Set Launch Option to nothing
    0 讨论(0)
  • 2020-11-22 06:00

    In Android Studio under Run/Debug Configuration -> Android Application -> General -> Activity -> select the option "Do not launch Activity".

    0 讨论(0)
  • 2020-11-22 06:00

    Exit Android Studio.

    Go to path C:\Users\YOUR_WINDOW_USER_NAME\.AndroidStudio3.3\system

    Remove /caches folder and /tmp folder

    0 讨论(0)
提交回复
热议问题