0

I'm new to android studio. I recently made a new project with default MainActivity, then deleted the activity and made a new Activity that i set as default in AndroidManifest.xml by adding

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

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

Since I did that, my whole android studio broke down. I couldn't run any app I previously made or any project I created since then. After hitting run/Shift+F5 it just says

 Error running 'app': Default Activity not found

It does this on any project I open/newly create. I am not able to launch with default or any activity, it just says that it isn't declared in manifest file. If it is a newly generated project, it usually won't even launch. I have to sync it with gradle files. After that I am able to sometimes run it, but after every android studio restart it breaks again. Some of my bigger projects were able to start after around 4-5 clean projects and gradle syncs, but broke down again after android studio restart. I have reinstalled android studio and build tools multiple times and I am all out of ideas. Every build or gradle sync is successful without errors, it just can't find the activity to run.

  • do both activities use the same name? can you post your entire manifest please? maybe you're missing a tag, or have a hierarchy issue – Nikos Hidalgo Dec 03 '18 at 16:46
  • I am 99% sure all my manifest files are correct. Even newly generated codes or codes that work on other devices are not runnable for me. But this is my Manifest file https://imgur.com/QDJlOqn .It's newly generated project with one default activity and it says default activity not found. – Marek Berka Dec 03 '18 at 17:06
  • https://stackoverflow.com/questions/15825081/error-default-activity-not-found – Adeel Ahmad Dec 03 '18 at 17:15
  • already looked at that post, i tried File -> Invalidate Caches / Restart... After doind this it sometimes works, but restarting android studio breaks the project and makes in unrunnable again – Marek Berka Dec 03 '18 at 17:25

1 Answers1

0

If none of these other troubleshooting options work, such as Invalidate Cache/Restart and Syncing Gradle, it may be the project setup itself.

Most Android Studio projects need at least one module. A module is a way to divvy up the source code based on different devices being targeted (e.g., you may need one for Android TV, one version of your app for Android Wearables, etc.). You can find more info here on that: https://developer.android.com/studio/projects/add-app-module

So make sure you have a module (typically named app or if it's the only one, lower-case version of your app's name maybe). It should have the source code, assets & res folders (drawables and launcher icons and such), the AndroidManifest.xml, and its own build.gradle file separate from the main project's. It doesn't have to have much in there other than where to look for library repositories.

Just ran into this issue when migrating an old project to Android Studio 4.0, this seemed to do the trick.

EDIT: Still working on it, looks like it will run the first time and then it recognizes "No Default Activity" and stops me from running/installing.

EDIT: Figured it out. It is a new issue with AS 4.0 where the merged manifests had a library (from androidx compatability library) that targeted minSdk=15 instead of 14 like I previously had. It appears when I click on that error in the Merged Manifest tab when I have AndroidManifest.xml open (bottom-left of the pane) I am able to run as normal again. See here: https://issuetracker.google.com/issues/158019870

A13X
  • 409
  • 1
  • 6
  • 27