diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b251e96e0bfbecc6ecdda8f453a39c4ae7c913c0..e62c523e64d03cf5eaa54c2e2f435e65faa133a8 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -36,7 +36,7 @@ version:
   stage: "test"
   script:
     - "export VERSION_NAME=$(git describe --abbrev=0 --tags HEAD)"
-    - "export VERSION_CODE=$(git rev-list --count $VERSION_NAME)"
+    - "export VERSION_CODE=$(git rev-list --count $VERSION_NAME --tags)"
     - "echo \"{\\\"name\\\":\\\"$VERSION_NAME\\\",\\\"code\\\":$VERSION_CODE}\" > version.json"
   artifacts:
     paths:
diff --git a/gradle/convention/src/main/kotlin/AndroidApplicationConvention.kt b/gradle/convention/src/main/kotlin/AndroidApplicationConvention.kt
index 034284bbcf259647b10689356c9462b430732ad9..19d57b8398500b555130e29e3b01d0efe7b2a948 100644
--- a/gradle/convention/src/main/kotlin/AndroidApplicationConvention.kt
+++ b/gradle/convention/src/main/kotlin/AndroidApplicationConvention.kt
@@ -27,7 +27,7 @@ class AndroidApplicationConvention : Plugin<Project> {
           val commit = git("rev-parse", "HEAD")
           val name = git("describe", "--always", "--tags", "HEAD")
 
-          versionCode = git("rev-list", "--count", "HEAD")?.toIntOrNull()
+          versionCode = git("rev-list", "--count", "HEAD", "--tags")?.toIntOrNull()
           versionName = git("describe", "--always", "--tags", "HEAD")
 
           val fancyVersionName = if (commit == null || name == null) name