When i run my app every time, versionName is incremented in Manifest file. 20389 means that is old version name, 20390 is incremented number.
Project is built successfully like BUILD SUCCESSFUL. But the question is that why Android studio caches previous apk version. Here is what is error:
Target device: lge-nexus_5-061642fd00511249 Uploading file local path: H:\customFolder\app\build\outputs\apk\MyAppName-0.6.200_20383-debug.apk remote path: /data/local/tmp/com.example.app Local path doesn't exist.
As you pay attention when app runs on a device, android studio try to instal 20383 version of apk. It is wrong. Could anyone help me? I've googeled and saw this link.
Here is how i can change manifest file with gradle script:
def updateRevisionNumber () {//autoIncrement Version Name
def currentVersion = getVersionName();
def currentRevisionInManifest = currentVersion.substring(currentVersion.indexOf("_")+1);
def lastRevision = Integer.parseInt(currentRevisionInManifest) + 1;
println("currentRevisionInManifest: " + currentRevisionInManifest);
println("lastRevision: " + lastRevision);
def oldText = manifestFile.getText();
def changedText = oldText.replace(currentRevisionInManifest,lastRevision+"");
manifestFile.setText(changedText);}