Default Activity Not Found - Bug in Android Studio 3.3 - android

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

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)

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

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.

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

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

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.

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

Run/Debug Configurations
AndroidApp > app > General
Module: app
Deploy: Default APK
Launch: Default Activity
GL

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.

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

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

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.

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.

Related

Android Studio: The activity 'MainActivity' is not declared in AndroidManifest.xml

I know that there are some similiar questions to this one but I've tried the suggestions that I found in the asnwers but none of them worked for me so I decided to publish my version of the problem.
I'm using this android studio project https://github.com/rosjava/android_core that has multiples modules inside as you can see. I had another project that I had to import to this android_core one so I downgraded its graddle version, since the version was more updated, and added it as an imported module.
After I fixed some building problems I got the "Default Activity not found" error which seemed odd to me since I had an activity marked to be the default activity so either way I decided to add it here too:
The next warning is the one on the bottom of the image which, once again, sounds odd to me since I had everything declared in the oringal project's AndroidManifest.xml file it's exactly the same on this one:
I have tried re-building, Invalidating Cache/Restarting and deleting and re-extend the AppCompactActivity class but nothing seems to work.
What am I missing? Thanks in Advance!
In the root of the manifest xml should be a manifest node with an attribute package. Make sure that the package 'com.example.prj_' is the value.
Then in your activity node you only have to place the value '.MainActivity'. Otherwise you can get some build errors for the resources in the R class.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.prj_">
<application
...>
<activity
android:name=".MainActivity"
...
</activity>
</application>
</manifest>
Add .MainActivity to your Android Manifest file.
<application
...>
<activity
android:name=".MainActivity"
...
</activity>
</application>
There are apparently race conditions with background computation of the merged manifest vs. automatic checks of it. The workaround would be to open AndroidManifest.xml and click on Merged Manifest, this forces the merge. Then clicking Run should pass the automatic tests.
See also https://issuetracker.google.com/issues/158019870
There are some ways to clean a project for removing this error.
1- File-> Sync Project with Gradle Files
2- Files -> invalidate cache / Restart
3- android:name=".MainActivity" --> android:name="com.example.prj.MainActivity"

Could not identify launch activity: Default Activity not found after upgrading to Android Studio 4.0

I've been having this problem since upgrading to Android Studio 4.0 on macOS. When I try to start my app from Android Studio, I get the following error:
Could not identify launch activity: Default Activity not found
Error while Launching activity
What's a bit unique about my project is that the default activity is defined in the manifest of another library used by my project, not the project itself. This was all working fine before the upgrade, but now it isn't for me. When I open the project containing the dependency, it builds and runs fine. I've already tried the following steps:
clean the project, rebuild
invalidate caches and restart
reinstall Android Studio
delete all generated files and folders (build, gradle, .idea, etc)
You can solve the problem as follows:
Click your Module Selection window,then click Edit Configurations…
Then set Launch Options to Nothing; that's okay:
To dovetail off of Mike N.'s comment, it looks like it is an issue to be resolved in the next point release: https://issuetracker.google.com/issues/158019870
For the details of the quick fix, for me I looked at the Merged Manifest tab, which is at the bottom-left of the AndroidManifest.xml pane. This shows all of the library manifests combined with your activity's.
The dialog said an error occurred where browser:1.0.0 manifest had a minSdk of 15 whereas all the rest of my minSdk are 14. I clicked on:
use a compatible library with a minSdk of at most 14, or increase this
project's minSdk version to at least 15.
Which brought up my minSdk to 15, and the error with the launcher went away, it will now insta-launch on my device. So I would sit tight for AS 4.0.1 but in the meantime, check the Merged Manifest.
For me this was happening in a project in which the main activity was declared in the manifest of an imported module (e.g. not in "app" module).
The solution for me was to add again the activity declaration in the manifest file of my top project:
<activity android:name="com.cristian_slav.elements.MainActivity"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
On my side it was a issue with the manifest. You can detect this type of issue by watching the merged manifest tab. For more details you can watch the link shared by Mike N. in the first comment.
The problem will arise in new projects when one forgets to tick the default activity checkbox during adding anyone of the first or subsequent new activity.
This can be rectified at later stage by going to Run> Edit Configurations > Launch : in which change to specified activity and select the activity you choose to keep as the first page on launch of app.
Try these steps:
Close Android Studio
Go to
C:\Users\my_user_name.AndroidStudio4.0\system\caches
Delete "caches" folder
Relaunch Android Studio
set Launch Options to (Nothing)

"Error running com.example.flutter_launcher. Default activity not found" after changing AndroidManifest

I added this 2 lines in AndroidManifest.
<category android:name="android.intent.action.DEFAULT" />
<category android:name="android.intent.action.HOME" />
Now I get this error, even after reverting the changes.
Error running com.example.flutter_launcher. Default activity not found
Unable to read manifest info from D:\src\flutter_launcher\build\app\outputs\apk\app.apk.
No application found for TargetPlatform.android_x86.
Is your project missing an android\app\src\main\AndroidManifest.xml?
Consider running "flutter create ." to create one.
I ran "flutter create ." with no luck.
Deleting D:\src\flutter_launcher\build\app\outputs\apk\app.apk worked for me.
Looks like Android Studio detects that it's missing and rebuilds it. This issue is likely caused because you opened a second Android Studio for platform integration with the Android platform, and the Flutter Android Studio didn't detect a manifest change and didn't rebuild the APK.
I fix this problem with :
flutter clean
flutter pub get
I used the above solution still was getting issues of manifest not found or default activity then I removed code which I have added in manifest and separately open the android folder and made changes in it and run the app from there. It worked.

Default Activity not found in Android Studio

I just upgraded to Android Studio 0.2.8 and I am getting an error that says "Default Activity not found" when I try to edit the run configurations.
When I launch Android Studio I get this error "Access is allowed from event dispatch thread only"
The activity I am using is a fragment activity.
So far I've tried rebuilding and invalidate caches/restart. Both were of no use.
Please let me know what I can do to fix the problem.
Have you added ACTION_MAIN intent filter to your main activity? If you don't add this, then android won't know which activity to launch as the main activity.
ex:
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="com.package.name.MyActivity"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
In Android Studio, 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).
EDIT: There is no sources tab in later versions of Android Studio, but you can edit the build.gradle file instead: https://stackoverflow.com/a/22028681/1101730 (thanks for comment Josh)
I had the same problem while importing a project into Android Studio, probably caused by the fact that the project has been developed on an earlier version of Android Studio than currently installed on my computer.
What solved it was simply choosing:
File -> Invalidate Caches / Restart...
and then selecting Invalidate and Restart.
If you don't have the tab and you started with an empty activity try this.
Below is a sample code example:
<application android:label="#string/app_name">
<activity android:name=".HelloActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Now go to your AndroidManifest.xml file. Next copy the intent filter from this code. Look at your manifest file really good and paste the intent filter in the exact place it is in the code above. (after the .yourActivityName> part of the manifest.) I hope this helped.
If you are still getting an error that says "Default Activity not found" when you try to edit the run configurations even after executing:
Invalidate cache and Restart.
Then try deleting the Settings/Preferences folder:
/< USER_HOME_DIR >/.AndroidStudioPreview3.2
or on Mac :
/Users/<USER_NAME>/Library/Preferences/.AndroidStudioPreview3.2
When I clicked "Open Module Settings", there was no "Source" tab, I think because that's been removed for newer versions of Android Studio (I'm on 0.8.14). So I had to do this instead:
Add these lines to the build.gradle file inside the android { ... } block:
android {
...
sourceSets {
main.java.srcDirs += 'src/main/<YOUR DIRECTORY>'
}
}
After editing the file, click Tools > Android > Sync Project with Gradle Files.
Credit to this answer and this comment.
Following did the trick for me. From Run -> Edit Configuration.
My problem came down to an additional error that was popping up sometimes, stating
Manifest Merger failed with multiple errors in Android Studio
What ultimately was causing my problem was the fact that there were multiple manifests (a debug Manifest, and a manifest in the new module I had just imported), and they were not merging correctly due to this. After seeing this answer, I was able to analyze the merged manifest and find the cause of the issue and fix it.
Press app --> Edit Configurations
After that change value in Launch on "Nothing"
this happened to me because I capitalized the paths in the manifest. changed:
<intent-filter>
<action android:name="ANDROID.INTENT.ACTION.MAIN"/>
<category android:name="ANDROID.INTENT.CATEGORY.LAUNCHER"/>
</intent-filter>
to
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
and it was fixed
I ran into the same issue today and was going through the answers here.
For me the difference was that yesterday it worked fine, so I figured it could not really be a configuration issue, neither configuration nor Version of Android Studio changed.
Fortunately, I tried a restart of Android Studio before trying any of the other answers, and luckily that solved the issue.
So for all people out there who run into this: first thing to try is to restart Android Studio and only if that does not solve the issue try the other answers here.
I just experienced the same error in Android Studio 1.5.1. and just found the source of the problem. I am not sure whether the cause was a human error or some strange glitch in the behaviour of the IDE, but none of the existing StackOverflow questions about this subject seemed to show anything about this so I figured I post it as an answer anyway.
For me, either one of my team members or the IDE itself, had changed the launcher activities manifest entry, causing it to look like this:
<activity
android:name="com.rhaebus.ui.activities.ActivitySplash"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<id android:name="android.intent.id.LAUNCHER" />
</intent-filter>
</activity>
While it should, in fact, look like this:
<activity android:name="com.rhaebus.ui.activities.ActivitySplash"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <!-- Change Here -->
</intent-filter>
</activity>
So please double, triple, quadruple check the format of your launcher activity in the manifest and you might be able to save yourself some time.
Hope this helps.
EDIT:
I strongly suggest people not to go with the answers that suggest to manually select a launcher activity inside the configuration options of your module, as this caused the application to no longer be shown in the list of installed apps on both the Samsung Galaxy S5 Neo and the Samsung Galaxy S6 (at least for me).
You can get Android Studio not to complain by going to the "Edit Configurations" menu (tap "Shift" three times, type "Edit Configurations"), then change Launch Options > Launch to "Nothing".
I'll probably add a generic activity containing instructions, just to avoid any confusion.
Please make sure in manifest that package name is same with your main activity
In Android Studio switch to Project perspective (not Android perspective).
Make sure that your project follows the gradle plugin's default structure (i.e. project_dir/app/src/main/java...)
Delete all build folders and subfolders that you see.
In the toolbar click Build -> Clean Project, then Build -> Rebuild Project.
Try to run the project.
In my case, it worked when I removed the .idea folder from the project (Project/.ida) and re-opened Android Studio again.
Right click on the project and choose Open Module Settings.
Go to the Sources tab in your module.
Find your src folder.
Right click on it and mark it as Sources.
This solved the error in my case.
If you changed name of directories (class structure) for example com.dir.sample to com.dir.sample1, after that don't forget to change package com.dir.sample to com.dir.sample1.
Modify "Workspace.xml" (press Ctrl + Shft + R to search it)
Modify the activity name with package name
Make sure to change "name="USE_COMMAND_LINE" to value="false"
Reload the project
Done!
For those like me who were struggling to find the "Sources tab":
Here you have to mark your "src" folder in blue (first click in Mark as: Source, then in your src folder), and you're good to go.
There are two steps you can take:
Go to configurations and enter the name of activity to be launched
If it is still not working Disable Instant Run
I have tried all solutions, but not working at all.
than I have tried to disable Instant run in my android studio.
Go to Android Studio Settings or Preferences (for MAC) -> Build,Execution,Deployment -> Instant Run.
uncheck the Instant run functionality and than after click sync project with gradle files from file menu
now run your build...
In some case you can have model with some category field, if you will refactor it in all places, it may refactor it in manifest file and then and the tag xml will became invalid.
Many possibilities can be happened for this kind of case (Default Activity not Found)
If all code are fine, especially on Manifest, just just need to Invalidate Cache and restart the studio,
But sometime it is happened when you have duplicate activity declaration on manifest, not only for the Main activity, it is also triggered by child activities as well.
That happened with me, Default activity not found because i have duplication child activities on manifest, after deleted that, everything is well
Check if there is any duplicate tag in your AndroidManifest.xml file.
I figured it out. I mistakenly added final keyword in activity declaration. Once I removed it everything works!
public class SplashActivity extends AppCompatActivity {
...
}
In my case, this happened because of sudden shutdown of the system.
I followed these steps:
Close Android Studio
Go to
C:\Users\my_user_name.AndroidStudio4.0\system\caches
Delete "caches" folder
Relaunch Android Studio
In Android Studio
Go to edit Configuration .
Select the app.
choose the lunch Activity path.
apply, OK.
Thanks!!
Default Activity name changed (like SplashActivity -> SplashActivity1) and work for me

Android R.java will not generate in Eclipse

I am running Eclipse 4.2.2 Juno on Windows 64-bit for development on Android SDK 17 with ADT. Just today, I cleaned a working project, only to find that the R.java file would no longer generate.
This problem has a very divergent list of possible causes. User Gray, in response to the thread located here, listed a set of articles, all addressing different possible causes.
He says:
Dont worry. First you may clean the project, then run the project. If
this does not work then follow the following links:
And then proceeds to list articles pertaining to different causes of this problem, the links to which I am unable to include, but can be found in the question linked to above.
Gray's comment is a good summary of the most common causes to this problem, including resource file naming convention, the erroneous "import Android.R" statement, XML errors, corruption requiring cleaning and rebuilding, and checking the Android SDK in Project -> Properties -> Java Build Path / Libraries.
The problem is, my R.java still doesn't generate! The only remaining possibility within Gray's list seems to be that either my main.xml or AndroidManifest.xml is broken, so I have included them to make sure I didn't miss any errors.
My main layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.bostonwalker.sseng.SSSurfaceView
android:id="#+id/ssview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
And my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bostonwalker.enginedev"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
As a beginner Android programmer, this is beyond my capability to debug. Can someone please find an explanation?
First check if there are any errors in your resource file's. R.java will not be generated if that's the case. Check if you have updated your adt to rev 22. If so follow the below
Right click on your project goto properties. Java Build Path. Choose Order export tab. Make sure that Android Private Libraries is selected. If you have referenced library project. do the same for the library project also. Clean and Build.
Also goto android sdk manager and check that you have the android sdk build tools installed. This many not be necessary but make sure you have android build tools installed.
Check the link below
Eclipse error: R cannot be resolved to a variable
Whenever your generated R class isn't generated, it indicates that there's a problem with generating it due to some parsing issue from the XML resources. Check the error console in your IDE to figure out what's specifically wrong.
Common problems are:
An unescaped character in your strings.xml, for instance you're instead of you\'re
Missing layout_width or layout_height tags in layout resources
Missing namespace declarations
Variable names that aren't supported by Java, for instance due to capitalization or use of spaces, hyphens or other unsupported characters
Any other kind of syntax error in XML
In addition to what Reghunandan said, I just had the same issue after updating to SDK 22 with Eclipse Indigo Win x64. Turns out that when updating the SDK Manager uninstalled the old Build Tools and never installed the updated ones so I had to run it through again to get them reinstalled. Doing this fixed my issue and all the build errors disappeared.
Note: I had to restart Eclipse before the errors disappeared, even though I wasn't prompted to.
I faced a similar issue and found that I imported com.google.android.gms which had a reference to google-play-services.jar. So once I added the path of google-play-services.jar in my apps libraries, R.Java is generated.

Categories

Resources