Repository: flutter/flutter
File: packages/flutter_tools/test/integration.shard/gradle_jni_packaging_test.dart (Dart)

Code before:
  });

  // Tests the behavior of abiFilters during the build process.
  // Without abiFilters set, third-party x86 libraries would be packaged into the resulting APK/bundle.
  // This would force Google Play to add x86 ABI to the list of supported ABIs, leading to crashes on x86 devices.
  testWithoutContext('3rd-party x86 library is not packaged (default settings)', () async {
    final Directory projectDir = createProjectWithThirdpartyLib(tempDir);
    processManager.runSync(<String>[flutterBin, 'build', 'apk'], workingDirectory: projectDir.path);

    // Verify that the library is valid and picked up by Gradle during transform tasks.
    // Note: Gradle transforms and merges all available native libraries by default;
    // abiFilters are not applied at this stage.
    expect(
      projectDir
          .childDirectory(
            'build/app/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib/x86',
          )
          .childFile('libflutter.so'),
      exists,
    );

    // Verify that libflutter.so is not packaged in the APK for x86 architecture.
    expect(_checkLibIsInApk(projectDir, 'lib/x86/libflutter.so'), false);
  });

  testWithoutContext('abiFilters provided by the user in buildTypes can be overridden', () async {
    final Directory projectDir = createProjectWithThirdpartyLib(tempDir);
    final String buildGradleContents = projectDir
        .childFile('android/app/build.gradle.kts')
        .readAsStringSync();

    // Modify the project's build.gradle.kts file to include abiFilters for a single ABI only.
    final String updatedBuildGradleContents = buildGradleContents.replaceFirstMapped(
      RegExp(r'(buildTypes\s*\{\s*release\s*\{)([^}]*)\}', dotAll: true),
      (Match match) {
        final String before = match.group(1)!;
        final String body = match.group(2)!;
        const ndkBlock = '''
                ndk {
                    abiFilters.clear()
                    abiFilters.addAll(listOf("arm64-v8a"))
                }
    ''';
        return '$before$body$ndkBlock        }';
      },
    );
    projectDir
        .childFile('android/app/build.gradle.kts')
        .writeAsStringSync(updatedBuildGradleContents);

    processManager.runSync(<String>[

Review comment (suggestion):
nit: the test name confuses me. It reads as though the user-provided abilFilters is the thing being overriden when the thing being overriden is actually the default Flutter abi filters.

```suggestion
  testWithoutContext('abiFilters provided by the user in buildTypes can override Flutter defaults', () async {
```

Code after:
  });

  // Tests the behavior of abiFilters during the build process.
  // Without abiFilters set, third-party x86 libraries would be packaged into the resulting APK/bundle.
  // This would force Google Play to add x86 ABI to the list of supported ABIs, leading to crashes on x86 devices.
  testWithoutContext('3rd-party x86 library is not packaged (default settings)', () async {
    final Directory projectDir = createProjectWithThirdpartyLib(tempDir);
    processManager.runSync(<String>[flutterBin, 'build', 'apk'], workingDirectory: projectDir.path);

    // Verify that the library is valid and picked up by Gradle during transform tasks.
    // Note: Gradle transforms and merges all available native libraries by default;
    // abiFilters are not applied at this stage.
    expect(
      projectDir
          .childDirectory(
            'build/app/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib/x86',
          )
          .childFile('libflutter.so'),
      exists,
    );
    // Verify that libflutter.so is packaged in the APK for Flutter supported architectures.
    expect(_checkLibIsInApk(projectDir, 'lib/arm64-v8a/libflutter.so'), true);
    expect(_checkLibIsInApk(projectDir, 'lib/x86_64/libflutter.so'), true);
    expect(_checkLibIsInApk(projectDir, 'lib/armeabi-v7a/libflutter.so'), true);
    // Verify that libflutter.so is not packaged in the APK for x86 architecture.
    expect(_checkLibIsInApk(projectDir, 'lib/x86/libflutter.so'), false);
  });

  testWithoutContext(
    'abiFilters provided by the user in buildTypes can override Flutter defaults',
    () async {
      final Directory projectDir = createProjectWithThirdpartyLib(tempDir);
      final String buildGradleContents = projectDir
          .childFile('android/app/build.gradle.kts')
          .readAsStringSync();

      // Modify the project's build.gradle.kts file to include abiFilters for a single ABI only.
      final String updatedBuildGradleContents = buildGradleContents.replaceFirstMapped(
        RegExp(r'(buildTypes\s*\{\s*release\s*\{)([^}]*)\}', dotAll: true),
        (Match match) {
          final String before = match.group(1)!;
          final String body = match.group(2)!;
          const ndkBlock = '''
                ndk {
                    abiFilters.clear()
                    abiFilters.addAll(listOf("arm64-v8a"))
                }
    ''';
          return '$before$body$ndkBlock        }';
        },
      );