I am using Xamarin cross-platform for the development of an application. At this moment, my goal is to develop it for Android OS. But future goal also consists of using the same code(with some modifications) for Windows phone application.
I have to create a database and make it available to other applications. I am planning on using Content Provider(android specific) in my app. My question here is where do I write the code for Content Provider - android space or common code space ?
Should I use Shared Library or Portable Class Library for this type of development ?
Related
Currently, we are developing a .NET Standard class library that will be used by different Xamarin.* platforms.
I was wondering if there is a way to use the shared code in a native Android project (maybe produce an AAR/JAR file).
The reason I need this functionality is because our company provides an AAR to one of our customers (that is used by a native Android project), and we would like to keep a single source base instead of two.
Thanks in advance!
Update:
The name changed to ".NET Embedding" and it is at v0.4 at the time of this update.
https://developer.xamarin.com/releases/dotnetembedding/dotnetembedding_0/dotnetembedding_0.4/
New instructions:
Installing .NET Embedding
Original post:
You can use Mono's Embeddinator-4000
It supports various language consumers, so it surfaces .NET code as idiomatic code in the target language. This is the list of supported languages at present:
Objective-C: mapping .NET to idiomatic Objective-C APIs.
Java: mapping .NET to idiomatic Java APIs.
C: mapping .NET to an object-oriented like C APIs.
Embeddinator-4000 is a tool that allows your existing .NET Code (C#, F# and others) to be consumed from other programming languages and in various different environments.
Java is currently in a preview state for macOS, Windows, and Android.
The platform is selected by passing the --platform= command-line argument to the embeddinator. Currently macOS, Windows, and Android are supported.
re: https://mono.github.io/Embeddinator-4000/
As a part of the requires For Android you will need Xamarin.Android 7.4.99+ and Android Studio 3+ (Java 1.8) but if you are building Android apps with Xamarin and Java you would have those already.
Note: This tool is in Preview, so review the open issues and post new if needed.
re: https://github.com/mono/Embeddinator-4000/issues
Note: This is not trans-compiling, but embedding Mono's runtime in a native package that allow CIL code, AOT'd (i.e. iOS) or not to run within a different language/runtime.
We are developing a cross platform mobile application using Xamarin. I have noticed there are different ways of structuring your code using Shared code or PCL/.net standard.
I attempted to use .net standard and what i have found is that it doesn't include all the libraries such as using ado stuff , datatable/datasets using system.data. Or using system.net for example. Other functions have less overloads and seems that its a stripped version of .net to work across platforms. Is there any way to add this functionality or use a broader range of .net?
You are correct - .Net Standard and .Net Core are stripped down versions of the full .Net framework. They contain only features that can be used on all platforms (Mac, Android, iOS, Linux, Windows, etc.)
The full .Net framework only needs to work on Windows, so there are additional things that you can do based on the fact that there is less complexity in implementing and that the code base is more mature (cross platform is still pretty new by C# standards). To the best of my memory, System.Net should work if you have your references correct, but System.Data will not (or at least direct database access is not possible)
You can regain some functionality through NuGet packages, but it won't be the same as using WinForms or something like that...
My best advice would be to program against an API. You can use a web server that runs on the normal (full) .Net framework, and does all the heavy lifting using all the .Net features that you are accustomed to. Your Xamarin app would send and receive data from the API and basically provide a mobile front end for whatever you are doing. This approach makes sense for most apps anyway, and is generally what you would be doing anyway if you used Swift and Java to create separate iOS and Android apps.
So, I have been developing an android app for some time, and I was requested to try porting this app to windows phone too. In order to reduce the hassle in trying to maintain two separate versions of the same app, I decided to try to port this app into xamarin, because I have heard that its performance is better than hybrid apps. These are my questions with regard to xamarin:-
I want to maintain the same look and feel which I had in my original app into my cross platform app, and at the same time, make it distinct in the windows version. What are the things I can do to achieve this effect?
Is it rather better for me to port this app to windows phone native, because of added problems in trying to create a common app?
Are there any restrictions with regard to Windows store when publishing xamarin apps?
Xamarin doesn't really cover Windows UWP apps, only in the notion that they have the UI Framework Xamarin.Forms running on that platform. Meaning, that what you are making is a native Windows UWP app.
What Xamarin is great at is when you start targeting more than one platform and you have structured your code in a way that it can be reused on the supported platforms. This could for instance be done by putting most of your logic and behavior into a Portable Class Library/NETStandard library and consume it in your apps.
A Typical pattern for making platform agnostic logic and behavior for your apps, is the pattern known as Model-View-ViewModel, where the View is platform specific, while the Model and ViewModel usually are platform agnostic. The ViewModel is where the behavior resides and it is what ties the Model together with the View.
Usually the ViewModel wouldn't directly know the View, but there would be a layer in between (glue), such as XAML or a binding engine from MvvmCross, MvvmLight or ReactiveUI to name some MVVM libraries.
What Xamarin provides is the ability to write C# code for Android and iOS, which greatly enables you to share code between those two platforms, but also all the Windows platforms. Hence, UI, is very much dependent on each of the platforms on their own.
You can, of course, use Xamarin.Forms as a UI abstraction layer, which produces a native UI using the native UI controls to get a similar app on all the targeted platforms.
First of all you need to know there are different styles of Xamarin development, who will share more or less content.
If you use Xamarin Forms you have a Main project non-related to any platform (where you create the views and clases), and specific platform projects who adapt the controls to each native style.
If you develop using Xamarin Classic, you have a Shared project where you only develop data-related classes, and specific platform project with their own views and classes with native-friendly controls and native similar functions, but I think, there is no direct Xamarin Clasic Windows Project.
So if you only want to have two apps who look native both, but with same structure and functionalities Xamarin Forms will be the best option for you, cause you only develop "one single app" who becomes native-style like this:
If what you want is to have different apps, with different functionalities and diferent content, then you need to go for Xamarin Classic. What I recomend you to do then is develop the windows phone in native, but put all of the code you can in a shared library. Then you can create a Xamarin classic Android app and use the shared library. You will still need to mantain two different apps, but you will only need to change the "core" code only one time.
If you use Xamarin Forms to do a UWP windows app I don't think you have any problem to publish it, think Xamarin is from Microsoft.
To my knowledge, Xamarin is cross platform framework, so I can build one app and share it to any platform (Android, iOS, and Windows phone). I can't find any documentation that demonstrate how to port an existing Android project (completed project) to other platform, What are portable parts in the project, and what parts that can't be ported? Could you please explain these points in simple words. Thanks in advance.
When using Xamarin.Forms, projects are constructed in two parts:
A PCL project which contains the shared code; this includes business logic and classes which define user interfaces for the application (these can be written using C# or XAML with a C# code-behind). These user interfaces are platform-agnostic as Forms defines elements which are common to all platforms (buttons, labels, entries, etc.), and those translate into the native controls on each respective platform.
One or more platform-specific projects which contain boilerplate code to get the application up and running (such as the AppDelegate on iOS or MainActivity on Android), as well as any platform-specific behavior via the DependencyService, custom renderers, or the recently added effects. These three aforementioned features are not necessarily mandatory, but for times when you need to access platform-specific features, you may need to use one depending on your requirements.
See here for a quickstart guide on how to get a Forms-based application up and running.
i just downloaded Appcelerator Titanium and experimenting with it, I selected Desktop application and to support python,PHP and Ruby but I can't find Java. how to really work with java. I just need a hint about how to get my java code working there, where to put my java files and where should I include them.
Appcelerator Titanium does not support java .. well not directly
But take a look at these URLs for some possible options in writing java code
that indirectly uses titanium ..
As usual, the mileage obtained from adding a new layer of code would depend on how
well one understands the core architecture of how all the bits plug together .. :
https://github.com/emitrom/titanium4j
http://www.learningtitanium.com/software/gwt4titanium/javas-write-once-run-anywhere-for-titanium.html
As Emitron writes:
Titanium4j(Ti4j) is a Java application framework designed for creating rich
and interactive native applications for mobile and desktop.
The mobile package inside Ti4j leverages Appcelerator Titanium Mobile
to create native mobile applications.
The desktop package inside Ti4j leverages The TideSDK to create native desktop
applications.
Titanium4j takes the underlying frameworks to another level by making you avoid
JavaScript and puting all Java libraries and tools are at your disposal
You will have to decide whether the above justifies learning this extra functionality .. I reckon it does justify it