Non-existing icon generated in manifest - c#

I created a project with a template that included a launcher icon called Icon. I received the right one to use so I changed it, and named it ic_launcher.
I changed the name on the manifest:
android:icon="#drawable/ic_launcher"
And in the launcher activity annotation:
[Activity(Label = "[...]", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, Icon = "#drawable/ic_launcher")]
When I build the project, the IDE generates a complete AndroidManifest (located at \obj\Debug\android\manifest\AndroidManifest.xml) that contains the right icon names, except for this line:
<activity android:configChanges="[...]" android:icon="#drawable/icon" android:theme="[...]" android:name="[...]" />
Which says; android:icon="#drawable/icon". I searched the text in the project and found nothing.
The file is generated in every build, so no matter what I try, it's always changed back and thus, I can't deploy.
Any ideas?
Yes, I know I can just rename ic_launcher to Icon but I want to try to do the right thing first.
Thanks.

Android by default takes up 'ic_launcher' drawable which is an Android Logo. Trying changing the name to something different like 'app_logo' and try refreshing/Cleaning and rebuilding the project.
UPDATE:
As the change of name doesn't work yet, follow these steps.
Uninstall the app completely and try building and installing.
Make sure the icon with the other name say 'app_name' is placed in all density folders.
Ensure that you don't have an Icon Activity definition in your Main Activity because this overrides the manifest. It a very common situation.
More info on this here
Hope this helps.

After an internal talk, it turns out a library was generating that activity declaration. That definition was then added to the manifest of the project and causing the issue.

Related

Xamarin.Android: Problems changing the application icon from the default icon

I just started learning how to develop for Android a few days ago, so I'm still in the process of learning all the ins and out of the environment. Recently, I finished writing the functionality for a basic Contacts app and decided to turn to fixing some of the finer points of the UI. I have been trying for the last couple of days to change the launcher icon for the app from the default Android icon Default Icon to one that I selected Selected Icon. However, nothing I seem to try will allow the icon I selected to appear on the device I am testing on.
I added what is supposed to be the proper line in the Android Manifest file as seen here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="Contact_Manager.Contact_Manager" android:versionCode="1" android:versionName="1.0" android:installLocation="internalOnly">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:label="Contacts" android:icon ="#drawable/contacts-3"></application></manifest>
But this solution did not work. I also tried deleting the default icon from the drawable folder(I also saved a copy of it elsewhere) but it still showed the default Icon on the device screen. I then tried to uninstall the application on the device in order to clear all the cache files, but was met with the same outcome. Is there something I'm doing wrong?
Note: I am also new to StackOverFlow so I apologize if the formatting of this question is awful.
I suspect you have not deleted all the versions of default icon. In android there is a icon for each screen density in drawable-mdpi, drawable-hdpi, etc folder. Hence search for that file and remove it from all the folders and try again.
You need to add fresh icons for each density.
UPDATE 1 :
I think I know the problem now. Right click the project on solution explorer. Then click on options. Then Build-Android Application.
Change the application icon there.
Delete the default icon.png files from all the Android drawable folders, and save your new icon as icon.png. Also make sure that in the manifest you point to the icon file:
<application android:label="<Your app name>" android:icon="#drawable/icon"></application>
Try with a different icon name
Copy the new icon(myIcon.png) into mipmap- folders.
Update the icon value in Android project MainActivity.cs file
Uninstall the application from your device and try again.
Had the same issue. Deleted the old icons (maybe you only removed them from project not deleted them? I dont know) and tried building. It threw errors wherever the old icon was referenced so I was able to trace the issue. Also removing the old and adding the new with the same name (Icon.png) worked for me

C# Visual Studio using the wrong .exe icon

I first added "icon1.ico" to my project under Properties->Application. When I build it my .exe had "icon1". After this I decided to change the icon to "icon2.ico", which I added in the same way and selected. The little icon beside the dropdown menu shows "icon2". However, when I build the project it still uses the old "icon1".
Then I removed the old icon from the project, and rebuilt. Still the same old icon.
I then changed to the "default icon" in the dropdown (the dropdown only shows "icon2" and (default)) and rebuilt. The exe then has the default icon. Changing back again to "icon2", and the exe has got "icon1", dispite it not being in the project anymore.
How can this be?
I managed to find what was wrong.
In my Solution I had 3 projects. For some reason, dispite being seleted as the startup project, all my cleaning and rebuilding attempt seemed not to affect the project with the wrong icon (this includes deleting the bin folder), the only project that was being build was one of the other two (the output still said 3 build successfull, with 0 up to date).
What solved it was to right click on the specific project and select rebuild, which applied the correct icon.

Xamarin.Forms Windows 10 Universal Error "CS0103 InitializeComponent does not exist"

I have a working Android Project with a .Droid-Solution and a SharedProject. I started the App on my phone and it works great. Now, I just added a blank Windows 10 Universal Solution and did the instructions here: http://developer.xamarin.com/guides/xamarin-forms/platform-features/windows/installation/universal/
Anyway... I did nothing else. Just followed the instructions and tryed to start the Windows 10 Universal app, but I get this error:
"CS0103 C# The name 'InitializeComponent ' does not exist in the
current context."
I googled a few times, but didn't find something that helps.
I also tryed the example here: https://github.com/jamesmontemagno/Hanselman.Forms with the same error.
Does someone know this error with Xamarin.Forms and Windows 10 Universal Apps?
Everytime you create a .XAML page in Xamarin.Forms, you are using partial class definitions in three different places.
Your actual .xaml file will have a Class="" attribute on the root element that defines the namespace and class name.
The actual root element type will define the base class that your new .xaml page is subclassing. By default, that would be ContentPage.
You also get a .xaml.cs file that is linked which contains a partial class definition as well. This is your code behind file, where you put page specific code, this is also where the InitializeComponent() call is called from the constructor.
This call serves to parse the xaml contents and fill out the references to all the views you gave ids to using x:name="something" in xaml.
InitializeComponent() is automatically generated by xamarin, it is part of the output of your project and it should get re-generated each time you edit your .xaml file.
In order for this to happen, in the properties of your .xaml file Build Action needs to be set to "Embedded Resource" and the Custom Tool needs to be set to "MSBuild:UpdateDesignTimeXaml"
Now, even with these values set correctly, there are bugs in Xamarin which can lead to the file not getting generated and you getting the error.
The absolute first thing to try when you get this error is to right click the .xaml file and click on "Run Custom Tool".
You only need to do this once, on ONE xaml file, the tool will automatically run for all the .xaml files in your project.
This is somethign that I have to do about once a day during my normal development and it started when i switched to VS 2015. Your mileage may warry.
Another very important thing to check is the BuildTargets in your .csproj file.
The way Xamarin is able to do it's thing is by specifying build actions that call into it's DLL that you get when you install the Xamarin.Forms nuget package. Sometimes the build actions import line get's messed up and this causes all sorts of problems.
Unload your .csproj and find the line that imports Xamarin.Forms.targets.
It should look something like this:
<Import Project="..\..\packages\Xamarin.Forms.2.0.0.6484\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.0.0.6484\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
make sure that the version in here matches the version of Xamarin.Forms from your packages.config file, then make sure that you can actually navigate to your project's root folder, and find the actual file the important line is referring to. Ie, packages\xamarin...\Xamarin.Forms.targets
A common thing to do is to delete everything from \packages\ and let nuget re-download everything on your next build. Just make sure the version in your .csproj import and the version in packages.config is the same.
If all of these are done, you should have a valid generated partial class that implements InitializeComponent() and the errors should dissapear.
Just as an update to this:
New, clean Windows 10 Pro installation with all updates in a VM.
New, clean Visual Studio 2015 Community Edition installation with all options selected and all updates.
New project: Blank Xaml App (Xamarin.Forms.Portable) with nowt but generated code.
The project will not build as InitializeComponent in App.xaml.cs does not exist in the current context.
Opinion: this Xamarin add-on is a free add-on on top of a free product, but even so this kind of thing doesn't really inspire you to use it...

replacing application icon after build

I need to brand a specific white labeled app and it needs to get the appropriate app icon, so that when I browse to the exe in file explorer it shows with the branded icon. I dont mean changing the icon at runtime because that is not a problem.
I have tried accessing the assemblies with mono.cecil and replacing the resource called "app.ico" but it doesnt seem to work. I also tried to use pack URIs in xaml but that doesnt work because at compile time I dont know where the branding resources are located.
I know that this can possibly be done during a pre-build event but I prefer replacing the icon after the exe is built.
Any ideas?
In the 'Solution Explorer' in Visual Studio, select the startup project. Either right click on it and select 'Properties', or just press Alt+Enter on the keyboard to open the project properties. On the 'Application' tab, you should see a 'Resources' section. Click on the 'Icon and manifest' and select an icon for your application. Is that what you were talking about?

Application Title is missing when pinned to start menu

I have a problem with pinning my c# application to the start menu in Windows 2008 R2. The application pins with the correct icon but the application name is missing. In effect I just get the icon displayed.
My csproj has an msbuild import that points to a custom target file to automatically generate the AssemblyInfo class. I have checked the generated AssemblyInfo file and verified that the attributes for AssemblyTitle, AssemblyProduct, and AssemblyCompany are set correctly.
Everything looks ok when I right click the .exe and look at the properties\details. All the information is displayed as expected, just not when the application is pinned.
Does anyone have any ideas as to why this might be?
Cheers,
Ben
Ok, so I have solved my problem.
I am a little hazy on the finer details but it seem that when an item is added to the startmenu a registry key is created containing metadata about the item.
Under:
HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\Shell\MuiCache
This regkey has a set of key/value pairs, one of which was the path to my .exe. The value was the display name of the executable. Modifying this value modifies the application name text displayed on the start menu.
Deleted this key and it was re-added correctly. It looks like when this key is initially set it takes whatever is set in the AssemblyInfo.AssemblyTitle attribute.
Problem solved.

Categories