Hi everyones i got a anoying problem:
The application could not be started. Ensure that the application has been installed to the target device and has a launchable activity (MainLauncher = true).
Things i do:
adb uninstall ; nothing happens
try to uninstal app from device: the app dont apeard, even like a fake app whith 0kb
Uninstall Mono Shared Runtine and Api from app
Factory reset
Check in another device
Nothing solve my problem and i dont know who i must do.
Add:
My MainActivity;
[Activity(Label = "AppTecnicos", Icon = "#drawable/icon", Theme = "#style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
I found the error (Finally): my app package name started with uppercase.
AppTecnicos.Droid
I changed it to:
appTecnicos.Droid
The application could not be started. Ensure...has a launchable activity (MainLauncher = true).
One Activity in your application needs to be assigned as the MainLauncher otherwise the Android OS does not know the main entry point to app and what to display.
In Xamarin.Android typically this is done via the ActivityAttribute by assigning MainLauncher = true.
Example:
[Activity(Label = "StackOverflow", MainLauncher = true, Icon = "#mipmap/icon")]
public class MainActivity : AppCompatActivity
{
~~~
}
Ref: ActivityAttribute Class
If you are using visual studio and your aplication is a Xamarin.Forms aplication, this could be happening due to a solution configuration problem.
In that case, try to open the solution properties and within the configuration properties section check that your proyect its checked for deploy.
Related
In a Xamarin project, I can set the Android Label and Icon directly via the Build Options UI - which I believe updates the AndroidManifest.xml file
And I can also set it in code like so above the MainActivity class:
[Activity(Label = "MyXamApp", Icon = "#mipmap/ic_launcher", Theme = "#style/MyXamApp.Splash",
MainLauncher = true,
Does one take precedence over the other, do I need both, which is the correct way?
When you set the icon in Option, it will then be used to automatically generate the manifest for you. This is the default value for the Android project.
When you set the Icon, Label in Activity, it would reset the Icon, Label at runtime.
Normally, we would set our own Icon, Label in Activity. If you do not set it again, it would use the Icon, Label value in AndroidManifest file.
I am using Visual Studio for Mac 7.6.6 to create a Xamarin.Forms app targeting macOS (to be shared with something running on Windows). I create a new Project and select
Multiplatform App | Blank Forms App. Click Next
Configure your Blank Forms App. There are target platforms: Android and iOS.
(There is nothing for macOS). Since I have not installed the build toolkits for either iOS and android, both of these checkboxes are disabled. Therefore the Next button on this wizard page is disabled.
How do I proceed? I assume there is no way to use the New Project wizard for this.
I came across an old post for starting with a Xamarin Cocoa app and using NuGet to put the Xamarin Forms functionality but don't understand the code
LoadApplication(new App()); // <-- don't know what App is
I suspect the VS Mac and Xamarin.Forms are out of sync being on the bleeding edge. Has anyone gotten this to work?
I would suggest following SushiHangover's suggestion since that is simpler which is what you have done already:
Add a new CocoaApp project to your solution.
Install Xamarin.Forms NuGet package into your CocoaApp.
Reference the shared project or .NET Standard project from your CocoaApp project.
Edit info.plist and remove the source entry (NSMainStoryboardFile).
Change the AppDelegate to derive from Xamarin.Forms.Platform.MacOS.FormsApplicationDelegate.
Update Main.cs to initialize the AppDelegate
In the AppDelegate's DidFinishLaunching add the code to initialize Xamarin.Forms.
Create a new NSWindow which should be returned from the MainWindow property in the AppDelegate.
Main.cs:
static class MainClass
{
static void Main(string[] args)
{
NSApplication.Init();
NSApplication.SharedApplication.Delegate = new AppDelegate();
NSApplication.Main(args);
}
}
AppDelegate.cs:
[Register("AppDelegate")]
public class AppDelegate : Xamarin.Forms.Platform.MacOS.FormsApplicationDelegate
{
NSWindow window;
public AppDelegate()
{
var style = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled;
var rect = new CoreGraphics.CGRect(200, 1000, 1024, 768);
window = new NSWindow(rect, style, NSBackingStore.Buffered, false);
window.Title = "Xamarin.Forms on Mac!";
window.TitleVisibility = NSWindowTitleVisibility.Hidden;
}
public override NSWindow MainWindow
{
get { return window; }
}
public override void DidFinishLaunching(NSNotification notification)
{
Xamarin.Forms.Forms.Init();
LoadApplication(new App());
base.DidFinishLaunching(notification);
}
public override void WillTerminate(NSNotification notification)
{
// Insert code here to tear down your application
}
}
However Visual Studio for Mac does include a Mac project with the Xamarin.Forms project templates. However it does not expose this in the New Project dialog currently. You can create a Mac Forms project from this template but it is a bit more work than what SushiHangover suggested and you have used.
Install the Xamarin.Forms project template into the .NET Core project templates
dotnet new --install "/Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/AddIns/Xamarin.Forms.Addin/Templates/Xamarin.Templates.Multiplatform.0.0.1.nupkg"
Create a new Forms project including the Mac project (you may want to review and set other template parameters - the following creates a blank Forms app with Android, iOS, Mac, UWP and a Shared project).
dotnet new forms-app --CreateMacProject -k blank
Create a new blank solution (Other - Miscellaneous - Blank Solution) in the parent directory of the projects you just created.
Add all those projects created to the solution.
Then you can build and run the Mac project which includes Xamarin.Forms.
Note you may want to remove the Xamarin.Forms project template from the .NET Core project templates which you can do by running the following:
dotnet new --debug:reinit
In addition to the approved answer, which is incomplete with recent updates, now you have to do one more step.
Link the delagate in the Mac project main class
main.cs:
static class MainClass
{
static void Main(string[] args)
{
NSApplication.Init();
NSApplication.SharedApplication.Delegate = new AppDelegate();
NSApplication.Main(args);
}
}
nota. My edit was refused and I'm not allowed to add comments. So I added a complementary answer to help those looking for help now.
I have a default theme for my app. I customize this theme using Style file in Android. But I'm creating a login page that I want use other theme just for it. How can I do that?
I am not sure you can do that, because Android theme can be applied to an activity in Android, but Xamarin.Forms run "within" a single activity, so you would have to do the styling either in Xamarin.Forms. Check out this post on Xamarin Forums where the developer was able to change the theme at runtime, which however restarted the activity and in turn also his Xamarin.Forms app.
If your Xamarin Forms app is only using one activity, then this is quite straightforward. This solution is for Lollipop and versions after. You can do this using platform specific Android code:
public class StatusBarStyleManager : IStatusBarStyleManager
{
public void SetStatusBarColor(Android.Graphics.Color color)
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
{
Device.BeginInvokeOnMainThread(() =>
{
var currentWindow = GetCurrentWindow();
currentWindow.DecorView.SystemUiVisibility = (StatusBarVisibility)SystemUiFlags.LightStatusBar;
currentWindow.SetStatusBarColor(color);
});
}
}
Window GetCurrentWindow()
{
//Note this is a nuget package for retrieving the activity.
var window = CrossCurrentActivity.Current.Activity.Window;
// clear FLAG_TRANSLUCENT_STATUS flag:
window.ClearFlags(WindowManagerFlags.TranslucentStatus);
// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
return window;
}
}
Then just use this implementation in your pages to set their specific status bar colors when they appear.
Inspired by this article when I needed this in my own projects:
https://evgenyzborovsky.com/2018/08/20/dynamically-changing-the-status-bar-appearance-in-xamarin-forms/
I have a Xamarin.Forms project. Here is my MainActivity.cs from the Android part of the project:
[Activity(Label = "MyApp.Droid", Icon = "#drawable/icon", Theme = "#style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity {
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
Every time I try to test on my device I get an Android.Util.AndroidRuntimeException with the following message: requestFeature() must be called before adding content even though I'm not calling requestFeature() at all. Here's the stack trace:
--- End of managed Android.Util.AndroidRuntimeException stack trace ---
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.PhoneWindow.requestFeature(PhoneWindow.java:338)
at md5f4656b392f6d15b90a32ccb2cb36af91.MainActivity.n_onCreate(Native Method)
at md5f4656b392f6d15b90a32ccb2cb36af91.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:6672)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107)
I've already tried restarting Xamarin Studio and cleaning/rebuilding my solution. What am I missing?
Edit: Just created a new blank Xamarin.Forms project. It ran perfectly on my device. Still can't get the old project to run though.
Solution:
Close project
Close Xamarin Studio/Visual Studio
Delete app (along with app data) from phone/emulator
Go to project directory, delete bin and obj folders
Open Xamarin Studio/Visual Studio
Re-deploy
Issue should be resolved now
Xamarin.Forms does generate a greyish Android application. I'd like to have a light / white theme in Android (like in the iOS target).
Does a simple way to switch exist?
You can put Theme parameter to ApplicationAttribute of your main activity
like this
[assembly: Application(Icon = "#drawable/Icon", Theme = "#android:style/Theme.Holo.Light")]
Or you can put this string to AndroidManifest.xml
<application android:theme="#android:style/Theme.Holo.Light" />
The answer from ad1Dima got me most of the way there, but I found that in my environment I needed something slightly different. This is what I put in my 'MainActivity.cs' file to change the theme.
[Activity( Theme="#android:style/Theme.Holo.Light",Label = "HealthTechnologies", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : AndroidActivity
Note that the only thing that was new here was the addition of the 'Theme=...'. Everything else was already in the MainActivity.cs file.
open android manifest file
app_name->Properties->AndroidManifest.xml
now add this line inside <manifest>:
<manifest>
...
<application android:theme="#android:style/Theme.DeviceDefault.Light"></application>
...
</manifest>