I want to update my app changing the value of the version and name, I do not find nothing, about change version programatically
Asked
Active
Viewed 1,346 times
0
-
Simply said, **you can't**. But you can use some FAKE strings to show to the user. – Phantômaxx Jun 26 '14 at 12:04
-
You want to change the version name text dynamically from Androidmenifest to your activity ? or you want reverse ? – user1621629 Jun 26 '14 at 12:20
-
I need update my App, and I need compare with versión of web, from my pone, and update my phone – Jun 26 '14 at 12:38
4 Answers
1
I managed to do it.
version = sys.argv[1]
gradle_file = './path/to/your/build.gradle'
with open(gradle_file, 'r+') as file:
offset = 0
previous_line_length = 0
for line in file:
if "versionName" in line:
previous_line_length = len(line)
break
offset += len(line)
new_line = ' versionName "'+version+'"'
# add spaces at the end if new line is shorter than previous
diff = previous_line_length - len(new_line) - 1 # minus 1 for the carriage return char
length_diff = diff if diff >= 0 else 0
for i in range(length_diff):
new_line += ' '
new_line += '\n'
file.seek(offset)
file.write(new_line)
This is a python script, you call it with the new version string, for example:
python script.py 1.2.3
You will need to add safety spaces at the end of the versionName line in your build.gradle file, otherwise a longer version name will mess up the file.
Hope that helps.

Kignuf
- 96
- 7
1
For Android you can easily increase versionCode and versionName by
add this to your gradle script and also create a file version.properties with VERSION_CODE=555
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def code = versionProps['VERSION_CODE'].toInteger() + 1
versionProps['VERSION_CODE'] = code.toString()
versionProps.store(versionPropsFile.newWriter(), null)
defaultConfig {
applicationId "app.umanusorn.playground"
minSdkVersion 29
targetSdkVersion 30
versionCode code
versionName code.toString()

UmAnusorn
- 10,420
- 10
- 72
- 100
-1
Version Name & Version code you must mention in Manifest Itself , so you can change and give Update manually but You can't change programaticallly

pavanmvn
- 749
- 10
- 21
-
and how I can update my App ? / check ? http://stackoverflow.com/questions/24393950/android-update-app-programmatically – Jun 26 '14 at 20:38
-
If you want manual update follow this http://stackoverflow.com/questions/15213211/update-an-android-app-without-google-play – pavanmvn Jun 30 '14 at 06:02
-
You can, just not in the android app. You can do it via a script that changes your manifest/other file with a version number in it. Most companies eventually add this to their build system. – Gabe Sechan Jan 02 '21 at 16:00
-1
You can't do it rather doing in manifest.xml