How can I reuse code AND resources in several applications? I have a fairly large code base (including resources) that I want to reuse i several applications. How can I do that?
I did try to use the Android Library concept (http://developer.android.com/guide/developing/eclipse-adt.html#libraryProject) but never got it to work in Android 1.x
I'm amazed by the lack of information on the subject. It seems like Google has aimed Android development at pet projects and not real development. Variant handling should have been solved ages ago.
I've faced this issue. Android doesn't really lend itself to 'template' style development because the frameworks are relatively immature and the nature of the development is so wide ranging, however, these are some steps I've taken:
Create a library of common resources - I have generic XML files ready to go that support things like checkbox lists, context menus and dialogs.
Create some generic APIs for things like service bindings
Wrap common functionality into components - I've written my own location wrapper for example.
Note: I assume you mean reuse outside of SCM.
Related
Are there any advancements in this area? I want to be able to write purely functional code on Android in Haskell or similar languages. I've tried some examples with Scala but it seems to be a pain to get started. Are there any other functional JVM languages which I can use to write Android applications?
Edit: functional languages that write native android applications. My mistake about the JVM.
I doubt that you can find anything mature for writing Haskell-like code for Android. You do need to implement Java abstractions which are required by Android API (implement activity, etc.).
But if you really want to write for Android in a purely functional style you can try to implement your business logic in a pure functional language that compiles to JVM and call it from your Java classes. That approach would be much simpler than trying to implement it entirely in pure functional style.
As your language choice, you can try
Frege, it even has a library for android - froid
Eta lang, it is very new and probably nobody has tried to use it for Android yet
I you want a painless solution in terms of Gradle builds etc., you have only two options: Java and Kotlin, of which of course you should choose Kotlin ;)
Kotlin has most of the things you need to write in functional style:
functions as first class citizen
higher-order functions
immutable collections
var and val like in Scala
if-else as a statement
elements of pattern matching (where statement)
tail recursion
and more...
If you also include funKTionale and kotlinx.collections.immutable, you'll have all the functional goodies like: Option, Try, currying, memoization, persistent data structures and so on...
To start with Kotlin just install the latest Android Studio 3 Preview, which already has built-in Kotlin support.
BTW, don't be so polarized into "pure" functional ;) After all, being 100% "pure" means no side-effects, which means your app can't interact with the user ;)
Hope this helps :)
I've never tried it personally, but you can do F# programming using Xamarin.Android (and, I believe, with Xamarin Forms too). You can see the guide here. (It also includes sample code).
As some background, F# is the .NET Framework's functional language. It is derived from ML; in fact, many ML scripts can be compiled almost "directly" as F# (with the caveat that you may have to do some renaming because F# has some additional keywords that ML doesn't have in order to support several .NET-specific extensions).
Xamarin allows for native development for Android, iOS, and Windows phone. Xamarin Forms allows for a single code-base for all three platforms (it's a competitor to Ionic).
One more quick point: Android does not use the JVM, even if you're writing apps in Java. (In fact, Android does not even support all Java 8 features yet). Through Android 4.4 it used Dalvik; after that, it started using Android Runtime.
You could also try using a JVM language like Scala to create a JAR file and create a bindings library for it.
Please also note that you'll end up using at least somewhat of a mixed paradigm - for example, things like Activities are objects, and the XML files used to define an Android screen is, for all practical purposes, declarative. Edit: This last point is slightly debatable - see the comments.
One final possibility: I haven't checked this out too closely, but try also this link for a site claiming you can do Scala in Android.
Between Pure functional and Java, there is a way which is IMO Pragmatic functional. For instance Redux achieves that in the React arena.
My goal is to write an app (Activity) having an immutable state that advanced as a result of interactions is functional.
In the browser you can see that done with elm (Haskel like language which is also web platform)
Since we want an Android app, I opened the Android Studio used the wizard to create and app with Navigaton Drawer Action bar (with Drawer, FloatingActionBar),
Then converted it to use Elm concepts of immutable model functional approach into a working POC based on a small ElmBase class and idioms.
The code is written in Kotlin (JetBrains tool of choice for the JVM).
You can find the app at my GitHub https://github.com/saffih/ElmDroid The sweet spot of that approach is that it leverages Kotlin being strongly typed and the editor does code completions very well,
making lot's of the code completed for me in a way I have never seen before - amazing experience (But it require using idioms like the sealed class and when properly).
I work on a lot of closed source projects but often find myself extending the same classes, implementing the same libraries, doing the same things for caching and solving memory issues, and seeing other companies I work with facing the same issues
It makes me wonder if there are engines for android out there created for certain purposes. My cursory google search on this issue was unproductive
but I think this question is constructive because there is a real answer to this instead of discussion. Alternatively, what StackExchange site would this be a better question on?
Google Play Services and Volley are great examples and responses by google to certain problems such as but not limited to GPS/Positioning logic, network calls, bitmap caching, but I was wondering if there was anything more that is also maintained.
It sounds like you have a few different problems that each have their own solutions.
extending the same classes, [...] doing the same things for caching and solving memory issues
Making your own library that contains these custom subclasses and caching implementations would probably suit your needs pretty well.
You may also want to learn how to create your own templates for Android Studio. Templates (such as the "new Master/Detail flow" default template) can be used to automatically generate classes and XML files to avoid spending time writing boilerplate code. Here's a GitHub repo with a number of examples.
implementing the same libraries
This sounds like your core complaint is that you want a way to automatically generate a base project of sort for your projects that might automatically include certain libraries, set up a package structure, etc. This can be accomplished using Maven archetypes.
If you want an example of how to create a Maven archetype, I would check out Velcro.
There is a core ERP mobile application for Android. A customer has requested additional features that will require more screens (and Activities) and extra functionality.
Is there a way I can add sort of an extension to the core mobile application in order to intergrate the extra features or should I code on top of the code of the core application?
I am interested in finding a neat solution focused on extendability since different clients might ask for different additional features. How would you deal with such an issue? Any tips on the structure of such a project would also be welcome.
Would it make a difference if the extra features need to use the same db as the core application?
Thank you in advance for your help.
The answer to your question lies in the Open/Closed principle introduced by Bertrand Meyer. Open/Closed Principle is a very simple Object Oriented Design principle which states that
Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification"
From your question its clear that you have identified the core functionalities in your application. So rather than Modifying this core functionalities and making it more specific, I would recommend, on the basis of the Open/Closed principle, that you should freeze your code features and write your customer specific functionalities over it without corrupting the core.
Now to answer your question on what kind of structure you may follow. I would recommend that you create a library project of your core functionalities and make different client specific projects that would include your core functionalities as a library project.
It won't make a difference if your application is using the same db as your core application provided all your applications uses it, else it should not be in your core application in the first place.
Hope this explanation help you.
Update:
My friend pointed out that I may not have understood the question right. So rather than correcting my old post(...which may be useful for others) I am updating it.
So if I understand it right, you have an ERP project which you may not have coded. The right approach, according to me,still would be that you build over this existing code. Rather than making changes on this project, include it as a library because if the project is downloaded from a reliable source, you will have the benefit of getting the updated version as and when it is available.
This is kind of a design philosophy question. Here are a couple choices that might give you ideas:
You could look into making your core application code/features into a custom library. Then your new core application is just a simple wrapper that includes the custom library. Your additional features for a specific customer could then be a different app that also references the core library but will include additional features. There are lots of tutorials on how to turn your app into a custom library. You would end up with different apps that target different a customers. (A tip that took a while for me to uncover is that if you have a resource name in your custom library you can "override" it by using the same name in the app that includes the library. Another tip is that you need to essentially duplicate the manifest of the library in the app by listing all the activities in the library that would be used by the app.) I haven't tried this but it might be that your additional features are each libraries that are included in different apps.
You could have an key the user inputs that will unlock certain features. You could save this as a shared preference so that they don't need to keep entering the key. This approach has the benefit that you can "reuse" features for other clients without any more implementation other than determining which client gets what feature. The majority of users just wouldn't have a key to unlock anything.
Both these solutions should use the same db since they would be calling the same core classes, etc.
Another possible solution is to create a Library Project. Put your core ERP app code inside the library Project, and then create different project for different customers. Each one of these projects will also use the same library project.
Your core library project could expose an api to dynamically register new features (Such as a menu that can expose new menu items).
We are starting the development of an Android and IPhone app and wanted to know if the best practice on developing the UI for both environments.
We have developed the core (functionality) for both the environments as common classes. The core does not have dependency on the UI at all.
Is the best practice to have separate UI code for IPhone and Android or should they be combined together and where required conditionally written?
I would like to understand this as you may have come across situations like this.
Appcelerator has two recommended methods for creating cross-platform UIs - branching and platform-specific commonJS.
In my experience the use of platform-specific commonJS has been the easiest to maintain, although it does require a little extra work up front.
The section on supporting multiple platforms in a single code base in the Titanium 2.0 documentation goes into greater detail on this subject and should be helpful in choosing the path that's right for you.
A good example of creating cross platform UIs is the community app created by Appcelerator's Titans program.
I'm currently in the process of creating quite a large scale Android application. As part of the application I've created a Custom View (one of many).
The Custom View in question is quite wide ranging in terms of functionality and because of that there are an awful lot of layouts, resources & drawable involved to respond to different devices, orientations, resolutions etc.
How can I separate out this functionality so it can be developed in isolation and not contaminate resources in the rest of the project. (Also, make it available to share across projects without having to untangle resource's).
I'm hoping that it is possible to somehow "jar" it all up in some way but fear this may not be possible. It would be great if anyone has any strategies to achieve this.
You'll probably want to look at a Library Project.
It lets you share code and resources between applications.
From here:
An Android library project is a development project that holds shared Android source code and resources.
Other Android application projects can reference the library project and, at build time, include its compiled sources in their .apk files. Multiple application projects can reference the same library project and any single application project can reference multiple library projects.