mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
`android_obfuscate_test` is currently being schedule to run on a limited devicelab physical phone bot. However, it's only checking if `--obfuscate` works, not running anything on the device, so can move into the tools test integration shard. https://ci.chromium.org/ui/p/flutter/builders/prod/Linux_pixel_7pro%20android_obfuscate_test/7722/overview The test only takes < 2 minutes, spinning up an entire build for it, especially on a devicelab bot, is wasteful. Similar to https://github.com/flutter/flutter/pull/80161 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
119 lines
3.2 KiB
Dart
119 lines
3.2 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:convert';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:archive/archive.dart';
|
|
import 'package:file_testing/file_testing.dart';
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
|
|
|
import '../src/common.dart';
|
|
import 'test_utils.dart';
|
|
|
|
void main() {
|
|
late Directory tempDir;
|
|
|
|
setUp(() async {
|
|
tempDir = fileSystem.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
|
|
});
|
|
|
|
tearDown(() {
|
|
tryToDelete(tempDir);
|
|
});
|
|
|
|
test('Dart identifiers are obfuscated with build apk --obfuscate', () async {
|
|
const projectName = 'hello_world';
|
|
await processManager.run(<String>[
|
|
flutterBin,
|
|
'create',
|
|
projectName,
|
|
], workingDirectory: tempDir.path);
|
|
final String projectPath = tempDir.childDirectory(projectName).path;
|
|
|
|
await processManager.run(<String>[
|
|
flutterBin,
|
|
'build',
|
|
'apk',
|
|
'--target-platform=android-arm',
|
|
'--obfuscate',
|
|
'--split-debug-info=foo/',
|
|
'--ci',
|
|
], workingDirectory: projectPath);
|
|
|
|
final File outputApkDirectory = fileSystem.file(
|
|
fileSystem.path.join(
|
|
projectPath,
|
|
'build',
|
|
'app',
|
|
'outputs',
|
|
'apk',
|
|
'release',
|
|
'app-release.apk',
|
|
),
|
|
);
|
|
|
|
expect(outputApkDirectory, exists);
|
|
// Expect "hello_world" is not present in the compiled output.
|
|
// This fails without the --obfuscate flag.
|
|
expect(_containsSymbol(outputApkDirectory, 'lib/armeabi-v7a/libapp.so', projectName), false);
|
|
});
|
|
|
|
test('Dart identifiers are obfuscated with build aar --obfuscate', () async {
|
|
const moduleName = 'hello_module';
|
|
await processManager.run(<String>[
|
|
flutterBin,
|
|
'create',
|
|
'-t',
|
|
'module',
|
|
moduleName,
|
|
'--ci',
|
|
], workingDirectory: tempDir.path);
|
|
final String projectPath = tempDir.childDirectory(moduleName).path;
|
|
|
|
await processManager.run(<String>[
|
|
flutterBin,
|
|
'build',
|
|
'aar',
|
|
'--target-platform=android-arm',
|
|
'--obfuscate',
|
|
'--split-debug-info=foo/',
|
|
'--no-debug',
|
|
'--no-profile',
|
|
], workingDirectory: projectPath);
|
|
|
|
final File outputAarDirectory = fileSystem.file(
|
|
fileSystem.path.join(
|
|
projectPath,
|
|
'build',
|
|
'host',
|
|
'outputs',
|
|
'repo',
|
|
'com',
|
|
'example',
|
|
moduleName,
|
|
'flutter_release',
|
|
'1.0',
|
|
'flutter_release-1.0.aar',
|
|
),
|
|
);
|
|
|
|
expect(outputAarDirectory, exists);
|
|
// Expect "hello_module" is not present in the compiled output.
|
|
// This fails without the --obfuscate flag.
|
|
expect(_containsSymbol(outputAarDirectory, 'jni/armeabi-v7a/libapp.so', moduleName), false);
|
|
});
|
|
}
|
|
|
|
bool _containsSymbol(File outputArchive, String libappPath, String symbol) {
|
|
final Archive archive = ZipDecoder().decodeBytes(outputArchive.readAsBytesSync());
|
|
final ArchiveFile? libapp = archive.findFile(libappPath);
|
|
expect(libapp, isNotNull);
|
|
|
|
final libappBytes = libapp!.content as Uint8List;
|
|
final String libappStrings = utf8.decode(libappBytes, allowMalformed: true);
|
|
|
|
return libappStrings.contains(symbol);
|
|
}
|