Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
As a complete beginner to Xamarin and new entrant to mobile app development, I have some questions about Xamarin and about the way it works which I was not able to find on the internet
How does Xamarin Cross-platform actually work? Is it any use? I was told Xamarin told Xamarin is a cross-platform mobile development solution, but when I Start off, I see it actually encourages you to create separate projects for iOS and Android. I understand that is to give us more power and there is always Xamarin Forms if we want cross-platform UI. In that case, however, I would expect the Portable Class libraries to handle all the backend logic while the native projects are used only for the UI. But when I started out, the most basic library for accessing mobile functionality (Xamarin.Mobile), is not compatible with PCL. What is the use of PCL even in that case?
How are cross-platform apps generally made in Xamarin? What is the role of the PCL and how do we get it to do cross-platform stuff?
Is there no pre-built Xamarin API which allows to do most mobile-related stuff platform independently? Seems we have to download new libraries from nuGet for every little thing we want to do which is quite painful
I hate to ask this. But is the only real advantage of Xamarin the fact that we can code in C# instead of native languages? What I was expecting is actual cross-platform shared code-base. If unity can do it, why can Xamarin not do it?
As someone who's worked with Xamarin (certified) for more than 2 years I will try to answer your questions:
1) Xamarin is a .NET framework that compiles to native code for both platforms. 2 years ago you'd create projects for every 'type' of app you built (Android, iOS, etcetera). In practise this meant you writing Activities for android (in the .NET way of doing things, but with the exact same native android types) and UIViewControllers for iOS. Xamarin.Forms has been out for a while and is a solution that will allow you to share UI Code as well as Business logic.
2) Depending on the app, one chooses either Xamarin.Forms or the native route. In case of the native route you'd create views for every platform (Android AXML and iOS Storyboarding). Additionally a PCL would be added containing all the business logic. This way you can call
var authResult = AuthService.Login(username,password);
var settings = SettingsService.GetUserLocalDbSettings();
from both iOS and Android, and the business logic for logging someone in - only has to be written once. Xamarin.Forms allows you to also share UI, by building XAML-layouts in the Xamarin.Forms project. These get transformed to the right screen type in either OS. Note: This only works properly with simple layouts (think lists, tabs etcetera). Complex layouts take way more time in forms to the point you switch to native.
3) Xamarin is only the framework allowing you to write .NET for these platforms. There's a lot of plugins available (e.g. Connectivity check) that are available. Install them in your native projects AND the PCL, and you'll be able to check whether the app has connectivity from within the PCL, or not). Xamarin is the hammer, Nuget offers the nails.
4) You can share a lot of code (PCL). My honest experience though is that most of the time you'll be building layouts (views) for both platforms. The business logic (signing in, saving items to a SQLite database) costs the least time to build. UI / design however,....requires a lot more patience. So YES you can share all business logic (as far as the used libraries respect the PCL profile).
5) Protip: Xamarin offers some free university training since they have been part of Microsoft.
I agree with the comment made by Lex Li above that you seems to be quite new not only in Xamarin space but also in C# development space, but will still try to add to the points mentioned by Eric J which I think he has missed in his answers.
Answer to Question 1:
How does Xamarin Cross-platform actually work? Is it any use?
Already answered by people before me.
What is the use of PCL even in that case?
You didn't found the use of PCL because you didn't tried to use it correct way. It's not for accessing mobile feature from common code, It's used for writing code which is common for all the platforms example for such type of code can be 'Web Service call', 'Business Logic' etc.
Answer to Question 2:
This is a very generic question whose answer is given many times, by many people. The best place to know more about Xamarin is by following the Xamarin Developer Guide
Answers to Question 3:
As mentioned by Lex Li Nuget is core of .Net package distribution and you should use it not only because of this reason but also because it makes development and deployment more easy.
Like :
1) You need not to worry about where to store DLLs (GAC/Local)
2) No need to store a particular version of DLL in fear of loosing it, all the versions are stored on Nuget Servers and Visual Studio automatically downloads the one which is mentioned in you Package config.
3) You can choose to use pre-release version of any DLL in one project and Stable version in other with out worrying about any clash.
Answers to Question 4:
I think all the advantages are already mentioned in above answers, I would request you to first try working with Xamarin sincerely and then start ranting about it.
Unless you learn Xamarin as part of the larger C# ecosystem, the questions and answers will be hard for you to digest.
1 and 2: Kind of the worst questions. So many use Xamarin. PCL is dying if you really know how C# and .NET ecosystem go. .NET Standard and Standard Library will be the future, and have already been supported by the latest beta builds from Xamarin.
3: NuGet is the core of .NET package distribution (like npm for JavaScript) and every C# programmers should use it. If you cannot get used to that, well, nobody forces you to start your own tool chain.
4: Then why not use Unity? What are you waiting for then? Xamarin has its own target user groups, and those guys do appreciate that only the meaningful code should be shared. People do love platform dependent UI, as that can blend perfectly into native platforms.
Related
I'm on the cusp of beginning a Xamarin project. I have been doing loads of research on what the best starting point would be and i have come to the conclusion that i need to learn the Android framework and begin by building a native Android app in Xamarin instead of Xamarin.Forms.
However, looking to the future i would want to be cross platform for this app. I have searched high and low on any information about what it would take to take a Xamarin.Android app and migrate it into a Xamarin.Forms app so that i can then build out the iOS app for my project.
Does anyone have any information on if this process is easy or hard to do? Can you take a Xamarin.Android app and someone migrate it to a Xamarin.Forms project? And if not would the approach be to rebuild the apps under a Xamarin.Forms project? Is there a easy approach to this?
Any info on this would be greatly appreciated.
With more than two years of experience with Xamarin (Native and Forms), I have never seen a tool or anything of any sort that will help you with migration but I can give you my personal opinion on this and maybe help you a little. Let's begin.
I have been doing loads of research on what the best starting point would be and I have come to the conclusion that I need to learn the Android framework and begin by building a native Android app in Xamarin instead of Xamarin.Forms
I would say this was a good decision Since my personal experience tells me that it is crucial for you to know either Android or iOS before you start working with Xamarin Forms otherwise there will be points in time where you will be lost af seeing the code, thinking how did you get yourself into this mess ;)
I have searched high and low on any information about what it would take to take a Xamarin.Android app and migrate it into a Xamarin.Forms app so that I can then build out the iOS app for my project.
There is no direct way of doing this you will have to do it the old fashioned way...
Converting(Manually) Android XML to XAML is quite easy so the design won't be an issue.
The C# part might be a problem as a native Android code is quite different to forms, But you can do it with ease with time.
Note: That there will be a lot of stuff that you would want to keep in mind for eg how Xamarin.Forms works. Because when you start doing the changes you will face a lot of issues finding equivalents and stuff but it will get easier
Does anyone have any information on if this process is easy or hard to do?
It's not about hard or easy it's about time taking or not and trust me it takes time.
Can you take a Xamarin.Android app and someone migrates it to a Xamarin.Forms project?
I am a little bit confused by this part of the question but if you mean is it possible yes it is.
My comments:
You will need good knowledge of how Xamarin.Forms work and by that I mean you should at least go through all the Xamarin.Forms guides in Xamarin University which can be completed in a week or so with proper understanding.
Going forward I would say use an MVVM framework for your Forms app, it will help you have a well-structured code and will keep you up to date with the industry standard.
Also, note that MVVMCross for a beginner in MVVM is too complex, so avoid it if you have no idea what MVVM is, going with Prism or FreshMVVM would be comparatively easier.
Don't depend too much on Xamarin.Forms NuGet's for doing certain functionalities.
Rather write your own code using Plugins for everything is too much dependency and becomes a problem at crucial times.
I want to print the current UI of a Xamarin.Forms cross-platform application. Are there any plugins or libraries available which support both android ios and uwp projects to do this? I'd really appreciate being pointed in the right direction to get started on implementing this kind of feature in my application.
I would approach this in two steps. Firstly you need to convert the current visuals into a printable file type. So assuming we are working with primarily mobile devices then we should make use of the 'screenshot' mechanisms.
There is a very good answer to another stack overflow account HERE that guides you through setting up screenshots in xamarin forms using dependancy injection. The chaps answer is straight forward and easy to follow.
Once you have that screenshot as a png or jpeg etc. It's time to print it. There are a lot of threads on xamarins developer forums dedicated to the issues around printing from xamarin, a collection of these can be found HERE.
So to start with it's worth mentioning that every platform xamarin forms (XF)supports has it's own mechanism for printing. XF does not provide any abstractions for printing in a cross-platform manner. You will need to write printing logic for each layer and expose it to XF using DependencyServices.
Android Printing - this is a link to printing in android.
iOS Printing - this is a link to printing in iOS (Heres a sample app to help you as well.)
As I previously mentioned, because xamarin hasn't created a simple cross-platform mechanism for this in Forms, it's not quite as simple as you'd think and does require some work to implement. But none of the work is overly complicated, it uses standard dependancy patterns, it's really just the bulk of code required that can seem a bit daunting.
I'm fairly new to Xamarin development, but I've started doing some experiments with Xamarin.Forms and I'm really liking it.
Now, I've discovered MVVMCross, and it sounds interesting for developing apps that have separated UIs for each platform, but I'm trying to find updated information regarding how (and if / why) it may tie in with Xamarin.Forms (mvvm's docs has a page for this, but it's empty ATM).
Is there any currently-relevant information I'm not being able to find? (all results I'm finding seem to be too old and not really helpful, please correct me if my google-fu is just not strong enough)
Well, for lack of better replies. From this blog post:
(...) it is crucial to understand that neither MvvmCross nor Xamarin.Forms is a replacement for one another. While both of them provide infrastructure modules that help developers in their mobile application projects, Xamarin.Forms is a UI technology stack that enables common XAML declarative UI implementation for target platforms; MvvmCross is a framework that enforces clear distinction between the UI elements and core logic implementation. Either of them alone or together can increase the shared amount of code in cross platform projects.
I have found a lot of articles (and forms) about Ionic vs Xamarin but they always talk about Ionic 1 or Xamarin when it was still paid for (so before march 2016 when it was acquired by Microsoft).
I have to research Ionic 2 vs (current) Xamarin and I know that both technologies have made huge advancements. Can anyone help me on my way with some sources or is it still too early to ask this question?
Xamarin: With one year of experience, I have realise it is really flexible IDE to use. The amazing part about Xamarin is you have 2 option, i) go native ii) go cross platform, this make it open on what kind usage you prefer and how you want to go about.
OS Support/Deployment to: Windows, iOS, Android, Mac
Languages Used: XML, C#
Ionic: especially Ionic-2, It amazing for all HTML, CSS, and JS users to build application for web, mobile applications. I haven't seen its deployment for windows phone(if it is, then i am not sure) With Ionic, forget all your MVVM structured coding. But the new implementation of version-2 parallel with angular-2(typescript) it might make it possible to implement.
OS Support/Deployment to: iOS, Android, Web(HTML/CSS)
languages Used: HTML, CSS, Angular-2
Star Rating
Xamarin - Mobile and PC Dev - 4/5 stars on usage of IDE and deployment. There are immediate help available upon stuck through Xamarin Forums. Documentation is little vague.
Ionic-2 - Mobile and Web Dev - 3/5 stars on usable and compatibility. Its hard to find some answers to specific question, rest ionic docs are great at documentation and implementation.
Hope this helps. PS: This is completely my own view as i have used both of this tools personally. Comments are welcomed.
I started Xamarin and I'm beginner. Since there is no documentation about Xamarin, when I have crash I can't find solution.
Anyway, I want to ask some question to you.
There are 2 choices: you can either use only Xamarin code with C# and this code yields to work with Android, IOS and Win Phone, or you can use separate code for Android, IOS and Win Phones. Is this information true or false? (I don't know I am exactly true.)
When I create a .xaml file with C# to yield Android, IOS and Win Phones, how can I use native pages, libraries (ex: SharedPreference). For example, I have a .xaml page and I want to navigate to an Android.Activity page - is this possible?
Thank you for your responses.
Your best friend for bugs and errors is google and stackoverflow. You can find almost everything as xamarin started to grow a lot after microsoft's acquisition.
You can either choose a unified solution like a PCL (Shared or Portable) or seperate projects.All of them are written in C# because that is what Xamarin is doing.
I don't think you have the ability to do that, but i am not sure.
You must do your research in order to find which way of coding is appropriate for your application. If you want to build something very unique with complex ui in each platform, you would probably choose separate projects. Else you can use xamarin forms to have a unique UI across all of your projects.