Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manage code/build for Android app stores (Google/Amazon/etc)?

I have an Android app that's downloaded primarily from Android Market (now, Google Play). We made a few tweaks to the source and also submitted to the Amazon App Store to see what sort of traction it gets. I'm now looking for a sustainable way to develop from a common code base and yet build so that I can submit to either/both.

Amazon's store has some restrictions about available APIs, and hence I'd like to conditionally remove/modify features from that version. Since Java doesn't support traditional conditional compilation, and conditionally including files in Eclipse doesn't seem trivial (is it even possible?), I wanted to ask what others are doing to solve this.

Admittedly, I'm no Eclipse/Java expert so feel free to school me.

What I'm looking for in a solution:

  • Building/debugging using Eclipse.
  • Static code files, with environment/settings toggles to control what to build.
  • No duplicate code or conditional logic in code to pick code flow at runtime

Is this something you've solved for Android apps specifically, or for other Java/Eclipse based projects? Suggestions for where to begin?

like image 842
psychotik Avatar asked Mar 22 '12 00:03

psychotik


People also ask

Can I make a Android app with AWS?

In this tutorial, you will create a simple Android application using AWS Amplify, a set of tools and serverless services in the cloud. In the first module, you'll build a simple Android application.

Is Android Studio necessary for app development?

Before start building an Android app, it's important to select an IDE for programming. The official IDE for Android development is Android Studio. Android Studio is the best overall IDE for getting started.


1 Answers

It's quite easy to do in the newest versions of ADT (version 17), though I do find it makes compilation a bit longer:

  1. Create a new Android project (proj-A)
  2. Go to Project->Properties, select Android, and check "Is Library"
  3. Move all your common code to proj-A, import all the necessary libraries
  4. Create a new Android project for Google Play (proj-B)
  5. Go to Project->Properties, select Android, and add Proj-A to the Library
  6. Repeat #4&5 for the Amazon version

If you have some variables that should be set differently for each sub project (i.e. boolean GOOGLE_PLAY_VERSION to enable Google Play specific functions), you have to create another project to contain these values since you can't have projects that reference one-another in a circular fashion. You can solve this by adding the following steps:

  1. Pull all of your sub-project specific variables into one or more Classes that just serves as container(s) for these variables
  2. Create a "dummy" Java project (dummy)
  3. Config proj-A to add a new Source link to the bin directory of dummy
  4. Add the config Classes in each sub-project with project-specific changes
  5. Profits!

Note that the variables in dummy should not be set as final, otherwise it will override sub-project's setting.

This may seem like quite a bit of up-front work, but has worked quite well for me as far as version control goes.

Edit: Now with Google's move to Android Studio & Gradle, it may be better to move to that if you are starting a new project if you want to support multiple APKs, see Android dev site's Building Your Project with Gradle#Work with build variants. It definitely doesn't hurt to evaluate that option before deciding.

like image 122
Kai Avatar answered Oct 05 '22 09:10

Kai