After upgrading project that was made with unity 5.6.3p4 to unity 2018.X and taking an android gradle build, the application version gets set to 1.0 even when version is 3.1.2 in android player settings

Hello,

I am facing a bit of a weird issue upgrading an Android project made with unity version 5.6.3p4 to unity 2018.X.

I have an Android project that I made with unity version 5.6.3p4 and I am trying to upgrade the unity version by simply opening the old project with the new unity editor 2018.X. Following the steps, I allowed the auto API updater to update the obsolete APIs too.

Now the application version of my project is 3.1.2 and the bundle version is 40, but every time I build APK of the application, the Application version of the app gets set to 1.0 automatically, even when the Version and the Bundle-Version Code is set 3.1.2 and 40 in the android player settings. I saw the application version in Android Device → Settings → Installed Apps → {My app} details and I also printed a debug.log to see Application.version returning 1.0 in Android Studio logcat.

Now this happens even when I take out an android project export and then open it in Android Studio. The application version and bundle version code get set to 1.0. Now with Android Studio, I have an option to change the application version and bundle version code manually, but the issue is with the Internal Android build system in unity 2018.X.

This doesn’t seem to be a device specific issue as I have tested it with different android devices and the results are same. I have tested with a different combination of devices and unity version and have been doing it since past one week now. And with some analysis, I have noted that this issue is reproducible in unity version 2018.1.0, 2018.2.0 and 2018.2.8 android build. Also, this is the reason I am using the notation “2018.X”. I also noted that this issue is NOT reproducible in unity version 2017.4.0 or older versions.

Now, is this a unity’s internal android build issue or am I doing anything wrong here?

Please note: I have raised a request with the unity support team, but they asked me to raise a question in this forum first and get some pointers to a cause of the issue.

Also Note: I even tried switching the target build platform back and forth from PC, Mac & Linux to Android, but the issue still persists.

Guys if you are able to replicate the issue then kindly confirm it here, or in case if you were able to successfully migrate from unity version 5.6.3p4 to unity version 2018.X then please let me know the steps you followed for the same.

Kindly help! Thanks.

To answer my own question, the issue that I was facing was due to the android:versionCode=“1” android:versionName=“1.0” I had in the main AndroidManifest.xml inside Plugins/Android folder and this was overriding the app version code and bundle code from the player settings in unity 2018.X. I removed these 2 lines from the manifest file and was able to get the correct app version code and bundle code set in the player settings.

I agree the mistake was silly but I was unable to locate it as the same project build correctly with the app version code and bundle code mentioned in the player settings till unity 2017.4 irrespective of the numbers mentioned in the manifest file. Seems like since unity 2018 the behavior has changed and the internal Gradle build has started to consider the settings mentioned in the manifest file on a higher priority than the player settings.

Anyways, I was able to locate this issue after one and half month of debugging yet only after Ricardo Arango from unity’s premium tech support team pointed out this as a plausible reason for the behavior. Thanks Ricardo Arango for an instant direction towards the solution even for such an issue. I hope others don’t commit the same mistake and if they do, they now would just have to find this post.

Regards,

Sanket Kale.

EDIT: It seems that there was also a bug with unity’s internal Gradle build system. After few days of this answer, I again saw this issue and found out that I had to use a mainTemplate.gradle in my Assets > Plugins > Android folder for facilitating some external plugins, and then the APK again ignored the VersionCode and VersionName mentioned in the Android PlayerSettings of unity editor. If you mention the value in mainTemplate.gradle then it will take mentioned value from there but if you don’t, it will set the default value of 1.0 in the APK. It will completely ignore the values set in Player settings if you use mainTemplate.gradle in your unity project.
I found this out after probably 2 months of debugging and communications with the unity support team. Again, Ricardo Arango helped me reach this conclusion and there is bug raised for this with unity. As of now, if somebody is using mainTemplate.gradle then they can set the versionCode and versionName there to get it correctly set while building an APK. Hope it helps.

I have very similar problem.

I went from 2017-4-2f2 version of Unity to 2017-4-18f1 version.

With this script attached to text UI element in the main menu of my game:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TextVersion : MonoBehaviour
{
    private Text textVersion;

    //Awake is always called before any Start functions
    void Awake()
    {
        textVersion = GetComponent<Text>();
    }

    //Use this for initialization
    void Start()
    {
        textVersion.text = "Version: " + Application.version;
    }
}

Before the update, I would always get the correct version of the game written by this script. So if “Version*” in Android player settings was 1.1, I would get “Version: 1.1” in the main menu of the game.

After the update, in Unity editor and PC build of the game, I still get the correct text written “Version: 1.1” but after I build APK of the game for Android and install it on my android device, I always get “Version: 1.0” text. It is like Application.version always states 1.0, no matter the input in “Version*” field of Android player settings. With that said, for example “Package Name” is still reported well in the APK. So this problem might be concerning just “Version*” field for all I know. And beside this, game works fine on my Android device.

I don’t have any Android plugins in asset folder of the game (I didn’t have a reason so far to use Plugins/Android at all) and following thesanketkale case, I made a change directly in AndroidManifest.xml file in Unity installation dir. Line android:versionName=“1.0”, which I set to 1.1. After I did this, I got version correctly reported in my built APK. I also don’t know what android:versionCode=“1” in this manifest is… so I set it to what I set for “Bundle Version Code”, but is this equivalent to “Bundle Version Code”? And if I delete android:versionName=“1.0” and android:versionCode=“1” as thesanketkale did, I get no version reported at all (text in main menu of the game is "Version: ").

Obviously “Version*” input field for whatever reason gets override, in Android player settings so that Application.version is always reporting 1.0 in APK. Is this a bug in Unity? What would be correct way to handle this? Should I create Plugins/Android folder with custom AndroidManifest.xml in it?

Stuff I did during the update of Unity:

  • I didn’t uninstall previous version of Unity and I just installed the new version over the old one, in the same dir. Everything went without any noticeable problems.
  • Once I loaded the game project, Unity warned me that it was project based on old Unity version. When I got in editor, I move/removed an object in the scene, then I saved both scene and the project. Next time I loaded project, Unity didn’t complain.
  • When I was about to build APK, for the first time in new Unity, Unity warned me that Android SDK build tools were old version 28.0.2 and that new 28.0.3 version was needed, and asked me to update it. It downloaded new version dir in SDK directory and resumed building APK without problems.

Hi all,

My solution under Unity 2017.4.18 is : don’t use Gradle (because of the above, very informative answers); rather simply use the Internal Build system, which still does consider the version values in Player Settings.

This can be set under Player Settings > Publishing Settings > Build System, if that is fine for your requirements.

@thesanketkale

Update your mainTemplate.gradle file as in the following:

defaultConfig { applicationId '**APPLICATIONID**' versionCode **VERSIONCODE** versionName '**VERSIONNAME**' }

Unity replaces those with the values you set in PlayerSettings.