Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versioning an Android application #253

Open
deliberist opened this issue Jun 23, 2022 · 3 comments
Open

Versioning an Android application #253

deliberist opened this issue Jun 23, 2022 · 3 comments

Comments

@deliberist
Copy link

Has there been any thought as to how bump2version can be used to change the version of an Android project?

Typically an Android project has a <repo>/app/build.gradle file that has something like:

android {
    defaultConfig {
        versionCode 1
        versionName "1.0"
    }
}

Where android.defaultConfig.versionCode is basically a one-up counter, and android.defaultConfig.versionName usually follows the form {major}.{minor} (rarely does it have a patch element) -- per the Android versioning documentation.

I have not yet tested it, but I believe bump2version should be able to handle versionName (major.minor) but I do not know how it can handle versionCode (one-up counter), if it even could. Initially I would write a config with:

[bumpversion]
current_version = 1.0
commit = True
tag = True
tag_name = v{new_version}
message = Bump version: {current_version} → {new_version}
parse = (?P<major>\d+)\.(?P<minor>\d+)
serialize = {major}.{minor}

# The versionCode is a one-up counter.
[bumpversion:file (versionCode):app/build.gradle]
search = versionCode {current_version}
replace = versionCode {new_version}

# The versionName is a {major}.{minor} pair.
[bumpversion:file (versionName):app/build.gradle]
search = versionName "{current_version}"
replace = versionName "{new_version}"

But this won't work for versionCode. Any idea how I can finagle something into versionCode to be consistent with how it is normally handled by Android?

@olutra
Copy link

olutra commented Jan 6, 2023

This should work:

[bumpversion]
current_version = 1.0
parse = (?P<major>\d+).(?P<minor>\d+)
serialize = 
	{major}.{minor}

[bumpversion:file (versionName):build.gradle]
search = versionName "{current_version}"
replace = versionName "{new_version}"

[bumpversion:file (versionCode):build.gradle]
serialize = 
	{major}
search = versionCode {current_version}
replace = versionCode {new_version}

@deliberist
Copy link
Author

This should work:

[bumpversion]
current_version = 1.0
parse = (?P<major>\d+).(?P<minor>\d+)
serialize = 
	{major}.{minor}

[bumpversion:file (versionName):build.gradle]
search = versionName "{current_version}"
replace = versionName "{new_version}"

[bumpversion:file (versionCode):build.gradle]
serialize = 
	{major}
search = versionCode {current_version}
replace = versionCode {new_version}

@Maccheroni I do not believe that will work. It will only set versionCode to the major version. The major version (and versionCode in that sample) does not increment when there are minor releases.

If hypothetically we released an Android application starting with 1.0 we'd want to maintain versionName and versionCode consistent with Android conventions:

  • versionName = 1.0 ; versionCode = 1
  • versionName = 1.1 ; versionCode = 2
  • versionName = 1.2 ; versionCode = 3
  • versionName = 1.3 ; versionCode = 4
  • versionName = 2.0 ; versionCode = 5 # new major release
  • versionName = 2.1 ; versionCode = 6
  • versionName = 2.2 ; versionCode = 7
  • versionName = 3.0 ; versionCode = 8 # new major release
  • versionName = 4.0 ; versionCode = 9 # new major release

Bumpversion, as it stands, does not have a way to get a handle on what Android apps need as the versionCode.

Hope that makes sense.

@olutra
Copy link

olutra commented Feb 8, 2023

@rbprogrammer the unreleased version 1.0.2-dev has a configuration option indepenent for a part. By default when parent part is bumped, children part is set to its first value, and if part is independent, it retains the previous value. If I understand correctly, you want the part to increment every time the parent part changes.

I added configuration option always_increment in my fork
https://github.com/olutra/bump2version/tree/feature-always-increment
You can try to install it with
pip install git+https://github.com/olutra/bump2version.git@feature-always-increment
and test with config like

[bumpversion]
current_version = '15.4#19'
parse = '(?P<major>\d+).(?P<minor>\d+)\#(?P<counter>\d+)'
serialize = '{major}.{minor}#{counter}'
[bumpversion:file (versionName):build.gradle]
serialize = {major}.{minor}
search = versionName "{current_version}"
replace = versionName "{new_version}"
[bumpversion:file (versionCode):build.gradle]
serialize = {counter}
search = versionCode {current_version}
replace = versionCode {new_version}
[bumpversion:part:counter]
always_increment = True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants