ChatGPT解决这个技术问题 Extra ChatGPT

"Default Activity Not Found" on Android Studio upgrade

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

I reverted back to 12.0.4 and it everything works again.

Any ideas? I think it might be an issue with a missing plugin. Since the plugin is not installed, it is not able to find the default activity. Another thing could have been a local configuration, but I doubt it. I deleted the configuration folder to verify and that didn't change anything.

have you looked at the manifest? maybe switching versions cleared it or something? developer.android.com/guide/components/fundamentals.html
No... but I got it to work with 12.0.4 but re-importing the project from scratch.
Manifest's the key, probably a name error or omission, or a namespace problem
A Manifest problem in all seven modules of the project that 12.0.4 runs correctly but 12.10 doesn't ??
No, but a change in a namespace or something project layout, for example, might have gone out of sync with the manifest

P
Peter Mortensen

If you see that error occur after upgrading versions of IntelliJ IDEA or Android Studio, or after generating a new APK file, you may need to refresh the IDE's cache.

Menu File → Invalidate Caches and restart...


You may also try to file a bug here: youtrack.jetbrains.com/issues/IDEA I find them to be very good at following up with bugs I file.
This worked for me in Android Studio, but after restarting I also had to do Tools -> Android -> Sync Project with Gradle Files.
Didn't work for me. I'm having to settle for launching the app manually. This sucks.
sometimes this occurs, but the problem is somewhere else, for example my problem was in too low minSdkVersion
P
Peter Mortensen

I can't comment on why the upgrade of IntelliJ IDEA 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 file 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.

Additional details

(Android Studio 4.1.2) if the project is created as EmptyApplication then the developer must manually create below three files to avoid the Default Activity Not Found error:

File AndroidManifest.xml

https://i.stack.imgur.com/oG6GY.png

File MainActivity.java

https://i.stack.imgur.com/gq569.png

File activity_main.xml

https://i.stack.imgur.com/kZUwy.png


ant builds it fine and so does IntelliJ 12.0.4
I started my app in Eclipse, yes I have a default activity. I imported my app to Android studio it was fine until one day I added notification manager and stuff, that is when I run into this error. I did File->Invalidate cach->Restart and that fixed it. But the error was not caused by the lack of default activity as you stated.
Worked for me too! BUT NOTE: please write "android.intent.xxx" in lowercase letters - my fault was that the Android Studio completion suggested uppercase letters (this took me one hour) :-(
For those who are relatively new to Android and you've just screwed up your Android Studio project, this is the answer you're looking for. The accepted answer is for when an upgrade has screwed things up for you.
I have set this and my project already run many times and it gets wrong suddenly. I don't know where is wrong. Perhaps, it's a potentially bug of AS.
P
Peter Mortensen

If your app has a launch activity default, possibly this could be your mistake:

https://i.stack.imgur.com/V2Z1a.png

Step 1: Select Edit Configurations

https://i.stack.imgur.com/KIgS8.png

Step 2: watch this warning: Default Activity not found

https://i.stack.imgur.com/eIoOV.png

Step 3: select a default activity

https://i.stack.imgur.com/q47xk.png

https://i.stack.imgur.com/6hBpr.png

Step 3: Save your changes and finish

https://i.stack.imgur.com/kr4Du.png

Good Luck

https://i.stack.imgur.com/6rHhz.png


Good answer! This what helps if there is no activity in the app. (only service). you need to change in "activity" to "do not launch activity"
This is the only answer that worked for apps without activity. Thank you.
This worked for me! I actually had a Default Activity in the Manifest, but for some reason Android Studio didn't find that.
I followed the aforementioned steps but now it says "The activity 'MainActivity' is not declared in AndroidManifest.xml" although MainActivity is there
I selected Launch: "Nothing" option and works for me :)
P
Peter Mortensen

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

Go to Edit Configuration Set Launch Option to Nothing


This is just skip the problem, but it doesnt fix it. The app wont run at the end of build after set to nothing
I did this. It didn't correct, but displayed an error that I could correct. After setting back to Default Activity, it worked. (My application isn't a widget)
R
Rahul Gaur

The correct way to do this is to add the following to the Manifest file:

<activity
    android:name="FULL_NAME_OF_YOUR_ACTIVITY"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

This should be inserted between:

<application> </application>

No need in invalidating caches.


Worked for me too! BUT NOTE: please write "android.intent.xxx" in lowercase letters - my fault was that the Android Studio completion suggested uppercase letters (this took me one hour) :-(
Good Point : "This should be inserted between: ". This was my issue. Thanks a lot.
Be very careful when refactoring your codes. in my own case, I mistakenly refactored 'category' as 'phone' thus, android.intent.category was changed to android.intent.phone.
I used Android Studio's project creation wizard and still had to do this manually. Am I wrong for thinking that is a bug?
P
Peter Mortensen

Try to right click on the project and choose Open Module Settings. Then go to the Sources tab in your module, find the src folder, right click on it and mark it as Sources (blue color).

There is no sources tab in later versions of Android Studio, but you can edit the build.gradle file instead: How to add a linked source folder in Android Studio?


This helped me out, I realized intellij dropped a lot of source files from the src in the Sources tab. I moved my package out of the project and back in. That solved my problem
I did this same kind of thing, but I right-clicked the src folder and went to "Mark Directory As..." and then "Sources Root." - Android Studio 0.8.6
Works like a charm, Removed the current root, and added the parent folder of src and gen again
a quick way to access the module settings is to click in the project navigator and press F4
this is deprecated since there is no Sources tab at Open Module Settings anymore.
P
Peter Mortensen

In Android Studio 4.0, please change Launch to Nothing:

Run/Debug Configuration → Android App → app → General → Launch Options → set Launch to Nothing.

https://i.stack.imgur.com/5E84W.png


Updating Android Studio to 4.x gave me this issue, tried the common stuff. Only this works!
This is not really a good solution to change to Nothing. It works, that is true, but the app will only be installed on the device and you have to run it manually. On my side I just had to check the Manifest file. I had 2 activities declared twice. Now, after removing the duplications, I can run the project without problems with "Default Activity" for launch options.
T
TouchBoarder

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


This is the solution when the project is a service, or has no default activity for some other reason.
In Android Studio 2.2.3; Run/Debug Configuration -> Android App -> myApp -> General -> Launch Options -> Launch : Nothing
P
Peter Mortensen

Nothing in the previous answers helped me. After some time I found that IntelliJ IDEA changed action names to uppercase. Like:

<intent-filter>
  <action android:name="ANDROID.INTENT.ACTION.MAIN"/>
  <category android:name="ANDROID.INTENT.CATEGORY.LAUNCHER"/>
</intent-filter>

After reverting to normal, IDEA recognizes the default activity:

<intent-filter>
  <action android:name="android.intent.action.MAIN" />
  <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

P
Peter Mortensen

Firstly make sure that you have the included default activity in manifest.

Example:

<activity android:name=".DefaultActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

If you have tried everything and nothing seems to works then

Delete the cache from your %Home%\.gradle\caches and sync project again.

Or check this answer:

Android Studio shows wrong file contents


Android Studio 3.2.1: File -> Sync Project with Gradle Files ::: Had to do this after invalidating cache and restarting before the problem went away.
This worked for me. What I believe caused this was moving my main activity to a different directory, downstream from the root.
P
Peter Mortensen

This solution is 100% working

You must be seeing this:

https://i.stack.imgur.com/uL5Q9.png

First open your manifest and check if this present,

  <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 not present, add it

If the above is present, but still you see default activity not found, follow these steps:

Click edit configuration On clicking edit configuration you'll see that launch option is set on DEFAULT ACTIVITY Change it to nothing.

Problem solved!


P
Peter Mortensen

In my case menu File → Invalidate Caches / Restart... didn't help.

Everything was OK with my project and of course I had the following intent filter for my activity:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

What really helped me was deleting the Android/Gradle cache folders (they can grow up to 10-30 GB).

Go to C:\Users\YOUR_USER_WINDOWS_NAME and delete the following folders

.android

.AndroidStudio3.2

.gradle

(You may save some Android configurations from .AndroidStudio3.2 before deleting it if you want it.)


P
Peter Mortensen

This method works for me. Click on the app icon and then choose edit configurations.

In the edit-configuration, choose the specified activity instead of the default activity. Then give the path of the activity below.

https://i.stack.imgur.com/GCYX8.png

https://i.stack.imgur.com/oODQN.png

In the end, synchronise with the Gradle files.


P
Peter Mortensen

Exit Android Studio.

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

Remove the /caches folder and the /tmp folder.


Oh my, it's only one solution which helps me when Android Studio broking its caches and think that some of my project files are broken. It's awful, but I'm really glad to find your solution on the second page)
P
Peter Mortensen

As this question is a "landing page" for plethora of issues with manifests, resulting in no Default Activity found, here is another thing to check if you are having this problem.

Open your manifest and switch to Merged Manifest tab.

Sometimes the issue is related to merging all the manifests in the project to one, which can result to error and therefore "Default Activity not found". The problem is this error is not shown anywhere except this Merged Manifest tab as far as I know.

For example: in a project minSdkVersion 10, downgrade the version of implementation in build.gradle file: from 25.4.0 to 25.3.1 solve this problem.

dependencies {
    implementation 'com.android.support:appcompat-v7:25.3.1'
    implementation 'com.android.support:design:25.3.1'
    implementation 'com.android.support:mediarouter-v7:25.3.1'

https://i.stack.imgur.com/EQ5N7.png


Wish I'd seen this before blowing four hours on finding the same thing. Must be a recent change.
P
Peter Mortensen

This occurred to me after my PC restarted unexpectedly. Strangely, I had made no changes and still got this error.

None of the above helped me. What solved my problem, was this.

Step 1:

https://i.stack.imgur.com/G2P0x.png

Step 2:

https://i.stack.imgur.com/K5y2M.png

Step 3:

https://i.stack.imgur.com/1kCfi.png

If this doesn't solve the problem give other tries.

Try 1:

Menu File → Invalidate Caches / Restart...

Try 2:

Check whether the following two lines,

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

are in your launcher activity declaration in file manifest.xml.

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

Try 3:

Click as shown: Run / Debug Configurations opens.

If this doesn't help either:

Try 4:

Menu File → Export to ZIP.

and

Import it as a new project.


That's very understandable, and much more valuable answer than the accepted one.
I just ran into this exact same thing with the merged manifest - would be nice if Android Studio had highlighted this tab to show that there was an error. :-/
the manifest one fixed my problem it told to increase min sdk version so i fixed it
P
Peter Mortensen

I changed my Intent-filter to

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

Just add the DEFAULT option as well. I was using the Process Phoenix library and it prompted me to define a default intent. This addition solved my problem.


P
Peter Mortensen

I got this error.

And found that in the manifest file in the launcher activity I did not put action and category in the intent filter.

The wrong one:

<activity
android:name=".VideoAdStarter"
android:label="@string/app_name">

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

</activity>

The right one:

<activity
android:name=".VideoAdStarter"
android:label="@string/app_name">

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

</activity>

P
Peter Mortensen

TouchBoarder almost had it. Although selecting "Do not launch Activity" results in nothing launching.

In Android Studio under Run/Debug Configuration → Android Application → General → Activity → select the option "Launch:"

Choose your Activity. This doesn't exactly fix the intended behaviour, but rather overrides it correctly.

https://i.stack.imgur.com/KwnsM.png


P
Peter Mortensen

All previous answers didn't help me.

Try to remove

<?xml version="1.0" encoding="utf-8"?>

in your AndroidManifest.

Then menu File → Sync Project with Gradle Files.


I figured out that just Syncing Project With Gradle Files worked fine as wine. By the way my error occurred from nowhere.
b
black

In case your application doesn't have an Activity (only a service for example), change the run/debug configuration 'Launch' option to Nothing.


M
Muz

I found this in my code:

<context android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</context>

If you look very carefully, it should be <activity android:name=".MainActivity"> instead.

Apparently, I refactored an "activity" somewhere, and it changed names in the AndroidManifest as well.


in my case the renaming of FilterClasses led to the tags :)
Be very careful when refactoring your codes. in my own case, I mistakenly refactored 'category' as 'phone' thus, android.intent.category was changed to android.intent.phone.
Isn't there some XML schema to detect such problems automatically (for example, to include in a test suite or build system)?
P
Peter Mortensen

In my case I refactored a member variable that was named "activity". I renamed it to "context"...

I found out that the refactor was made to the activity tags in the manifest, and I found them to be context tags instead... this is really stupid from Android Studio side!


this is a bug from Android studio, you are right @tere bentikh
P
Peter Mortensen

Menu Build → Rebuild Project Menu File → Invalidate Caches... → Invalidate and restart

It works for me.

Rebuild the project to make sure that there aren't any errors in the project. Then we can invalidate the cache.


P
Peter Mortensen

I have the same problem in Android Studio 3.3 Canary 3.

The project from the Android Studio 3.0 stable version works firstly correctly, but then after some cleans/rebuilds, it starts showing the No Default Activity error.

I tried to reinstall this alpha version of Android Studio: error again. But then I started it in the old stabile Android, and using APK install, and this APK file works correctly.

Moreover, my project was created with Instant App (base, feature, instant, and app subdirectories). I think this Android Studio has some problems with Manifest.xml files separated into this multiple directories.

So I have changed it in settings to this:

https://i.stack.imgur.com/gGsgW.png


P
Peter Mortensen

Sync Project With Gradle Files works sometimes.

To fix this overall issue you should:

Exit Android Studio Go to folder USER → AndroidStudio → system → caches Delete that folder Start Android Studio.

It will re-index your files and that should work.

Thanks to kirtan403 from a similar question.


P
Peter Mortensen

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

Remove HomeActivity from librarymodule Manifest whatsoever. Add: class AppModuleActivity1 : HomeActivity() to appmodule1 class AppModuleActivity2 : HomeActivity() to appmodule2 To appmodule1 Manifest inside application tag, I added: Same about appmodule2 but change 2 for 1 in naming.


S
Shah Nizar Baloch

This is still happening with Android Studio 4.0, so I have to delete the following folder to fix this problem:

C:\Users\my_user_name.AndroidStudio4.0\system\caches


P
Peter Mortensen

In my case, there was a typo in AndroidManifest.xml as shown below. Removing the "o" letter above the application tag solved it.

Apparently, Android Studio doesn't detect type errors in AndroidMainfest.xml

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

o
<application android:name=".AppName"
             android:allowBackup="false"
             android:icon="@drawable/ic_launcher"
             android:label="@string/app_name"
             android:theme="@android:style/Theme.Light.NoTitleBar">

As it works in one version and not work on another, it could not be the same problem as yours.
Thats why i said "in my case"
But isn't it syntactically correct XML (not a rhetorical question)? Is there an XML schema for it?
P
Peter Mortensen

Error: Default Activity Not Found

I solved it this way:

Run → Edit Configuration → Android Application → *enter the path of your default activity class in the "Launch" Edit Box.


What about on VS code?