Related
I have a C++ game engine that currently supports Windows, Linux and Android (NDK). It's built on top of SDL and uses OpenGL for rendering.
One of the design constraints of this game engine is that the cost of development must be $0.00 -- building the engine should come at no cost to me (other than man hours), I must be allowed to freely redistribute the engine's code and binaries, and users should be able to sell games created using the engine with no restrictions.
Right now, I'm using a very slow interpreted scripting language for game logic -- it actually works well for writing glue code and simple responses to UI events, but not much else.
I'd like to replace this system with a C# solution -- have the user compile a C# class library (DLL) containing their game logic, and have the C++ side 'consume' this DLL and call the appropriate hooks.
It's been rather difficult to find information on how to achieve this in a cross-platform way. Each platform has a different way of hosting the needed runtimes. Also, most articles I've found suggest the use of full-fledged frameworks that provide platform abstractions that are already implemented in my engine.
Is there currently a way to run code from a C# DLL from an Android NDK-based C++ application without using an entirely different SDK, and without having to shell out hundreds of dollars for a license?
In particular, I'm eyeing some of Microsoft's recent open source .net initiatives -- anything there I could use?
EDIT: To clarify, Windows and Linux have well-documented ways of running .net code 'for free' -- this question pertains specifically to calling managed code from an Android NDK application WITHOUT paying licensing fees to Xamarin or another vendor.
It's been rather difficult to find information on how to achieve this in a cross-platform way...
I'm only going to address the issue of "write once, run everywhere."
I build and maintain a library, composed of a single set of sources, that runs on Windows, Linux, OS X, Windows Phone, Android and iOS. To do that, I had to write everything in portable C/C++, and then build DLLs or shared objects.
The project uses .Net interop to call into the DLL, and Android uses JNI to call into the shared object. On iOS a static library is created rather than a shared object.
The DLL or shared object does have some platform specific defines. For example, it must know how to get random numbers from the underlying OS. So it will have a function like:
bool GetRandomNumbers(unsigned char* ptr, size_t size)
{
#if defined(WIN32) || defined(WIN64)
...
#elif defined(__linux___) || defined(linux)
...
#elif defined(__ANDROID___)
...
#endif
}
So keep your core business logic portable and in a DLL or shared object, #define where you must to abstract platform differences, and you will be OK.
On top of the portable library, you layer the platform specific GUI stuff.
If you try to write this in C# and then use that on other platforms, you're just going to be causing yourself problems. The only way to do portability with a single set of sources is to use portable C/C++.
I've also seen folks re-implement in every language: C and Win32 for Windows, .Net for Windows, C for Linux, Cocoa for OS X, .Net for Windows Phone, Java for Android and CocoaTouch for iOS. That creates about 6x the work, and the behaviors are never quite the same across platforms.
A popular script engine for games is Lua; you might consider using that, since it's trivially easy to link with C/C++. If you use LuaJIT, it's also blazing fast on Android (and not shabby on iOS).
One alternative to consider is that if you build your custom engine on top of Cocos2d-X, you'd not only get Lua (or JavaScript) for free as a connected scripting engine, you'd also get portability to Windows (Win32 and Windows 8.1 Universal), iOS, Mac, and Linux, an IDE (!!), and a huge supportive community.
Or you can spend a lot of time figuring out how to integrate C# into your engine.
The simple answer is no, what you're looking for does not currently exist. You will need to drop/change requirements to find a solution.
The closest I know of is dot42 - which seems to support some of .net on android has recently been put on github and the main site shut-down - but there's no mention of license in the main compiler repository (I've added a bug to get that updated..)
It's not clear that it supports dynamic loading of C# .dll's though as it claims to compile to DEX. (But it may be free, depending on what the developers release as the license...)
Xamarin is the only other feasible alternative that I know of, but as you're aware only the starter edition is free.
If what you're after is purely better scripting support, I'd drop the compiled and C# requirements and find something that works well on android already. Lua is my go to solution for this kind of thing, but I've not used it on android before... and many other options exist.
So, one of the main features of coding using the native SDK provided by Android and iOS is the fact that you get not only a better performance, but also the look and feel of each platform: for example, on iOS, a tab-navigation bar would be located at the bottom of the screen, while in Android it is located at the top (yeah I know it also can be top and bottom, but you get my point), or also the Navigation Drawer dock is an Android navigation style while (as far as I know) there is nothing similar in iOS native sdk. My point being, you can feel the difference of platforms by their design guidelines which is a good thing, since it makes your app looks professional.
So taking that into account, in terms of performance and maintaining the feeling of your app, using JS-based frameworks like Titanium or PhoneGap will not make a wise choice.
Then comes Xamarin. As I read in here: Xamarin how it is getting the Native Look and Feel? it seems it is a C# wrapper for native SDK, which as far as I understand, it should not affect performance. But where's the look and feel part. Since XML layouts are not entirely what gives Android or iOS apps their feel, but also the navigation (which comes from the controller classes) how does Xamarin deals with these? It is said in their website that you can share code between platform, but will that also means I have to share navigation system and similar?
Finally, for the sake of "not writing code for each platform" , is it worth NOT to use native SDK and go with Xamarin (I don't really have a problem writing code for both iOS and Android), or is this framework target for C# developers so they won't have to learn Objective-C or Android.
Any extra explanation would be awesome, and thanks in advance.
I built a large application within the last year (2013) with different components: mainly an API (ASP.NET Web API => C#), a Website (ASP.NET MVC => C# + AngularJS), and both an app for Android (Xamarin.Android => C#) and iOS (Xamarin.iOS => C#). The decision to use Xamarin had its advantages and its disadvantages, but all in all I am more than happy with it.
As you can see in my list above, almost everything was done with C# (okay, the Website is mainly written in JavaScript ;-)). It's a wonderful mature language with really nice features (as LINQ). In my scenario it becomes clear: I did not have to learn and to perfect four languages (Swift/Objective-C, Java, C#, JavaScript) but only two: C# and JavaScript.
That comes especially into play regarding the code sharing aspect: our client applications aren't really thin clients because of some offline functionality which requires a lot of synchronization logic, so the UI part of the two apps is only one side of the medal. As it turned out, I could really use 90% of that non-interface code on both iOS and Android. This is an incredibly huge benefit, as it's not only about some language originalities of Swift/Objective-C or Java, but also about the different frameworks you are using on iOS and Android. To use the .NET Framework/Mono as foundation of every Xamarin app enables you to abstract things like data access or network communication from the underlaying OS.
In terms of speed and UI you don't have any disadvantages, because you're using the native APIs 1:1. Whatever is available on iOS or Android is also available through Xamarin. And whenever Apple for example ships a new version of iOS, Xamarin will ship the update for that within a few days, so you don't have to wait to be able to use newly introduced features by Apple.
Xamarin uses a technique called Ahead of Time Compiling on iOS, so everything you write in C# is compiled into the native iOS stuff before it is deployed to your device. That means there is no difference in what is executed between a "native" Objectice-C application and a Xamarin application (except some small overhead which isn't noteworthy from my experiences).
On Android Just in Time compilation is used as just with any other "native" Android app, too.
That all means you have all the exact same APIs and possibilities you would otherwise have, if you would go with Objective-C or Java. You even use the same objects for building your UI with the exact same types and names (sometimes slightly optimized ;)). So if you want a tab bar navigation for your app - you use a UITabBarController for that. See iOS vs. Xamarin.
After multiple years on my way with Xamarin I only one disadvantage:
Possible memory leaks. Their whole samples out there are a bunch of crap regarding essential basics of preventing memory leaks. If you are working with "expensive resources" like media files within your application, you should take care from day one. I had to get rid of all that problems when an app of mine had already been growing to up to 35 different (complex) dialogs. That took me almost two months or in other words thousands of bucks. They provide some documentation about it, but the tooling is poor at this end. And errors are likely to appear and very hard to be found (example).
But all in all it was one of my best decisions to go with Xamarin.
I have been coding with Xamarin for a while now. Its been great so far. Any problems I've had I figured it out because c# is my native language. The Xamarin site has many examples and API references for many features on all platforms.
Performance - You get native performance from using Xamarin. No questions asked. I have been using it to create audio, video and photo recording features for a new app i'm working on. Xamarin processes the c# code into native byte code for all platforms. Thats how this is achieved.
Look - The look of your app will be native. You literally have to use the Android xml format to make your user interface and the same Goes for IOS. You will still style your elements the same way you did on each platform. All Xamarin does is link a view to an event for you.
Api - The beauty of Xamarin is in the API. They ported the whole Android and IOS namespace to c#. Take a look at their Documentation.
Expensive - My only problem with Xamarin is that it is expensive. If you check their pricing it is outrageous. But you get what you pay for. A premium product that is backed by support.
C# - Sharp is a great language that has loads of support. The new async/await gets ride of the whole thread management issue. Json processing is super easy on the platform. I have uploaded several classes on Github that can be used for many apps.
If you are from a java background, brushing up on your c# skills will be a breeze.
The rdio app was created with Xamarin. Download it on Android and IOS and test its performance and enjoy its native look.
Best of Luck
There is much much more internet content, help, and support for native. That alone helps me make my choice. If you are really good at Xamerin, maybe 70% of the code you write will be usable by both apps, you still have to custom tailor things for each app.
But again, the support for native is so vast, that if you run into a proble, so has someone else.
With xamerin, well, good luck.
When I say app I mean iOS/Android
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I'm building an application for multiple desktop platforms: Windows, Mac, and maybe later for Linux.
I was wondering which programming language and IDE combination would be the best for me:
Programming language need to be whether C# (preferred) or Java.
Core libraries must be shared between all platforms, means all platforms must link to a single core library (by library I mean a list of classes and functions).
Windows and Mac are in priority, Linux app is for future plannings.
Design of the app is completely custom, it doesn't follow any guidelines of each platforms.
I'm stuck between these three solutions:
Use Xamarin.Mac + Visual Studio for Windows and link the core classes between them.
Use GTK# for the whole project and compile multiple builds for each platforms.
Use Java for the whole project and compile multiple builds for each platforms.
For #2 and #3, I need an advice that which language is more suitable for me, considering the design of my application. I mean, which one has a better GUI building ability for my goal?
BTW GTK# uses different libraries for each platforms, so that should be an clutter for my core architecture, or not?!
Three years later and Javascript is now also a strong contender in this debate.
There are multiple options within the space.
https://electron.atom.io/
https://github.com/nwjs/nw.js/
And others
Even Microsoft has shipped Visual Studio Code, the cross platform version of their development environment, which is written in Javascript.
What is the Visual Studio Code editor built on
The benefits include utilizing the many available web libraries, and building/using your web development skills.
This sounds like a job for Xojo or something similar: http://www.xojo.com
Mac, Windows, Linux builds with easy GUI design and native apps. Custom UI easily done also, and you'd then have one code base for all three platforms. You can download and use the software for free to develop and test, only requires a license once you decide to build your app.
You can also conside Livecode
Livecode: http://livecode.com
For any platform except web, it is opensource and it includes mobile targets as well, if your code is flexible enough to not being C# or Java.
An option is to build the core logic in a compiled library using C# and GUI independence and then plug it to livecode, leaving the UI work for that tool.
"GTK# uses different libraries for each platforms", do you mean different rendering back ends (such as X11, Cairo)?
You only need to build your GTK# app once. However, you do have to bundle the GTK# runtime (which is different for Windows and Mac) with your app. Banshee is a good example you can follow.
Probably your best bet is to use Nevron Open Vision. It is a cross-platform, C# based User Interface Platform, that implements most of the controls you need to build enterprise-ready applications. It is the framework behind MyDraw (www.mydraw.com) - a professional drawing program similar to Visio. MyDraw is built completely with Nevron Open Vision and does not require any other third-party libraries. We mainly develop it under Windows and just compile it to Mac. Soon we are going to add support for Linux and WebAssembly hosts.
Microsoft just launched .NET MAUI, a cross-platform GUI framework that builds on Xamarian.forms.
As we consider what building device applications will look like in a unified .NET, we see many devices across multiple platforms used, from Android and iOS to Windows and macOS. To address this need we are excited to announce a new first-class UI framework for doing just that: .NET Multi-platform App UI, affectionately call .NET MAUI.
This seems to meet all of your requirements. They do not explicitly mention Linux in their article, but claim to support it in the description on the Github Repo.
It depends on the audience of the app: Consumer mass market or business/IT
If its mass market consumer facing
Electron or native UI, perhaps with shared non-UI code. Visual Studio Code was made with Electron, for example (last I checked). Google Flutter is a new entrant worth evaluating. Dropbox is Python (or used to be). It is a lot of work (a) getting Python packaged properly for smooth x-platform install, and (b) GUI work will take a long time. Sadly, for mass market consumer apps (not utilities for IT people but beautiful designs for the masses like Dropbox, Skype) you will be spending a ton of time getting the installation system to work and getting the app to look and feel appropriate. This is an extremely time consuming endeavour no matter what path you take.
Consumer: Java? I don't think Java is a great fit for consumer desktop although I could be wrong. There are some Java packaging systems that are leaner/all bundled in. I'd also say JVM software companies tend to go under (more on this later). FreeMind the free mind mapper, is a good example of what can be achieved in Java.
Consumer: .NET? Yes, for the Windows side. Then use something native for Mac and shared libraries for non-GUI code. There is ".NET Core" aka Mono but its not fully matured at this time for Mac. Mono has been around for over half a decade and I haven't seen it mature for a consumer app. Ask: How many .NET Core apps are in the Mac app store? I hope it gets better but as of this writing (2020) there's very few notable ones.
Business app or IT tool
If its a basic business app or utility where a basic UI is okay, I'd evaluate Xojo and/or LiveCode mainly for comparison sake. Xojo is fairly close to .NET. Google Flutter as well since it's up and coming. By the time you read this, Flutter may be the best choice.
B2B: Java? This is a pretty tried, tested and true solution for "heavy" enterprise apps. You might not have end-users love you given Java apps tend to eat up memory. But for enterprisey apps the main concern is that the very intense business logic will work. For IT tools, it depends. If it's a 3-screen utility program, avoid Java. If it's a complex ERP then Java is good. Remember to look around for different packaging tools to avoid consumer headaches with the JVM. Again, one Java desktop app I like is Freemind. It's a great example of making a reasonable desktop app in Java. I have used it in both Windows and Mac and it's great. You can also look at Kotlin or Groovy (for test cases) which compile to Java byte code.
B2B .NET? There is so much to unpack here. The key is, in my biased view, .NET Windows desktop development is about 2X-4X faster development time than Windows Java desktop development. From making the GUI, to better code completion, to faster compile times, to less packaging and install snags. That said, at the time of this writing the ".NET Core" or Mono are pretty thin for MacOS. I really, really hope this changes. But I've been waiting years for Mono or .NET Core to provide a full suite for MacOS without the limitations and it hasn't yet happened. If it's an enterprise app, you might be able to get away with using .NET Core for Mac. But please first build a basic .NET Core "hello world" app with all the control/libraries you want to use. Then try building an installer for it on MacOS, and find someone random with a Mac to see if it actually installs and runs. You may find you're struggling in this area today (although I hope it gets better, it hasn't for years).
Overall Notes on Cross Platform
If this is a smaller app which doesn't need a fantastic UX and super-deep OS integration, then I'd consider Xojo or LiveCode, perhaps for the UX elements. Like #merlucin said, you can write the core logic in something shared- perhaps C#, python, etc.
Here's why- Xojo and LiveCode have been around for 10 years now. They are more about keeping things consistent. Whereas I find .NET and QT changes all the time. You have a lot of costs of keeping up with the Joneses and maintaining installers. So for a small app or utility- an XML editor, IT helper tool, Xojo or perhaps LiveCode will help you get there sooner.
When you hit the build button on Xojo, for example, it literally makes 3 executable files for Windows, Mac and Linux. Compare that to the madness of packaging a cross platform Python app, or even packaging a .NET app for Windows, to be honest.
The tradeoff is these tools- Xojo and LiveCode often end to be missing a few critical things you need, requiring a bit of a hack. You can read around their forums. Xojo is a bit like .NET although LiveCode is a different programming paradigm entirely based on "stacks".
Keep in mind developer happiness too. Many developers wont want to code in Xojo or LiveCode because they are lesser known languages. So ensure you get buy-in. What happens if you get laid off and have 5 years of experience in Xojo? Hmm.
In your evaluation, no matter what you choose-- you must compile a basic GUI app in the platform you're evaluating and get 3 people to install it correctly on a Mac. You'll be shocked at the libraries and madness needed. Especially if you're a web developer, you'd see that just maintaining installers is a ton of work across 3 platforms. Never mind GUI consistency.
I want to make a project for the summer where I want to create an Android app. Now my question is for those who have used Xamarin before to create Android apps:
Is it better to create Android apps with Java than in C# with Xamarin?
Are there any restrictions with usin Xamarin for Android app development?
I.e. are there some things that I can do in Java but not in Xamarin?
And last, what do you think about Xamarin for a pretty new programmer?
You specifically asked to:
create an android app
If that is your only requirement, and you have no previous experience in C# development, you should stick to developing the application using JAVA and Android SDKs. After all, it is free of charge.
However,
Why do you want to limit yourself to Android platforms?
If there is a chance that you might want to expand to other platforms in the future, you should IMHO start preparing for it right now, and create a cross-platform application.
C# is a powerful language, Xamarin products are mature and of high quality and Xamarin community is big enough for wide support.
There are no restrictions that I know of, and everything that you can do with native Java you can also achieve with Xamarin.Android. Also, in case you will ever find any restriction, you can always include Native Java Code inside your application.
The only thing to mind is the price, which is probably high for a beginner developer.
An additional feature which is in C# but is omitted in Java is LINQ which gives significant assistance to data handing and sorting.
The main factor to consider is as Liel has already said your preference of programming Language, Java or C#, go with which you are more comfortable with. The only hesitation which I would mention when referring someone to Xamarin as opposed to Java is that their is significantly tutorials out their.
This in my view though should become less of an issue in time. The main source which I use when I am learning is AppDev and Pluralsight Training DVDs and have found them to be essential in learning.
It is possible to simply refer to Java sources the only manipulation sometimes needed is to capitalize the first character setContentView() => SetContentView() in C#, and then using Intelisence to find the correct syntax Resource instead of R in Java.
Good luck with whatever you choose,
James
I've been mostly programming in C++ as of late, but to be honest I think I need something else I could use. C++ being quite low level requires much more time to make things. It would be nice to know another popular language that is easier to code in. If I were to use C# I'd probably use XNA with it as well, however I'm not quite sure about Java. I know that Java is more cross-platform than C# and that C# is pretty much in Microsoft's pocket however that doesn't bother me. I'm mostly gunning for 2D ASCII/Sprite games as opposed to 3D, however 3D is indeed something I'll eventually move on to.
I want to know what the Stack-overflow community thinks.
XNA is really easy to use for 2D games. Not only does XNA give you content pipeline management within Visual Studio, which makes managing the entire build job quite easy, the framework also sets up a basic game loop and gives you the building blocks to get started. There are plenty of getting started guides and even a growing pile of books on XNA.
XNA works with the free version of Visual Studio and XNA runs on Windows Phone and the Xbox 360 (unfortunately deploying to either of these platforms requires a $100 a year license from MS).
I am sure there are good libraries for Java as well, but I can't give you any details.
I know this was answered quite a long time ago, but on the Java side of things you could have easily used libGDX. It is totally open source and simple to learn the basics. It supports Android, IOS, Desktop (Mac, Windows, and Linux via the JVM), and HTML5. The only (small) learning curb is figuring out how to set a libGDX project up via the Eclipse GUI, but if you are a command line person (and most people here are) then this is one of the most qualified frameworks out there.