Android Gradle: why the APK name changing is not working?

Viewed 44

I have this in my app level build.gradle / android {}:

android {

  applicationVariants.all { variant ->
        variant.outputs.all {
                def variantName = variant.name.replace("Release", "")
                def versionName = variant.versionName.trim().replaceAll(" ", "").replaceAll("\\.", "-")
                def formattedDate = new Date().format('YYYY-MM-dd HH-mm-ss').replace(" ", "T")

                if (!versionName.contains("-UAT") && !versionName.contains("-CICD") && !versionName.contains("-DEV")) {
                    versionName = versionName + '-PROD'
                }

                println "myapp_${variantName}_${formattedDate}_${versionName}.apk"
                def newName = "myapp_${variantName}_${formattedDate}_${versionName}.apk"

                outputFileName = newName
        }
    }
}

But if I build the APK, it is called myapp-cicd-release.apk (what was okay before, this was the default name of it, now it should change...)

Here is my android manifest:

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

    <queries>
        <intent>
            <action android:name="android.intent.action.SENDTO" />
            <data android:scheme="mailto" />
        </intent>
    </queries>

    <application
        android:allowBackup="false"
        android:testOnly="false"
        android:debuggable="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:showWhenLocked="true"
            android:turnScreenOn="true"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:windowSoftInputMode="adjustResize">

            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme" />
            <meta-data
                android:name="io.flutter.embedding.android.SplashScreenDrawable"
                android:resource="@drawable/launch_background" />
            <meta-data
                android:name="com.google.firebase.messaging.default_notification_channel_id"
                android:value="swie_ink_high_importance_channel" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_api_key" />
    </application>
</manifest>

Thanks in advance.

0 Answers
Related