[BUG] Unity 2018.1.6f1 can't set versionCode & versionName to custom AndroidManifest.xml

Hi Unity Team

i have a custom AndroidManifest.xml in

Plugins/Android/AndroidManifest.xml

it only define the xmlns:android and package property

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="xxxxxx">

in Unity 2017.4.6f1

if i build an apk . it will generate the correct versionCode and versionName for me

but when i upgrade to Unity 2018.1.6f1

it can’t set the value correctly

if i fill the android:versionCode and android:versionName proerty in AndroidManifest.xml.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="xxxxxx" android:versionCode="1" android:versionName="1.1">

it will use the property . not change it at all . ( the result will be versionCode=1 versionName=1.1)

============

it also happen in my Gradle template. previously i don’t need to set minSdkVersion in defaultConfig. but it 2018 version , if not set minSdkVersion, it will set as

minSdkVersion 1

defaultConfig {
minSdkVersion 16
targetSdkVersion **TARGETSDKVERSION**
applicationId '**APPLICATIONID**'
}

============

is this a bug or i need change something in my code?

Thanks

Eran

Hi Eran!

We cleaned up the manifest template, and moved more things to build.gradle, meaning that gradle will set the necessary values when building.

Please make sure you use build.gradle template from your current Unity version (and not older ones). Let us know if you still have any issues.

Hi

i have tested my project with new gradle templete. it’s working :slight_smile:

Thanks :slight_smile:

1 Like

Hi

We’re using 2018.4.18f1, The mainTemplate.gradle for this version doesn’t contain versionCode & versionName in defaultConfig Section. When building it doesn’t seems to be changing the versionCode & versionName in AndroidManifest.xml. Causing it be blank in generated builds.

4130884–363313–Unity2018.4.18-mainTemplate.gradle.txt (1.52 KB)

Yes. Exactly the same here. (Unity 2017.4.18f1 not Unity2018) I’ve got this in my gradle file

defaultConfig {
        minSdkVersion **MINSDKVERSION**
        targetSdkVersion **TARGETSDKVERSION**
        applicationId '**APPLICATIONID**'
        ndk {
            abiFilters **ABIFILTERS**
        }
        versionCode    **VERSIONCODE**
        versionName    '**VERSIONNAME**'

        multiDexEnabled true
    }

The output is converted to this

defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        applicationId 'com.help.stressfree'
        ndk {
            abiFilters 'armeabi-v7a', 'x86'
        }
        versionCode  
        versionName    ''

        multiDexEnabled true
    }

I thought LTS branch was meant to be stable? You can’t just replace the Android build system on a release branch that’s not meant to have any new features.

3 Likes

Same issue for me as @ (I think, using the LTS 2017.4.18f1). I can no longer upload new versions of my sdk because the version code is always set to 1 by unity, regardless of what I set in Player Settings.

1 Like

EDIT: this is a known issue; the fix has landed yesterday and will be available in the next version. Sorry for the inconvenience caused!

@ versionCode and versionName params seem to be missing in 17.4 template at all, but they are present in latest 18.3 versions.

@Yury-Habets Yes. I have a 2018 project that I copied them from assuming that would fix the issue but it didn’t. The issue exists whether you include those lines in the gradle file or not

Right, so the issue with the manifests was fixed and will make it into 2017.4.20f1.

2 Likes

Do you know why this was done on the LTS branch when its a breaking change?

1 Like

This was not done intentionally.

I get that. I’m not suggesting you intentionally broke the LTS branch but what I’m saying is that upgrading the gradle version - even if it worked, required me to regenerate my gradle script which was not communicated at all and cost me many hours of dev time to work out why my Android builds were failing. My understanding was that LTS would not introduce new features for this very reason.
If nothing else, please consider making upgrade instructions more visible when upgrading to a newer version of Unity.

2 Likes

Dang, I just ran into this after upgrading to 2017.4.19f1 that was just released. Can you please add this in BOLD in the release notes that this is a know breaking issue?

3 Likes

Is there a work-around fix for this bug? For example, can we edit the default gradle template and add the appropriate lines to make sure the versionCode and versionName get set?

2 Likes

When 2017.4.20f1 will be released? Do we have to wait another 2 weeks?

Hi everyone,
I had no time to wait for 2017.4.20f1, and I had to make temporary solution.
It totally works for me and I hope it helps you too.

I had the same problems as you guys. All of them:

  • versionCode,
  • versionName,
  • platformBuildVersionCode,
  • platformBuildVersionName,
  • and also with signature

[INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.xxx.yyy signatures do not match the previously installed version; ignoring!]

First of all, I analyzed the changes that gradle makes incorrectly in the mainTemplate.gradle file.
I found out that the versionCode, versionName, storePassword and keyPassword parameters were filled with empty values.
So, my solution is to populate these parameters from code instead of Unity.

private static void FixGradleTemplate(string bundleVersionCode, string bundleVersionName)
{
    var gradleFile = Application.dataPath + "/Plugins/Android/mainTemplate.gradle";
    var gradleData = File.ReadAllText(gradleFile);

    var signTemplate = "\tsigningConfigs { release {\r\n\t\tstoreFile file(\'_0_\')\r\n\t\tstorePassword \'_1_\'\r\n\t\tkeyAlias \'_2_\'\r\n\t\tkeyPassword \'_3_\'\r\n\t} }";
    var signData = signTemplate.Replace("_0_", PlayerSettings.Android.keystoreName)
                               .Replace("_1_", PlayerSettings.Android.keystorePass)
                               .Replace("_2_", PlayerSettings.Android.keyaliasName)
                               .Replace("_4_", PlayerSettings.Android.keyaliasPass);

    gradleData = gradleData
                 .Replace("**VERSIONCODE**", bundleVersionCode)
                 .Replace("**VERSIONNAME**", bundleVersionName)
                 .Replace("**SIGN**", signData);

    File.WriteAllText(gradleFile, gradleData);
}

p.s. Shame on you, Unity.

4 Likes

We apologize for the inconvenience. We are humans and sometimes make mistakes.

3 Likes

Have u guys writing more and more unit tests to avoid regression?

You are absolutely right, we are not machines and any person is prone to err.
The fact of the mistake is not a claim. It just happened.

Again, you are professionals and I have no doubt about that.

I am saddened by the reaction to error messages.
For example, as a system user, I expect to be told how to resolve the issue as soon as possible. As a workaround, until the patch version is released.

1 Like