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
Related
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"
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)
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.
I am using ADT 23.0.2.
I just imported the google-play library to my workspace and added the reference to it in my project.
Now nowhere in my project the resource ids can be recognized because there is no R file.
(Anywhere I have R.id.blah I get the error "R cannot be resolved to a variable);
It's just gone. What am I supposed to do?
I exactly followed the steps by developers.google.com. It's nothing complicated but I don't know why this happened.
(I have all layout files in place and no import for android.R are in my class files.)
Before adding the
Tools I use:
Here are screenshots from my app properties:
My manifest
<permission
android:name="com.appname.appname4.MAPS_RECEIVE"
android:protectionLevel="signature">
</permission>
<uses-permission android:name="com.appname.appname4.MAPS_RECEIVE"/>
<activity
android:name="com.appname.appname4.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>
<activity
android:name="com.appname.appname4.SearchResultListActivity"
android:label="#string/title_activity_search_result_list"
android:parentActivityName="com.appname.appname4.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.appname.appname4.MainActivity" />
</activity>
<activity
android:name="com.appname.appname4.ContactInfoActivity"
android:label="#string/title_activity_property_detail"
android:parentActivityName="com.appname.appname4.SearchResultListActivity"
>
</manifest>
I had similar issues when I first started Android programming. Here are some fixes that worked for me in the past.
1. Fix/Check all xml(layout) files.
Many times a R file not being generated is due to an issue with your layout file or Android Manifest file. Follow this link and work your way down the page checking permissions and the general layout format.
2. Project/Clean.
go to Project->Clean.
Also make sure you have selected the option to build project automatically.(Without this option check marked R file is never generated automatically).
3. Fix Project Properties.
Right click on your project in Package explorer then choose fix project properties.
Repeat Step 1 after this.
4. Builders.
Go to Project->Properties then Builders. Select the appropriate boxes.
Repeat Step 1, and Clean and rebuild project.
5. Appcom7 and Google Play services error.
Sometimes to fix errors associated with installing these two reference libraries. I copy there folders into a generic library folder on my hard(where I keep most of my eclipse reference libraries), after this I delete them from the Package explorer and from the "default" directory where they were installed. I Fix project properties again and clean/rebuild. This should get you back to your non-reference library version of the package. Then I manually add them as Projects to my eclipse IDE and finally follow this to add them as references to my project. Then fix project properties,clean and rebuild.
6. Reference Question.
Finally, referring to this StackOverflow page has helped me countless times. And one way or another fixed my issue.
Good Luck.
I just installed Android Studio 0.6.1 and imported a project from Eclipse. When I tried to run the project, I got Error: Default Activity not found.
I looked at these two StackOverflow questions:
Error: Default Activity Not Found
Default Activity not found in Android Studio
As suggested, I tried to invalidate the caches + restart and make sure my AndroidManifest was correct. Both didn't work.
I also tried this solution, but to no avail:
Try to 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).
When I opened the module settings, there was no sources tab.
How can I fix this problem?
Is there there any equivalent of the sources tab in Android Studio 0.6.1?
Edit:
Here's the launcher activity
<activity
android:name="com.lschlessinger.appname.activities.SplashScreenActivity"
android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I also tried cleaning my project, rebuilding my project, and restarting Android Studio, all of which, did not resolve the problem.
As a temporary solution, I'm manually selecting the launcher activity in the run configuration.
I encountered the same question. Finally I resolved the question.
My Manifest file is like this:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
and it should be:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
In the worst, if it cannot resolve you question, you can create a new activity and select as Launcher activity to see whether it's resolved.
It seems that you don't have any default activity. Create a new
activity by File -> New ->Activity and select as Launcher activity.
Switch to Android Studio 0.8.+.
This fixed the issue.
In my case it was a third-party library with invalid Manifest which defined another main activity. As you know, Gradle combines Manifests, so my application contained two main activities. When I fixed library Manifest this error also gone.
***************Simple Solutution**********************
This problem occurs because of caches.
If You are using Android Studio.
File---->Invalidate Caches/Restart.
Click on it and choose Invalidate Caches/Restart.
Perhads Build-> Clean Project, then Build-> Rebuild Project, then restart AS. source
It seems that you don't have any default activity.
Create a new activity by File -> New ->Activity and select as Launcher activity.
That should work.