Manifest changes undoing after build - android

I made changes to my manifest (adding a new activity). I copy and pasted someone else's code (was my first time setting a parent activity). I accidentally built with the wrong code and it gave me an error about resources (which I understand). I then made the changes to the manifest, but every time I build or clean, it reverts it to the original version and spits out the errors for that. I can't find anything about building undoing code, so I appreciate any help.
<activity
android:name="com.willnasby.your_turn.HistoryActivity"
android:label="History"
android:parentActivityName="com.willnasby.your_turn.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.willnasby.your_turn.MainActivity" />
</activity>
keeps being reverted to
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
every time I try to build.
Thanks.
EDIT: I read another post about how my versions might not be synced with gradle, but I did and it's still reverting.

I think you are modifying the Manifest in the build folder rather than the SRC folder. If you change the SRC one, that should resolve the issue.

I had the same thing happen repeatedly just as described (in Android Studio) which brought me to this thread. Changing the manifest file to change the package path and doing a rebuild all would simply overwrite my changes.
I managed to get past it by 1) only changing one item in the manifest file (to reflect the correct package) versus trying to change several lines at once 2) rebuilding all 3) pressing run. After the attempt to run, Android Studio figured out what was going on and automatically fixed my manifest file with the proper package paths.

I guess you are opening debug/AndroidManifest.xml , try opening main/AndroidManifest.xml it will come right

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)

Android Manifest Merge issue - Removing google ads gradle dependency doesn't remove its AndroidManifest.xml nodes

I am having two product flavors in the project (1) free (2) pro
I am including google ads library only to the free product flavor as below
freeCompile 'com.google.android.gms:play-services-ads:11.4.2'
Now I want to replace it with another ad library. I am trying to remove this dependency but it doesn't remove the library completely and gives me an error as below. Hence it doesn't let me build the project.
The screenshot is of AndroidManifest.xml from the app\build\intermediates\manifests\full\free\debug. Also I have not manually added these two activities (com.google.android.gms.ads.AdActivity & com.google.android.gms.ads.purchase.InAppPurchaseActivity) to the main AndroidManifest.xml.
What I have tried to remove these two activities from AndroidManifest.xml is
Clean, Build, Rebuild
Restart Android Studio
Invalidate caches / Restart Android Studio
Changing the project flavors & cleaning.
Removing the dependency from the Android Studio 'Project Structure'
But nothing seems to be working. How can I get rid of these errors and build my project?
After a day long hassle, I managed to fix it using this official Android guildeline - Merge Multiple Manifest Files
tools:node="remove" did the trick.
I have manually removed those two activities that are the part of google sdk. Here is what I have added to the main AndroidManifest.xml
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:exported="false"
android:theme="#android:style/Theme.Translucent"
tools:node="remove" />
<activity
android:name="com.google.android.gms.ads.purchase.InAppPurchaseActivity"
android:theme="#style/Theme.IAPTheme"
tools:node="remove" />
Hope it helps to someone.

After adding google-play-service_lib my resourceIds cannot be recognized

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.

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

Categories

Resources