Related
We're designing an app that will run on Windows, OSX, iOS, and Androids. It would be really nice to at least have most of the code in a single language rather than having to use Objective C for the Apple versions, C# or C++ for Windows, and Java for Android.
We were looking at Flex (with all of its problems) as a way to avoid having to use a different language for each version, but Adobe has thrown in the towel and in the long run that's not going to do the job. Java used to promise to be universal, but it looks like Apple no longer supports it as a part of the distributed OS, and as far as I can tell Microsoft never supported it. We don't want our users to have to download and install something just so they can use our app.
Is there a solution? Or are we stuck with building the app in multiple languages?
HTML + css + JavaScript!
Run your app on a standard web server. All of the above have standards compliant web browsers, all of the above support JavaScript and AJAX. The only thing that really varies is screen size and this can easily be dealt with by using a custom .css file for each target browser.
You could host a web application on a server and use the app browsers to interact with the application.
Although not a native application, all devices would be able to use it.
The downside is that server connectivity would be required, however this may not be an issue.
"global" languages are most likely to use virtual machines, so you can't escape the "users have to have to download and install something just so they can use the app"... I think Java is your best bet if you don't want to deal with problems of languages that compiles into native machine code.
You could use C# on all those platforms:
"Normal" .NET on Windows
Mono on OSX
MonoDroid on Android
MonoTouch for iOS
(If you ever wanted to write an app for Windows Phone 7, you'd be fine there too.)
Of course the UI part will have to change significantly between different platforms, and I doubt that it'll be particularly seamless, but it's worth considering at least.
i am not very sure, but i have heard python is a universal language. I have tried this with both mac and windows, not sure about the other plactforms
I believe C++ code can be run on all those platforms: Windows has full support for it; Android has NDK; and you can use Objective-C++ on iOS (and I assume OSX as well!).
I wouldn't go so far as to claim it's the best option, but I figured it was worth mentioning.
Ultimately a lot will depend on the nature of the app you are developing. If it's a large app I'd strongly suggest doing some detailed consultation with someone with experience in the area: because of the vagaries of the different platforms, this is one area where experience counts for an awful lot.
There are multiple options, depending on your app requirements:
First, Web app, as many said before. It is the same as the greatest common divisor - very small
Second Build the core of your app in c/c++, and for the interface use a framework that fits your needs. These suggestions are really, really great. You can even develop the interface separately for each platform, in Java for Android, Objective C for iOS, etc
Do not forget that never, ever you will be able to make the same code run on all platforms. There will always be some part with #define MAC or #define ANDROID. It's just impossible to run identical code, even for the simplest app.
Unless is a
void main(void){}
Even a web app will have a code like
if(browser()==Safari) {}
else {}
I think the answer depends on what kind of app you are going to build.
If it's like twitter, a good web interface is the answer. Each client just need to handle the GUI work, with the platform's own language and lib.
If it's a game, no communication with server. I prefer C and a script such as Lua to build the core of your app.
"Is there a solution? Or are we stuck with building the app in multiple languages?"
No, no solution for this. We use different languages because they run in different platforms. Universal languages, such as HTML, have lots of constrains because to be universal you must cut all the differences. It is the intersection set of all platforms, which is very very small .
Using HTML and Javascript is likely to be the best approach. Another option which runs on these platforms is Java FX 2.0.
All java libraries are not present within android e.g. javax.script, java.awt.* etc. It makes it very difficult to use a lot of useful libraries written in java (e.g. libraries for java script evaluation, image processing, etc.).
I am just curious, would anyone have an idea as to why android team has decided to keep these out of android sdk?
This article might provide some basic explanation:
Google’s mobile phone platform, Android, supports a relatively large
subset of the Java Standard Edition 5.0 library. Some things were left
out because they simply didn’t make sense (like printing), and others
because better APIs are available that are specific to Android (like
user interfaces).
I think that other reasons might include the fact that the mobile platform does not have the computational resources that other devices such as laptops and desktops might have (even though this seems to be changing with the introduction of high end mobile phones).
Edit: I think that the concept of 'usefulness' varies, so what yourself find useful might not be so for other people. If you want specific reasons why this specific package was left out, it is of my opinion that you are asking it in the wrong place. With regards to this specific package, the javax.script, you might want to consider taking a look at this previous SO post which proposes an alternative.
Can i use MeeGo (www.meego.com) to make my own handheld equipment? To distribute mobile or notebook or desktop as embedded equipment, with my custom application on it for multimedia?
Can i use MeeGo with Java/D or C language? Multimedia and cross platform is never easy. Is MeeGo the right choice?
Lots of questions, I'll answer them one at a time.
If your custom hardware runs an ARM or Intel Atom CPU you absolutely can use MeeGo as the OS. The downloads page has images for both platforms, as well as images for netbooks. The only caveat is that most of the source is GPL. If you patch the MeeGo distribution in any way, you might have to release the source code for it (depending on what it is you changed). Custom applications aren't bound by the GPL however so your app can be closed source if you want.
MeeGo is based on gcc-4.5.0. Which means you can use C and C++, and perhaps some Java via gcj. The MeeGo APIs are centered around C and C++ though. If Java is more your thing, the Android Open Source project might be a better choice, but since it's more specialized than MeeGo it might be more difficult.
MeeGo comes with GStreamer 0.10.30 which is the standard C-based Multimedia-framework for Linux. It's a very powerful framework based on streams and sinks. In other words, it's very modular, and in theory, you can easily replace or plug-in to any part of the rendering pipeline.
Edit: My bad, I meant objective-c, not c#. Some reason I got it into my head it was c# the iphone used. So the answers for c# were great, thanks, but theyre a bit irrelevant, sorry about that.
I've had a look but can't find anything that answers this, though a few have shortened the question by answering parts of it. Between a small group, we were planning on doing some work on iPhone and Android, the 2 seperate for the most part but helping each other out, and with some guys doing graphics work split between them.
But we were thinking about the possibilities of moving things between the two, not necessarily apps, maybe just useful classes or something. Looking at objective-c and Java, they seem to have about the same features that the biggest obstacle would be system interface stuff, so we were wondering whether, if we created an abstraction over these on each system so they could be given the same input (which unless I'm wrong wouldn't put too much strain on the system?), would there be any problems in writing something to convert between objective-c and Java, worse than the locations of methods in the sdks? Or are there key features or something in one language that the other doesn't have which we've missed that would mean the only way to do it would be rewriting from scratch.
I wouldn't waste time trying to find commonality between iOS and Android.
Cross-platform is almost always a waste of time and resources unless the cross-platform capability is central to the apps functioning. That is especially true for platforms such as iPhone and Android which have custom OS and work very tightly with the hardware.
Cross-platform development environments add rather than reduce complexity long term. Yeah, it sounds neat but usually you get 90% what you want easily and then you hit a roadblock that destroys all the savings you made and then starts putting you in the hole. There are simply to many compromises and square pegs jammed into round holes.
Unless your app could in theory work from a generic web page, cross-platform is not for you.
In the specific case of Objective-C and Java, although Java is descended from Objective-C they have no modern interoperability. You can't use code from one on the other.
You should spend the time to learn each platform's specific API. There are no shortcuts.
Tools like XMLVM, Codename One and iSpectrum tell us that you can actually cross-compile Java code (from an Android app or creating one from scratch) to Objective-C code that is running on an iPhone without having to install any virtual machine on the Apple side of things.
I suggest watching Developing iPhone Applications using Java
Unfortunately Apple's license
agreement for the iPhone SDK prohibits
the porting of the Java virtual
machine to the iPhone. In this
presentation we introduce an Open
Source Java-to-Objective-C
cross-compiler as well as a Java-based
implementation of the Cocoa library.
With the help of these tools, iPhone
applications can be written in pure
Java. Using the Java version of Cocoa,
it is possible to run a Java-based
iPhone application as a Java
desktop/applet application that can be
cross-compiled to run natively on the
iPhone. The talk will discuss the
challenges of the Java-to-Objective-C
cross-compiler as well as the
Java-based version of Cocoa. Details
are available at http://www.xmlvm.org/
and for more insight a more recent talk about Cross-Compiling Android applications to the iPhone from Frebruary 2010 is available here, which is documented at http://www.xmlvm.org/android/ :
Android is an Open Source platform for mobile devices. Initiated by Google, Android has received much attention. Android applications are developed using Java, although a special compiler converts class files to a proprietary, register-based virtual machine that is used on Android devices to execute applications. Android defines its own API for writing mobile applications. With the help of XMLVM it is possible to cross-compile Java-based Android applications to native iPhone applications.
The Android application is written in
Java and makes use of an Android
specific API. XMLVM offers a
compatibility library, written in
Java, that offers the same API as
Android, but only makes use of the
Java-based API for Cocoa Touch. During
the cross-compilation process, both
the application and the Android
compatibility library are
cross-compiled from Java to
Objective-C and linked with the Cocoa
Touch compatibility library to yield a
native iPhone application.
From the 2008 talk about building Java applications for the iPhone http://www.xmlvm.org/iphone/ :
Apple's iPhone has generated huge
interest amongst users and developers
alike. Like MacOS X, the iPhone
development environment is based on
Objective-C as the development
language and Cocoa for the GUI
library. The iPhone SDK license
agreement does not permit the
development of a virtual machine.
Using XMLVM, we circumvent this
problem by cross-compiling Java to the
iPhone. Just like a Java application
can be cross-compiled to AJAX, XMLVM
can be used to cross-compile a Java
application to Objective-C. The
cross-compilation is also accomplished
by mimicking a stack-based machine in
Objective-C.
If you focus on abstracting away things like system interactions, and stick to the common subset of the languages, you can probably build classes that would require little or no modification to move from one language to the other.
C# does have a better implementation of generics than Java, in that C#'s generics retain strong typing at run-time.
C# also has LINQ, which as far as I know has no equivalent (yet) in Java. LINQ provides a SQL-like query capability, built into the language and fully supported by the .NET frameowrk, that lets you query object collections, and does so in a very functional-language style. LINQ can be extended by query providers to work with other data formats, such as XML and SQL, once the query provider provides an object model that translates to the other format. LINQ also makes parallelization very easy for multi-core work. It's a huge extension to language capability.
This topic is often filled with the dogma of technology jihadis, so I shall try and steer clear of that in my answer.
In my experience, I would largely agree with people saying that trying to share code between the two platforms would be difficult. However, there are some important exceptions:
I would consider cross-platform development where your business logic:
is non-trivial;
should be standardized across platforms; and
has well defined interactions with the outside world (e.g. network stack or UI).
(bonus) is written already.
Apple is the rate determining step here, given the now infamous 3.3.1 restrictions on source code languages. You can write code in Javascript according to the bundled Webkit, C, C++ and Objective C.
If you don't want to install extra languages on a 'droid, you can use the Java that compiles down to dalvik code, the Javascript as per the slightly different build of webkit or something from the NDK. Then you'll be looking at C/C++. You could cross-compile Objective-C, but I haven't had any experience of that.
The clean separation of business logic from UI and networking is important, as you'll be looking to write adapters for the networking layer, something else for the UI.
I would not attempt to write cross platform UI code in C/C++, and would either write something that used HTML/CSS/JS, or more likely write something completely custom to take advantage of the different UI metaphors on each platforms - e.g. there is no analogue to the notification bar on the iPhone. Animation on the iPhone is orders of magnitude simpler to implement than on Android.
If you don't need the UI to be massively integrated with the OS, then a webview and some HTML5 may be sufficient. Titanium is a good option here, and my colleagues in the know tell me it is better (i.e. compiles, not interpreted) than PhoneGap. Again I don't know.
Going the other way in complexity, Open GLES is available on both platforms.
It should also be noted that SVG is not available on the current crop of Android OSes.
If you actually want to do cross phone development, as long as it is not something really computationally expensive, I would probably go with PhoneGap.
PhoneGap is an open source development framework for building cross-platform mobile apps. Build apps in HTML and JavaScript and still take advantage of core features in iPhone/iTouch, iPad, Google Android, Palm, Symbian and Blackberry SDKs.
As far as I can tell, it's pretty much the only cross platform toolkit that is allowed in the iPhone app store.
If you're dead set on native development, I think you'll find that unless you're making a game and targeting c, it will be a lot of work to port. The frameworks are very different and the way of building UI is very different. That said, to answer you're direct question of objective-c vs. java, it's not that bad. It is different enough, though, that an abstraction tool would not be that easy - not like Java vs C#. Objective-c does not have garbage collection (on the iPhone anyway), for example, and the syntax is very different. Objective-c is more loosely typed in the way that it does method calls (messages in objective-c). That said, they aren't wildly different in terms of programming paradigms. They are both object oriented imperative languages. They both have classes and methods, public and private. If you wanted to port the code by hand, it wouldn't be the end of the world, I just think you might wind up spending a lot more time trying to build an abstraction layer.
If you're thinking about doing Android development my best advice is to go for java. There is no benefit at all of writing a complete abstraction (assuming you can) layer to convert from C# to Java. As for the IPhone development dont doubt about using Objective-C for the same purpose.
You can't develop for the iPhone in the same language as for Android. For the iPhone, you can only program in Objective C, it's developed by Apple. You can't use it for android, and the only way to do iPhone development is with that language (it's in the user agreement).
As for C# vs. Java, the whole principle is different. Java is one language for every platform, .Net is one platform for every language. They are not compatible. You can use Java on Android, but I'm not sure if you can use C# (.Net) as well.
Anyway, you'll have to build two different apps for these two mobile operating systems.
I remember Sun's slogan so vividly... "Write Once, Run Anywhere". The idea being that since programs are compiled into standard byte codes, any device with a Java Virtual Machine could run it. Over the years, Java seems to have made it onto many platforms/devices.
Is this the intention or was it ever the intention of .NET. If so, what kind of efforts are being put forth to make this a reality?
To correct some comments by others here, .Net was ALWAYS intended to be multi-platform. That is why Microsoft separated the namespaces into "System.*" (which were platform-neutral) and "Microsoft.*" (which were Windows specific).
There is Mono which runs on Linux, Solaris and OS X. In practice .Net is still pretty much a Windows-only platform. It's not really in Microsoft's interests to push it to be WORA, on the contrary. Appearing to be cross-platform however is. A lot of people have been really paranoid about Mono on Linux. MS's supposed strategy is to first let it grow to be an important part of the Linux application platform and then release the lawyers. I wouldn't bet my future on .Net's portability.
The answer is a very shaky Yes. The moment you include an external library, the answer changes to No.
For example, Microsoft has no 64-bit JET driver. JET is used by .NET to access MS Access databases.
Any applications compiled for the Any CPU target that use MS Access databases will fail on a 64-bit version of Windows.
(This is ignoring that said applications are not portable to Mono.)
Microsoft has never made those claims but they ARE making moves in the WORA arena. Silverlight 2.0 for example will use a subset of the .NET framework and be available on Windows, Linux (through the Moonlight project), MacOS, Windows Mobile, and Nokia handsets.
As others have mentioned, the Mono project has also brought the framework to multiple environments.
To put this in context, in many people's view Java never delivered on its "Write Once Run Anywhere" promise either.
At best what you got was "Write Once Debug Everywhere" or "Write Once Looks like crap Everywhere"
The successful CLR based applications have all been written using a graphical framework that is native to the target platform.
For example the following highly successful linux applications where written using c# bindings to GTK called GTK# and not using winforms like you would expect:
Banshee - music player like itunes
fspot - photo manager
TomBoy - notes program
GnomeDo - Quick launcher and dock
Equally successful windows .net applications are not written using GTK# (even though it is cross platform) they are written using winforms or WPF.
When google came to make Chrome they didn't try to use a cross platform GUI framework, instead they choose to use native GUI frameworks on each platform. Why? because that way the application, fits properly into it's environment, that way it looks, feels and acts like its native to the operating system its on.
Basically when you try to have write once run anywhere you have to make serious compromises and what you end up with is something that doesn't really work right anywhere.
The industry has largely given up on the lofty goal of write once run anywhere, as a nice idea which didn't work out in practice.
The best approach with mono/.net is to share your lower level binaries and to use a native gui framework on each target platform. GTK# on linux, winforms or WPF on windows, CocoaSharp on Mac. This way your application will look and feel like a native app.
With Mono we're getting pretty close, and with SilverLight we're allready there.
I don't think the official "intention" of .NET was WORA. I think that you could safely say that .NET was designed so that it would always run on future MS OS's. But there is nothing that precludes .NET from running on other platforms. Mono is an example of an implementation of the .NET runtime for an OS other than Windows.
Yes, this was a goal of .NET although I don't think it had the same emphasis as it did in Java. Currently, the only effor that I know of is the Mono project that is creating a version of the CLI which runs on Linux.
Interestingly enough, Silverlight actually has a slimmed down version of the CLR which can run on both Windows and Mac, which allows the same Silverlight app to run on both platforms unchanged.
It's theoretically possible, since the CLR (.Net's "virtual machine") complies with an open standard (the CLI). The question is what other implementations there are of that standard. Mono is another work in progress, but it's the only other one I know of.
I think that the idea with .NET is that it is a "Write Once, Run Anywhere (that Microsoft chooses)". However, the Mono project is slowly changing the situation.
It will never be supported on as many platforms as Java, IMHO.
The only effort is Mono, not sponsored by Microsoft.
Check here on SO and on the official site
In theory, yes. .Net Assemblies are bytecodes, which are converted to native code upon startup, using a JIT ("just-in-Time") compiler.
In practice, there aren't many platforms beyond Windows which have a .Net JIT compiler. There's one for Linux, called MONO.
Don't know about Mac, Sun etc...
Theoretically, the language is designed to be compiled into bytecode like Java which is interpreted by the Common Language Runtime, a mechanism that also allows several languages (not just C#) to work together and run on the .NET framework.
However, Microsoft has only developed the CLR for Windows. There are other non-MS alternatives being developed, the most prominent being Mono, a CLR implementation or a number of platforms (see the link).
So in theory yes, in practice - we'll see.
Yes and no. Parts of the .NET environment are standards and could be openly adopted.
For example, the runtime (CLR) has a portable version called Mono which is multi platform, open source and is used by (for example) Second Life.
The intention, or at least the pitch, was for this to be the case. The reality is that .NET can't really run on other platforms. The only major exception is Mono, which is an open source project. It's essentially a rewrite of the .NET runtime (the equivalent of the java virtual machine) that works on Linux, Solaris, Mac OS X, Windows, and Unix.
It's been fairly successful, but it's not officially supported.
If you're thinking of getting your monolithic Acme corp employer to adopt .Net and Linux, forget it. Realistically, with .NET, you're on Windows machines, period.
Yes, .NET has the Common Language Runtime (CLR) which is the .NET equivalent to the JVM. Microsoft does not support it on as many platforms as Java but with the help of the Mono project it is possible to achive cross platform applications with the usual caveats.
Bear in mind that .NET is more than just the CLR. It is a whole platform.
Since .NET is only available (officially) on Windows, then not, it isn't write one, run anywhere. However the Mono team are making a good go at helping spread .NET beyond Windows, but they are always way behind the official stuff.
I don't think that it was the original plan, for Microsoft, to create runtimes for every platform and device, but they encouraged this by using a documented (?) intermediate language.
Multiplatform was of course in the vision.. right now mono does a good job of implementing the runtime for other os.
Mono
Short answer -- no, Microsoft only supports MS operating systems (including Windows Mobile) for .NET.
Long answer -- there are public open-source projects to replicate the .NET framework for linux and other OSs, notably Rotor and Mono. They don't support everything, but you can deploy a lot of .NET code, including silverlight.
That depends on your definition of "Anywhere".
There are several flavors of Java virtual machine and of .Net framework.
And most of the time you can't just write code for a desktop vm/framework and expect it to run on a mobile phone one.
So. in a sense, even Java is not really pure "Write Once, Run Anywhere".
It is true, however, that Java's VM is currently running on several operating systems while .Net framework runs only on Windows devices.
There is one interesting initiative called "Mono" which offers .Net support on Linux, Solaris, Mac OS X, Windows, and Unix. Read here: Mono Site
dotNet can be, because of the CLR which is similar in function to the JVM.
But i dont believe MS had any intention of it being.
http://www.mono-project.com/Main_Page
might be useful, but its not a MS product.
Btw, much like how the wide spectrum of j2ee containers cloud the WORA concept for j2ee apps, ASP.NET apps running on anything besides IIS wouldnt really work the same across disparate platforms.
I don't think this was ever really a design goal of .NET - Microsoft has no particular interest in people writing software for non-Windows platforms ....
However, there is The Mono project (http://www.mono-project.com), which is "an open development initiative sponsored by Novell to develop an open source, UNIX version of the .NET development platform."
It was most assuredly meant to be WORA. It's just MS figured Anywhere and Everywhere would be Windows by now. Who knew Linux and the MacOS would still be around. But judging by all the Macs at the PDC, I guess they were either half right or half wrong!
If WORA was really an original goal, then I guess we'd see .NET implementations on all the major platforms by now, fully supported by Microsoft. I seem to recall that at the time Sun was shouting WORA from the rooftops, Microsoft's riposte was "Write Any (language) Run on One (platform)" (WARO:-). As somebody else mentioned, I think they've always been firm backers of WORASLAIW (Write Once Run Anywhere So Long As Its Windows)
As you point out, they seem to be changing tack a bit with Silverlight to try and get a piece of the Flash/Flex action now that the battlefield has shifted significantly away from the desktop and towards the browser.
But it IS multiplataform Win9x/WinNT/Mobile
Given responses from others I'm still unclear as to whether it was an actual intention of Microsoft to have .NET be a WORA initiative. The only way to really know I guess is to have somebody from the Microsoft .NET team chime in on this.
Since we cannot definitively know the original WORA intentions of .NET we can point to efforts that are attempting to make this a reality (as previous answers have talked about).
[Mono](http://en.wikipedia.org/wiki/Mono_(software))
This effort is an initiative happening outside of Microsoft.
Mono is a project led by Novell (formerly by Ximian) to create an Ecma standard compliant .NET compatible set of tools, including among others a C# compiler and a Common Language Runtime. Mono can be run on Linux, BSD, UNIX, Mac OS X, Solaris and Windows operating systems.
Silverlight
This effort is being heavily pursued by Microsoft. Silverlight 2.0 implements a version of the framework that is the same as .NET 3.0 and seems to be an attempt to successfully deliver the framework to multiple platforms through the browser.
It is compatible with multiple web browser products used on Microsoft Windows and Mac OS X operating systems. Mobile devices, starting with Windows Mobile 6 and Symbian (Series 60) phones, will also be supported.
While it does not specifically address bring functionality to GNU/Linux there is apparently a third-party free software implementation named [Moonlight](http://en.wikipedia.org/wiki/Moonlight_(runtime)).
This seems to be what we currently know, but as stated earlier, it would be very helpful if somebody from the .NET team could pitch in on this one to properly clarify if WORA was in fact an original initiative.
If Microsoft were serious about dotnet on other non windows platforms they would have released the class libraries for reuse by others ajoiding the need to rewrite the same libs again. Sun on the other hand has done this meaning less barriers are present ifnone wishesto port to another platform. Natually with java one still needs to write a vm and do the native stuff but it helps avoid a headache that is reimplementing the entire class library. The standardization of the language wS a marketing ploy to grab jon technical folk. A language without libs is worthless. Try doing your next project withnknly the prjkitive types ... That's right write your own string class etc and tell me how helpful a standardiSe language is without any libs available...
I think the idea was to create inter-operability between the different programming languages, not WORA.
.Net Core makes .Net "almost" Write Once Run Anywhere.
But there are subtle differences -
.Net Core is not really .Net
With .Net Core, you write once but build multiple times, once for each specific target OS. Whereas in Java binaries are built once and can be run on any supported OS.
dotnet build --runtime ubuntu.18.04-x64