4

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

Umesh Konduru
  • 361
  • 1
  • 6
  • 19

13 Answers13

13

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.

(Refer image for better reference) enter image description here

Astha Garg
  • 1,022
  • 7
  • 21
12

Close the project and Delete Cache folder inside your C:\Users\UserName\.AndroidStudio3.3 folder and Build your project.

Sabyasachi
  • 3,499
  • 2
  • 14
  • 21
  • 4
    Caches folder is located in C:\Users\UserName\.AndroidStudio3.3\system folder in my PC – Faraz Ahmed Jun 15 '19 at 05:03
  • 1
    I have same issue. i updated android studio to 4.0. cleaned project, invalidate restart and sync project not worked for me. – Nitish Jun 08 '20 at 06:53
  • Yeah, I believe deleting this `caches` dir is the same as selecting *Invalidate Caches / Restart* from within Android Studio – Sterling Aug 09 '20 at 16:27
  • 1
    @String This answer worked for me, but _Invalidate Caches / Restart_ did not. A test demonstrates that _Invalidate Caches_ does not clear out the contents of the "system/caches" folder. – greeble31 Sep 27 '20 at 22:26
4

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.

2

Restart your android studio with option Invalidate Caches/Restart. You can find this option under file option. I think it will work for you.

RANAJEET BARIK
  • 185
  • 2
  • 7
2

There is a chance that Android Studio itself could've been corrupted. Uninstalling and Reinstalling Android Studio solves the problem.

Umesh Konduru
  • 361
  • 1
  • 6
  • 19
2

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.

William T. Mallard
  • 1,562
  • 2
  • 25
  • 33
  • 1
    I didn't read this carefully enough and thought it was saying you need the `DEFAULT` and `HOME` entries but it is saying you need `LAUNCHER` now – Jim W Jul 02 '20 at 19:29
1

I only had to remove my Gradle cache folder. On Mac this is located in ~/.gradle/caches

dell116
  • 5,835
  • 9
  • 52
  • 70
1

Run/Debug Configurations

AndroidApp > app > General

  • Module: app
  • Deploy: Default APK
  • Launch: Default Activity

GL

Braian Coronel
  • 22,105
  • 4
  • 57
  • 62
1

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.

shizhen
  • 12,251
  • 9
  • 52
  • 88
1

You might have picked the wrong module from the picker to run the app. Try running your main module which contains the main activity.

luckysing_noobster
  • 1,933
  • 5
  • 24
  • 50
1

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"

See this screenshot

Sourcerer
  • 1,891
  • 1
  • 19
  • 32
1

Android Studio Chipmunk | 2021.2.1

Edit Configurations ...

Launch Options:

  1. replace "Default Activity" by "Nothing"
  2. Run app (worked!) Launch Options again:
  3. Replace "Nothing" again by "Default Activity"
  4. Run app (terminate running app)

helped for me.

eic
  • 11
  • 2
0

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.

Sterling
  • 6,365
  • 2
  • 32
  • 40