Skip to content

Implement version code overrides for split ABIs#187742

Open
derdilla wants to merge 3 commits into
flutter:masterfrom
derdilla:49544-allow-overriding-versioncode
Open

Implement version code overrides for split ABIs#187742
derdilla wants to merge 3 commits into
flutter:masterfrom
derdilla:49544-allow-overriding-versioncode

Conversation

@derdilla

@derdilla derdilla commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

closes #49544 by implementing a flag to force the flutter plugin to not run override the version code for split APIs.

More or less follows what #177753 did. The design should be sufficient to hook into custom build systems and doesn't do anything else.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions Bot added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. team-android Owned by Android platform team labels Jun 9, 2026
@derdilla derdilla marked this pull request as ready for review June 9, 2026 18:40
@derdilla derdilla requested a review from a team as a code owner June 9, 2026 18:40
@derdilla derdilla requested review from camsim99 and removed request for a team June 9, 2026 18:40
@derdilla derdilla marked this pull request as draft June 9, 2026 18:40

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Gradle property, force-version-code-ignoring-abi, allowing developers to bypass ABI-specific version code overrides during Flutter builds. Feedback on the changes highlights several critical issues in the integration tests, including a missing comma leading to implicit string concatenation, a misplaced closing brace that prematurely terminates the main function, and an incorrect aapt command for extracting the APK version code. Additionally, a relative import should be replaced with a package import to adhere to the style guide.

Comment thread packages/flutter_tools/test/integration.shard/gradle_jni_packaging_test.dart Outdated
Comment thread packages/flutter_tools/test/integration.shard/gradle_jni_packaging_test.dart Outdated
Comment thread packages/flutter_tools/test/integration.shard/gradle_jni_packaging_test.dart Outdated
@derdilla derdilla marked this pull request as ready for review June 9, 2026 19:48

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Gradle property force-version-code-ignoring-abi to allow forcing the version code while ignoring the ABI split during Flutter builds, and adds an integration test to verify this behavior. Feedback on the integration test points out compatibility issues on Windows environments, such as incorrect path escaping, carriage return handling, missing directory checks, and the wrong executable name for aapt.

Comment on lines +331 to +352
final String fileContent = localPropertiesFile.readAsStringSync();
final regex = RegExp(r'sdk\.dir=(.+)');
final Match? match = regex.firstMatch(fileContent);
final String sdkPath = match?.group(1) ?? '';

if (sdkPath.isEmpty) {
throw StateError('SDK path not found in local.properties');
}

final FileSystemEntity? toolsDir = fileSystem
.directory(sdkPath)
.childDirectory('build-tools')
.listSync()
.firstWhereOrNull((FileSystemEntity entry) =>
entry.statSync().type == FileSystemEntityType.directory);
if (toolsDir == null) {
throw StateError('No build-tools directory found');
}
final String aapt = fileSystem
.directory(toolsDir)
.childFile(Platform.isWindows ? 'aapt.bat' : 'aapt')
.path;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are several issues here that will cause this integration test to fail on Windows environments:

  1. Windows Path Escaping: In local.properties, paths are stored with escaped backslashes and colons (e.g., C\:\\Android\\Sdk). Reading this raw string directly will result in an invalid path when passed to fileSystem.directory.
  2. Carriage Returns (\r): On Windows, lines end with \r\n. The regex (.+) will capture the trailing \r, making the directory path invalid.
  3. Missing Directory Check: Calling listSync() on build-tools without checking if the directory exists first will throw a FileSystemException if the SDK path is incorrect or incomplete.
  4. Incorrect Executable Name: On Windows, the aapt executable is named aapt.exe, not aapt.bat.

Let's update this block to robustly handle Windows paths, trim carriage returns, check directory existence, and use the correct executable extension.

  final String fileContent = localPropertiesFile.readAsStringSync();
  final RegExp regex = RegExp(r'sdk\.dir=(.+)');
  final Match? match = regex.firstMatch(fileContent);
  if (match == null) {
    throw StateError('sdk.dir not found in local.properties');
  }
  final String sdkPath = match.group(1)!
      .trim()
      .replaceAll(r'\:', ':')
      .replaceAll(r'\\', r'\');

  if (sdkPath.isEmpty) {
    throw StateError('SDK path is empty in local.properties');
  }

  final Directory buildToolsDir = fileSystem.directory(sdkPath).childDirectory('build-tools');
  if (!buildToolsDir.existsSync()) {
    throw StateError('build-tools directory not found at ${buildToolsDir.path}');
  }

  final FileSystemEntity? toolsDir = buildToolsDir
      .listSync()
      .firstWhereOrNull((FileSystemEntity entry) =>
          entry.statSync().type == FileSystemEntityType.directory);
  if (toolsDir == null) {
    throw StateError('No build-tools directory found');
  }
  final String aapt = fileSystem
      .directory(toolsDir)
      .childFile(Platform.isWindows ? 'aapt.exe' : 'aapt')
      .path;

@derdilla

derdilla commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

I still get a test failure. Not sure whether that is a wrong local setup (using wrong flutter), or a bug. I guess running in CI is easiest to check that.

@camsim99 camsim99 added the CICD Run CI/CD label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD platform-android Android applications specifically team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flutter version code is different from version code in google play console

2 participants