Reputation: 358
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 :)
Upvotes: 4
Views: 13104
Reputation: 11
Android Studio Chipmunk | 2021.2.1
Edit Configurations ...
Launch Options:
helped for me.
Upvotes: 1
Reputation: 11
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"
Upvotes: 1
Reputation: 2013
You might have picked the wrong module from the picker to run the app. Try running your main module which contains the main activity.
Upvotes: 1
Reputation: 6635
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.
Upvotes: 0
Reputation: 46
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.
Upvotes: 1
Reputation: 22867
AndroidApp > app > General
GL
Upvotes: 1
Reputation: 1122
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)
Upvotes: 13
Reputation: 5925
I only had to remove my Gradle cache folder. On Mac this is located in ~/.gradle/caches
Upvotes: 1
Reputation: 1660
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.
Upvotes: 2
Reputation: 41
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.
Upvotes: 4
Reputation: 358
There is a chance that Android Studio itself could've been corrupted. Uninstalling and Reinstalling Android Studio solves the problem.
Upvotes: 2
Reputation: 3599
Close the project and Delete Cache
folder inside your C:\Users\UserName\.AndroidStudio3.3
folder and Build your project.
Upvotes: 12
Reputation: 185
Restart your android studio with option Invalidate Caches/Restart. You can find this option under file option. I think it will work for you.
Upvotes: 2