Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto-increment build number of Android project in Eclipse (prefer portable solution)

Getting an IDE to automatically increment build numbers is a long discussed issue - I'm always surprised that something that seems so basic (to me) is so much work.

The highest scored question and answer (by quite a bit) for this topic are here: https://stackoverflow.com/a/8156809/150016 My problem is that the solution depends on .net and I'd prefer to avoid a .net dependency for Eclipse solution. I also want to avoid any dependency on VCS.

So, I'm looking for a solution that is portable and 'Eclipse-ish'. I think the best candidates are an Ant solution (which I will post) or a Java app similar to the dotNet app in the linked answer above.

(I didn't add my answer to that question because it has an accepted answer and is already a very long post. If the moderators prefer I will delete this question and add my answer to the question above.)

I was hoping for something comparatively simple but I don't think any solution to this problem really is simple.

like image 913
Tom Avatar asked May 25 '12 19:05

Tom


People also ask

How do I use auto-build in Eclipse?

Project > Build All (Ctrl+B) can be invoked at any time to trigger what auto-build was doing automatically. This allows you to build up a larger set of changes before invoking a build (Eclipse remembers which files have changed so that it does not have to do more work than required when you do ask for a build.

How do I automatically increment build numbers for my capacitor app?

Appflow provides an auto-incrementing environment variable ( CI_BUILD_NUMBER) that can be used to automatically increment build numbers for your Capacitor app on iOS and Android after each build. To do this, first install the @capacitor/configure project into your app: Next, create a simple appflow.yml file with the following contents:

How do I build a project in Eclipse?

Eclipse has a good answer on their website: You have two modes of working: auto-build mode and manual build mode. By default, you are in auto-build mode and Eclipse takes care of compiling source files automatically. Builds occur automatically in the background every time you change files in the workspace (for example saving an editor).

How do iOS and Android compilers read version and build numbers?

The iOS and Android compiler encode these values into the app binaries, reading the version and build numbers from certain project files. Both those values must be set in the project files before compiling the app since they can’t be set afterwards.


2 Answers

In the project's properties dialog, under Builders, you can configure a script to run prior to building your apk.

In the properties dialog, select Builders from the list on the left. Click New to add a new script. On the dialog that pops up, select Program. On the ensuing dialog, call your Builder Program what you like in the Name field. Put the path to the script in the Location field. Give it a working directory in the Working Directory field. Note that you can specify variables in these fields (e.g., we use ${build_project:/libs/update_version.sh} to reference a script in the project's lib directory).

You'll want this to run before any of the other builders, so move it to the top of the list using the Up button.

On the Build Options tab of the Dialog (it's right under the Name field towards the top), you can select options for when you want this program to run.

I'm assuming something like Linux, Unix, or MacOS here. In those systems you can use grep or its variants to get the current versionCode, increment it, and then awk or similar to modify the file accordingly. Or, you could write a Ruby, Python, Perl, etc. script to replace the versionCode in the AndroidManifest.xml file. I suppose there are equivalent tools on Windows, but I'm not very familiar with that environment.

like image 94
Brian Cooley Avatar answered Oct 19 '22 05:10

Brian Cooley


Have you tried to 'Maven-ise' your android project build ?

If you use the "maven-android-plugin", you can keep track of your project build with pom.xml's "version" tag.

In pom.xml you can increment the build version by using "versions-maven-plugin"

To reflect the incremented build number to to your AndroidManifest.xml you can use the Synchronizing Version technique within your pom file.

This way you can auto-increment the android project build number by running the "versions-maven-plugin" every time the app builds. The solution is also portable in the same way the Ant solution is.

I hope this can also solve the problem you have mentioned (and what I have understand). Please correct me if something is missing.

like image 22
rizzz86 Avatar answered Oct 19 '22 04:10

rizzz86