I want to develop an android application that supports dynamic loading and unloading of bundles. Therefore, I am considering using an OSGI implementation framework.
What would be my best OSGI implementation choice?
By best, I am talking about Documentation (Availability of resources), Compatibility with Android API, and support for embedding OSGI in Android Application.
While searching, I found two implementations that seem to be good:
1- Apache Felix
2- Knopflerfish
Any suggestions? Thanks.
Both work on Android. Like Balazs pointed out in a comment, there are quite a few subtle differences between Dalvik and the JVM and some of those do bite you when doing OSGi style dynamic loading of code. From memory, you also have to worry about not being able to load the same class twice (even if they are privately packaged in different bundles). However, since you're probably designing the application from scratch, you can probably work around such issues.
You will also find some information here: OSGi container for Android
One tricky aspect though is that Android is also a bit of a moving target. The first version of Android did not have the classloader methods exposed that we needed to get Felix running, so we had to do a bit of reverse engineering. It is hard to predict what future versions of Android will bring though. Things might break. Are you going to choose your own version of Android and deploy it to the devices you target, or does the code need to run on existing devices?
Related
I've been working on a writing a game for Android. Until now I've been using Java instead of the NDK, but I've decided to port my code to C++ (for performance, memory management and industry standards reasons).
Porting my application shouldn't be a problem (I've written my fair share of C++ applications), but I've been using RoboGuice as a dependency injection framework because otherwise my object graph would become too complex rather quickly.
I've been looking around, but I haven't found any resources about using a dependency injection framework in combination with the Android NDK.
Can someone tell me if there any such franeworks available. If so, which one would you recommend?
If you have a C++11 compiler for Android you could use several frameworks (I wrote Infectorpp) but there are others available. You should note that DI is quite limited in C++ due to the lack of reflection so you should make some compromises as not everything you did in RoboGuice would still be possible.
By doing a quick search seems that C++11 is possible on Android. I don't have an Android device and still not needed to emulate it, but if you have any feedback it will be wellcome (private message here or support ticket on google code is enough), the library is headers only so no special build stuff is required for it, apart enabling c++11 on your compiler wich is just one extra option by command line. If that will works good on Android then it will be definitely good also for PC. (Do not misunderstand please, I'm using it heavily, but seems very few people is interested in DI in C++ and so I get very little feedback)
There was also a nice framework cpp-resolver: a little awkard to use because you explicitly register factory functions for injecting ALL parameters, but very scalable, especially for server applications.. (decouple object lifetime management and works with plain old C++).
The most complete framework is probably wallaroo
If you search something really easy to use Infectorpp is a good choice
If you need control over lifetime (mostly servers): Cpp-resolver is perfect
If you need exotic features and configuration files: wallaroo
As side note, run-time configuration is possible also with frameworks that do not explicitly support it:
You just need a Factory that istantiate a different type based on a configuration file you could read through a class that you add as dependency to factories (Probably you don't need to know that since you were already using DI frameworks, but still good to know for occasional readers)
I want to know more about Cross-Platform. I'm currently working on my thesis and decided to make an Android Application but not all target users uses Android device. So, We've come up with an idea to Cross-Platform the android application.
I have read the same topic but it didn't get to me too well. iOS / Android cross platform development. I want to know if there is another way than using the frameworks discussed in the link.
I want know what is the best/shortest way to cross platform a Android Application?
Cross Platform tools are in my opinion not a good idea at all. Android is Java, and iOS is Objective C. Android can use NDK to use a C/C++ library so theoretically if you did most of your code in C/C+ it could be used on both sides. I think two natives is more in order. Study NDK to see what could run on both devices. Lets say you built your app as a C++ Library except for UI interactions. Then in theory the library should work on both sides. C/C++ a lot easier on iOS than android however.
Also it really depends on the dependencies your app will have. Lets say you want to use a library but its only available in Java or C++ how does this effect your decision.
You might also consider designing your app so that it just captures data on the devices and the actual processing of the data takes place in a web service.
Another way is use Mobile Web HTML5 Framework like Phonegapp, Sencha touch and more.
Although web technologies don’t perform as well as native, but it is a useful thing that you can try.
See Choosing Mobile Web HTML5 Framework and http://operationproject.com/2011/adventures-in-html5-part-one/
Android application are apk files that are basically zip file that contains dex/odex files and all other resources that you may wish to add.But I think you can use any coding language to develop as long as you have IDE that converts your code to apk and dex .And most important of all your programming language must support corresponding api or must have something similar to cross compile.The reason Google used Java for Android was they felt it is convenient to do it(read it during case Google v/s Oracle)
Personally I feel cross-platform is good since it increases the developers base and understanding of the System (here Android).And I think the same analogy would go with other Systems as well.
I'm working in a project similar to Taintdroid that uses a scientific technique called "dynamic taint analysis" .
So I have to find the appropriete containers for OSGi to deploy on android.
I find answers in https://stackoverflow.com/questions/560794/what-osgi-container-do-you-recommend
but it is is not destinated to Smartphones.
So what's the favorites OSGi containers for Smartphones and why?
I use Apache Felix, which has support for Android out of the box. I like it because of its 'clean' OSGi implementation, and its modest footprint makes it a good choice for a smartphone (especially since componentizing your application stops some of the Android tooling's optimizations).
Other than that, assuming that you get other containers to run on your device, it all comes down to personal preference and finding the best fit for your situation.
I'm debating using guice in an android project that is quite complex and has a lot of business logic. Guice seems like a good fit, but whenever I start reading deeper into it, it starts to look more complicated than it needs to be.
One thing I don't understand is: if Guice is so great and the best way to write java code, how come there is so little Android code that uses Guice... and why didn't Google use guice internally for Android?
Guice totally makes sense to be used and in fact is used in a whole bunch of applications. The extension RoboGuice adds some niceties for Android that makes it super productive to use.
In fact I can not imagine writing an Android app without it. Too painful.
Check out the links to apps using Roboguice on the website (e.g. Google Docs, OpenTable...). Also other apps like the Square app are known to use Guice directly.
It totally makes sense .. go do it!
Together with Robolectric it will also make your testing efforts easier.
PS: I am a committer on RoboGuice so I am partial ;-)
PPS - June 2013: Recent developments have given rise to other annotation/dependency injection based frameworks that do most of the work at build time and therefore avoid the performance hit of the runtime reflection (that is slow on Android) and are therefore more suitable for performance critical work - check out Dagger and AndroidAnnotations if you are interested in that.
Actually google discourages using Guice or RoboGuice in android applications due to memory overhead.
Source:
http://developer.android.com/training/articles/memory.html#DependencyInjection
5.11.2014 Edit:
There is a dedicated fast dependency injection library for android. I can see more and more people using it:
http://square.github.io/dagger/
13.04.2015 Edit:
Google released its own version of dagger, which does not use reflection in runtime:
http://google.github.io/dagger/
You know there is RoboGuice? It's Guice for Android.
The problem with demonstrating the strengths of a dependency injection framework is that it isn't possible to achieve it with a simple Hello World application. These frameworks show their value only in big systems with a lot of complexity. Also, they have a somehow steep learning curve.
Therefore it is quite normal that you can't find enough tutorials - open source projects that use Guice. This will be most often used in enterprise applications that do not get published.
As why Google doesn't use Guice, Guice doesn't fit everywhere. It adds a perfomance overhead and it doesn't make sense to use it in places, where it isn't needed.
As a beginner for Android development, code samples I am learning from look somewhat disorganized and are hard to test or even to understand. So I followed this post suggested: Using Dependency Injection with Roboguice? and am trying to use Android-binding and Roboguice. But I am now worrying about how good they really are.
Are they good enough for all Android projects including ones with a couple of views?
After building an app with these tools, how is the app's performance in comparison without the tools? Any problem with using these tools?
Is there any other tool that can help me for Agile/TDD?
I've only used Roboguice and this is my opinion of it.
Roboguice is derived from Guice. So it's not really a dependency injection framework built from the grounds up for mobile environment. That being said, it can cause quite some overhead to your app.
On the other hand, I haven't seen any mobile app that reached a complexity that really needs dependency injection. I had an app the used Roboguice, but soon I realized that it's making my app more complex than it needs to be. So I stripped it out. I guess this depends a lot on the scale of your app.