what are the differences between Java library and android library and what advantages/disadvantages has each?
You can include standard Java .jar file libraries in an Android app. They are translated into Dalvik format at .apk build time.
There is an Android Library system which allows the use of shared resources such as layouts and localized strings. As that has more restrictions that regular Java libraries I'd only recommend this method if you actually need to share resources.
http://developer.android.com/guide/developing/projects/projects-eclipse.html
I imagine you meant the android API (or SDK, I can't say) and java API (or SDK). Basically, android is based on java. It is a subset of it, but also adds specific classes and methods to interact with the hardware and the android OS, implement UI, etc.
You can find info about the android architecture here: http://developer.android.com/guide/basics/what-is-android.html
Concerning advantages/disadvantages, well, if you're developing for the android operating system, then is a great advantage to use the android API. If you're developing for PCs, then part of the android API won't be supported, which is what I would call a disadvantage...
In sum, you need to choose whether to use the andoid API or not depending on what will you be coding: will the API be supported by the OS? Is there a JVM for it?
It is very important to know that serialization of classes shared between the two is supported. But they must be located in a package with the same name in both projects.
Related
I was looking for a way to possibly use a java library of my own inside of my Flutter App.
I did some research but was only able to find information about how to integrate flutter with native Java libraries on Android exclusively.
Is there a way to call on java code also from Flutter Web and/or Flutter Desktop?
I am sorry I can't provide further information to this question as I was not able to find any "lead" if not starflut (https://pub.dev/packages/starflut) - which to the 'beginner' programmer I am in Flutter might seem an overkill approach to this problem - and I'm not even sure it supports Flutter Web/Desktop as of yet.
Any help, comments or ideas would be highly appreciated
EDIT 1
As implementing Java on Flutter Web seems close to impossible (or not worth the hassle), would calling C++ libraries from Flutter Web be a possibility?
EDIT 2
To better describe my problem/situation, I'll add some context.
I need to write a library that can be accessed by multiple flutter apps (both Web and possibly Mobile, but PWA would also be ok), but also by multiple programs which don't use the flutter framework.
I considered a couple of options, but I am still quite inexperienced and I am not sure which way to go forward with:
C++ as the core of the library, and making language bindings to Dart
It seems C++ code can work on mobile, but I haven't found a way it can be run on Web as well as within Flutter
JavaScript as the core of the library, and
either accessing the library directly from Flutter Web (seems to be possible https://medium.com/flutter-community/using-javascript-code-in-flutter-web-903de54a2000 )
Though I am not sure if this solution would work also on Mobile Flutter
Using Dart itself as the core of the library
this would be the quickest option when rolling out the Flutter App(s), but it would also have the drawback that I'll need to rewrite the library in another language later on
Calling c++ from flutter web is not possible. You can, however implement whatever functionality you want in the server-side using whatever language you want and expose the functionality to flutter using whatever web API you desire. You can follow the same approach with Java, and it doesn't have to be just web. The requirement though is that whatever you're implementing has to reside on the "server" which the system can run freely. Your flutter app just "connects" to it and sends and receives messages
I want to create application mobile with flutter but i need api java which is jena, so can we use library java.. In flutter if yes, so how?
You could use platform channels to communicate with native interfaces of your app, but looking at the library, that's probably not a good idea.
More drawbacks:
You have to implement native code twice, for Android (Java/Kotlin) and iOS (ObjC/Swift). That means an app depending on Apache Jena will only work on Android if you don't find a counterpart that works natively on iOS.
All communication through platform channels is asynchronous, which increases complexity.
When the API of the java library is complex, you end up duplicating a lot of code.
If your app heavily depends on Apache Jena, you have a few options:
Create a Backend Service in Java that does the processing which requires Apache Jena. Send the result to your Flutter client.
Write a native Android app that directly uses the library. Drop iOS.
Port the parts of Apache Jena that your app needs to Dart (probably too complex)
You would need a Flutter plugin that exposes the Jena API to your Dart code base over platform channels.
The bad news is that at least as of November 2018, no such Flutter plugin exists as yet.
The bottom line is that, yes, it's technically doable, but you would need to create the plugin yourself or motivate somebody to create it.
Android Instant Apps documentation states in the restricted features section that it can not:
Run unverified software, run arbitrary native code, or load code dynamically other than the code provided by the Instant Apps runtime.
I don't fully understand the above statement but it sounds to me like it may not accept any third party software or any native libraries other than libraries given in SDK/NDK.
Could someone help to elaborate?
This statement:
Prepare your app > Restricted features
Run unverified software, run arbitrary native code, or load code
dynamically other than the code provided by the Instant Apps runtime.
Refers to APKs, libraries, or code that is sideloaded, not packaged within the original apk.
unverified software
In other words, only the signed apk and its contents are allowed.
arbitrary native code
Everything must run from your apk or be provided by the framework.
load code dynamically
Such as use of DexClassLoader to retrieve stuff that’s not already packaged with the apk.
You can use third-party libraries. What you can't do, for example, is download a binary from your server at runtime and run that.
An unofficial answer from an official Google representative was that with Instant Apps, unlike normal apps, there is no technical way to run downloaded code, or load classes dynamically. For normal apps, the restriction is written in Play Store Developer Policy, and is enforced only on Play Store via standard security monitoring procedures.
I currently work for a company which gave me an application implemented by a former student. They completely wrapped (even the main) an existing C++ application with SWIG.
The application was first designed to work on a desktop and now they want to make it work on an android phone.
My questions are:
Is that possible for the application to work knowing they didn't succeed to wrap all
the libraries?
Is there another way to do this?
Is it necessary to write the main in Java and call the C++ libraries?
Any idea will be welcome!
I have doubts about there is a automatic utility like SWIG will work to convert PC -> Android - Android OS have significantly different architecture.
Look at Android NDK - it is a development kit supporting the features called JNI in usual Java applications.
You can include C++ libraries in your Android applications with Android NDK. So it is the way to develop cross-platform applications.
Android class libraries are written in C/C++ but java is the preferred language for developing applications.Why not C/C++ instead of java ?
If you prefer to develop via C/C++ you may use the NDK. The Android platform is run on the Dalvik Virtual Machine, what you code in java is actually compiled to Dalvik bytecode and run on the VM.
They spent a lot of time developing the facilities to make it fairly painless to make an Android application using a managed language. Some people would consider this an advantage.
There are many reasons to choose Java as the platform, but my guess as to the biggest reason why would be to not expose application developers to a slew of porting issues that arise from the sheer number of devices that Android powers. There would be far fewer apps available if every developer had to research every platform nuance for every phone and tablet out there.
Obviously, there are drawbacks, and that's why the Native Development Kit (NDK) exists. The NDK primarily addresses performance issues, but recent additions have included the ability to write an entire app completely in native code.
Java it's used in many application for mobile devices, it is a standard because it is more manageble, even the new languages that are appearing now it's based in java. It is a open language and you can learn it without going to class. Javame is used for mobile devices which incorporates some features of J2EE and adds new classes for the small devices.