I have an application A that consists of feature 1 , feature 2, feature 3. Now I want to create an application B that consists of only feature 1 and application C that consists only of feature 3.
Things I have tried
I have organized the packages according to features. Now maintaining Application A, B and C as separated projects will lead to duplication of efforts.
Android Studio
Using Android Studio I have created "Variants". I am able to get Application A, B and C as apks but size of all the apk is same i.e they contain all the code of complete project. I want Application A, B and C such that it only consists code relevant to there feature. Excluding packages while building is not supported as can be seen from this link. Am I missing something or is there any other way to customize build script for the applicatoin
Your best approach would be to separate your features (1-3) into standalone libraries that can be Java or Android library modules. In your Android Studio project, you can have more modules for applications A-C, and have them depend on the feature modules they need.
Maintaining the features as standalone libraries and keeping the different apps separated from them will probably make your code more modular and easier to maintain, so it should help you in that regard as well.
Using flavors in Android Studio to differentiate the application types would make sense if the applications are very similar and will share the majority of their code. Examples would be a free vs. paid version of the same app. If the apps are conceptually different, you'll probably find it better to make them separate app modules.
Related
I want to build an app with different configurations. Let's say there are two flavors, A and B, which depend on different third-party libraries to perform similar tasks. I want to offer a default configuration on Google Play which comes with a separate launcher for each flavor. Both launcher instances should share local data. However, I also would like to keep the option to build and ship just one of the flavors without including the third-party libraries required for the other one.
From what information I've found, I could either use a single flavor with two launchers, losing the option to build just for one of the third-party libraries. Or I could use two flavors, but would have to separate the whole project into multiple apps with separate ids which would have to be updated separately, presumably require more storage and require some kind of workaround for sharing local data.
So, is there a way to build multiple flavors into a single app bundle with separate launchers or a similar solution for these requirements?
is there a way to build multiple flavors into a single app bundle with separate launchers
I am assuming that by "flavors" you mean product flavors in the Android build system. If that is correct, then... no, sorry, there is no simple option for this.
or a similar solution for these requirements?
It might be possible to pull off something like this with a careful subdivision of your app into modules. You would have three app modules β I will call them a, b, and ab after your naming system. Those would be as small as possible. Most of your code would reside in a series of library modules. In particular, code tied to each third-party SDK would be isolated in its own library (or libraries). a would link to library modules tied to one SDK (plus common modules), b would link to library modules tied to the other SDK (plus common modules), and ab would link to (probably) everything.
So I have an interesting question more or less to the high level design of using Android Libraries vs product flavors vs product variants etc.
Right now my problem is that I am trying to build a second Android application (after building my first) one where in many cases I can reuse a majority of my non UI code (IE activities, styles etc.) and reuse a small portion of the UI code.
Right now I see two different strategies, one being make a new application + Android library for the shared code (resulting in basically my POV two new GIT repos along with two corresponding projects) or take my original application and write a few productFlavor / productVariants and sort of tweak things as needed (this would allow me not to have to make two new GIT repos + project setups).
What do folks usually do in this situation?
Update:
Maybe a project with each submodule would work best as separate apps while moving the central library (shared code) to a library module.
I'm working with Android Studio 0.5.8.
I have a Working project, and I want to reuse all its contents to make an almost identical app with only another name and different colors.
Basically I want to make a library from the original app and reuse it in various identical apps, but I don't want to copy & paste inside each new app, I want to maintain and develop only one codebase (the project library).
I have read and read, but I can'tt find any real solution.
I tried this in my settings.gradle:
include ':AppCopy1', ':..:LibraryProject'
It works, but I cant use any classes in AppCopy1.
This sounds like a good candidate for Product Flavors. The Gradle build system has support for maintaining a single codebase and building multiple apps from that codebase that only differ by a few files changes. See the configuration examples here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants for details.
It's quite often that we see two versions of an android app: a paid version and a free version. I'm also developing an app that would like to release two versions. What is the best way to do this? Creating two projects and copying files in between does not seem to be the best way in my mind.
Use Library Project, as the official dev guide suggested:
If you have source code and resources that are common to multiple Android projects, you can move them to a library project so that it is easier to maintain across applications and versions. Here are some common scenarios in which you could make use of library projects:
If you are developing multiple related applications that use some of the same components, you move the redundant components out of their respective application projects and create a single, reuseable set of the same components in a library project.
If you are creating an application that exists in both free and paid versions. You move the part of the application that is common to both versions into a library project. The two dependent projects, with their different package names, will reference the library project and provide only the difference between the two application versions.
Update: This method is really only good for compiling with Eclipse, since Android Studio supports build flavors which can achieve exactly this.
While #yorkw's and #Nate's answers are both good, this is the method I use due to its simplicity. From the article:
com.example.myapp β Android Project Library - This is where my ENTIRE app lives. All the functionality for the FULL and LITE versions.
com.example.myapp.full - Android Application Project - This is a shell that contains graphics and resources needed for the full version only. Basically itβs a super lightweight shell.
com.example.myapp.lite - Android Application Project β This is another shell that contains nothing but graphics and resources needed for the lite version. Again, its a super lightweight shell.
I also keep a static variable IS_PRO in a library class which is set when the app launches. This should be used only for notifications, alerts, and so on (such as asking the user to upgrade to pro).
However, this method has one drawback: you must clean and rebuild any time the library or its resources are modified. Also be sure to read this post on sharing resources between a project and a library.
I would call this a FORK in development. Start a new App development, but have your common code coming from a common file location. Make your free based edits to the forked code, and try your best to keep that code completely separate.
I actually did this on an iPhone based app, I have a free version and 2 different payed versions (a single player only and a multi-player). I would do it the same way on Android.
U can use git for example.
Create branch "app_with_ads", and master will be your "paid" version.
Develop in master and merge periodically to another.
before publish u probably will have to change app package, or something else in Android\ Manifest.xml
Here's a little blog tutorial about doing this.
Basically a howto for building a Full and Lite version of the same app, using a library project to accomplish code reuse between the two versions.
Since it's popular to have both a free and a paid version in the android market of the same app, I had decided to do the same. Initially I just duplicated the complete codebase and adapted some code here and there (added ads, built in some limitations etc) since there was no option to do library projects at that time, but that left me with two projects that are horrific to manage fixes to bugs as I need to do those twice.
Since r14 we can use library projects with resources, so that would be a great solution to this particular problem as far as I can tell. Therefore I've read up on library projects and conciderations, and I'm curious to know what the minimum amount of files needed in the projects of the different versions are. My questions therefore are;
Could I have all of the code in the shared project, and have bare bone project with basically just a manifest?
If so, should I? is this the optimal way conceptually? (so apart from the fact that it depends on my code base)
How should I deal with library package naming, are there specific rules?
Are there tools about that can compare code from two different projects and perhaps merge them auto-magically or auto-manually, and which one is preferred?
If I understand your problem correctly, you want to create multiple Android apps that are similar to one another (i.e., have a lot of the same source code), but which are different in particular (minor) ways, and you want each of these apps to have a distinct package, so that it can be separately uploaded and distributed on an app store such as Google Play. A Project Library is an excellent facility for accomplishing those goals.
I'm assuming that the differences between your various versions are minor, involving things like resources and the app name and package, and a switch that turns on certain features for a paid version while leaving them off for a free version.
Even if that is not the case, by using polymorphism in the ways described below, your various apps could differ in significant ways and still share a common Project Library.
A Project Library can be defined in Eclipse in the same way as any Android project can be defined, but it is marked as a Project Library (by checking the "Is Library" box near the bottom of the Android page of the library's Project Properties dialog) and cannot be compiled and run on its own. Instead, it is intended to be included by reference in one or more other projects which are actual apps (by adding a reference to it on the Android page of each such app's Project Properties dialog). These apps will use the Project Library, and thus will share its code and capabilities.
Each such referencing app will have its own manifest file (where their respective, different packages can be declared), and they can also define their own classes (including classes derived from the Activity and/or Application classes of the Project Library), so that these classes can be specialized polymorphically for each app that uses the Project Library (e.g., by overriding methods or by providing definitions for methods that are defined as abstract within the Project Library's Activity- or Application-derived classes), although you can also use those Library classes without modification (provided that they are not abstract) by simply referencing them within the manifest file (e.g., in an activity or application tag) of each app that uses the Library, just as you would reference Activity or Application-derived classes defined within the app itself.
If you decided to use this approach, then you would put your main source files in a Project Library, and would create a separate project for each app you want to produce, each of which would reference the Project Library. The manifest file of the Project Library would be overridden by the manifest of whatever project is being created using that Library (actually, I think that the Project Library's own manifest is completely ignored, not just overridden, but nonetheless it is useful to create a manifest for the Library, so that you can manually template - copy and edit - the manifest of each project that uses it from the Library's own manifest).
I have used this approach to create multiple android apps that share some of the same capabilities, and it has worked very well for me.
Regarding package naming, any old package name will work for a library project, but of course it makes sense to use the same prefix for the Library Project's package as you use for your various individual (e.g., free vs. paid) apps that use it, with something like ".library" as the last part of the name, while the various apps could have endings like ".myappfree" and ".myapppaid". Naturally, you would want to use your reverse domain name convention for the library's package prefix to prevent conflicts, just as you would for a package name of a released app.
In Windows, a nice, open-source tool for comparing code bases is WinMerge:
http://winmerge.org/
If I were in your position, however, I would only use this tool to manually identify differences, and would not attempt to use it to automate the refactoring of your code into a Library Project. That would be best done under your own (manual) control.
Finally, as an alternative, you might consider using a single app that is free and that has your free app's capabilities by default, with an option to upgrade to your full app's capabilities (delivered within the same APK) via an in-app payment, rather than having separate free and paid apps. In-app payments have improved a great deal in the past several months (with the release of version 3 of IAB), and although there are still some glitches, they have become a more practical alternative to the free/full dichotomy than they were at first.
Yes, you can have a project that is basically just a manifest specifying app name, name space, icon etc, with all the actual code and 99% of the resources in the library project.
Yes, I think you should use this approach. It's very common to use library projects to deal with the Free/Paid app problem.
I've not had any problems with naming, though you should be careful with any resources in separate projects to avoid using the same names.
I'm not aware of any tools, and if it were me I'd want to do it manually to be sure I'm merging what needs merging and keeping separate what needs to be separate. you've one significant refactor to do, but once all the duplication is removed I'm sure it'll be much easier.