'Default Activity Not Found - Bug in Android Studio 3.3
When I create a new project in Android Studio 3.3, it shows an error at Run -> Edit Configurations saying
default activity is not found.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
This is my activity_main.xml file. It shows an error in line
tools:context=".MainActivity"
saying
Unresolved Class MainActivity
Here is my AndroidManifest.xml file - everything seems to be all right here -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
The files colors.xml , ic_launcher_background.xml, and ic_launcher_foreground.xml are not correctly formed, and look something like this -
f
isInitialized
kotlin
Boolean
reflect
KProperty0
SinceKotlin
version
1.2
internal
InlineOnly0
4" 8�H PX�� (� �
I tried to Clean and Rebuild project, which gave an error saying
colors.xml is not formed properly.
I tried File -> Invalidate Caches/Restart, but it still shows the same error.
This problem started one day after updating Android Studio 3.2.1 to Android Studio 3.3. It worked all fine the first day, but when I tried run an app on the second day, it started showing this error saying Default Activity not found.
Is there any way to fix this issue and continue using Android Studio version 3.3?
EDIT -
Yay! As @Andreas suggested, my Android Studio itself could've been corrupted, and works all right after uninstalling and reinstalling the same version (I did not even revert to an older version). Should check if this problem might repeat again in a few days.
EDIT 2-
I'm viewing this after an year and I'm happy it has helped a lot of people. Turns out this problem can arise due to various issues, and there's no one perfect answer for this. So check all the answers and see if something works for you if you're facing the same problem :)
Solution 1:[1]
After searching a lot this is what worked for me,
Go to Edit Configuration -> Select your Application Module -> Under Launch Options -> Select Nothing from Launch drop down.
Solution 2:[2]
Close the project and Delete Cache folder inside your C:\Users\UserName\.AndroidStudio3.3 folder and Build your project.
Solution 3:[3]
I had the same problem with version 3.4. Goto Build -> Edit Build Types -> SDK location and checked Use embedded JDK (recommended). It worked fine.
Solution 4:[4]
Restart your android studio with option Invalidate Caches/Restart. You can find this option under file option. I think it will work for you.
Solution 5:[5]
In Android Studio 3.5.2 my custom launcher/custom home app is getting this error. I was able to reproduce it by creating a brand new blank activity app, then replacing
<category android:name="android.intent.category.LAUNCHER"/>
with
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
in the manifest. That single change causes Android Studio to lose track of the default activity. I'm able to continue debugging by specifying the activity in the Run/Debug configurations.
Solution 6:[6]
I only had to remove my Gradle cache folder. On Mac this is located in ~/.gradle/caches
Solution 7:[7]
Run/Debug Configurations
AndroidApp > app > General
- Module: app
- Deploy: Default APK
- Launch: Default Activity
GL
Solution 8:[8]
With Android Studio 3.6.2 this situation can arise with gradle updates. I found adding rootProject.name='YourAppName' above include ':app' in the settings.gradle file will resolve this issue once you invalidate the caches and restart Android studio, or close out the app and Android Studio and then restart them.
Solution 9:[9]
You might have picked the wrong module from the picker to run the app. Try running your main module which contains the main activity.
Solution 10:[10]
I faced similar problem and the reason was in Manifest merging. There was an error, so it wasn't merged correctly. After solving that error everything goes right.
To check if there are errors while merging go to your AndroidManifest.xml and tap Merged Manifest tab. There would be "Merging Errors"
Solution 11:[11]
Android Studio Chipmunk | 2021.2.1
Edit Configurations ...
Launch Options:
- replace "Default Activity" by "Nothing"
- Run app (worked!) Launch Options again:
- Replace "Nothing" again by "Default Activity"
- Run app (terminate running app)
helped for me.
Solution 12:[12]
None of the other solutions here worked for me, but this error went away after I added the following to my app module's build.gradle file (chasing a different problem):
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Worth a try, anyway.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow

