Add split-debug and obfuscation to build aar (#56342)
This commit is contained in:
@@ -12,7 +12,7 @@ import 'package:path/path.dart' as path;
|
||||
Future<void> main() async {
|
||||
await task(() async {
|
||||
try {
|
||||
bool foundProjectName = false;
|
||||
bool foundApkProjectName = false;
|
||||
await runProjectTest((FlutterProject flutterProject) async {
|
||||
section('APK content for task assembleRelease with --obfuscate');
|
||||
await inDirectory(flutterProject.rootPath, () async {
|
||||
@@ -21,13 +21,14 @@ Future<void> main() async {
|
||||
'--target-platform=android-arm',
|
||||
'--obfuscate',
|
||||
'--split-debug-info=foo/',
|
||||
'--verbose',
|
||||
]);
|
||||
});
|
||||
final String outputDirectory = path.join(
|
||||
final String outputApkDirectory = path.join(
|
||||
flutterProject.rootPath,
|
||||
'build/app/outputs/apk/release/app-release.apk',
|
||||
);
|
||||
final Iterable<String> apkFiles = await getFilesInApk(outputDirectory);
|
||||
final Iterable<String> apkFiles = await getFilesInApk(outputApkDirectory);
|
||||
|
||||
checkCollectionContains<String>(<String>[
|
||||
...flutterAssets,
|
||||
@@ -38,20 +39,69 @@ Future<void> main() async {
|
||||
// Verify that an identifier from the Dart project code is not present
|
||||
// in the compiled binary.
|
||||
await inDirectory(flutterProject.rootPath, () async {
|
||||
await exec('unzip', <String>[outputDirectory]);
|
||||
await exec('unzip', <String>[outputApkDirectory]);
|
||||
checkFileExists(path.join(flutterProject.rootPath, 'lib/armeabi-v7a/libapp.so'));
|
||||
final String response = await eval(
|
||||
'grep',
|
||||
<String>[flutterProject.name, 'lib/armeabi-v7a/libapp.so'],
|
||||
canFail: true,
|
||||
);
|
||||
if (response.trim().contains('matches')) {
|
||||
foundProjectName = true;
|
||||
foundApkProjectName = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
if (foundProjectName) {
|
||||
return TaskResult.failure('Found project name in obfuscated dart library');
|
||||
|
||||
bool foundAarProjectName = false;
|
||||
await runModuleProjectTest((FlutterModuleProject flutterProject) async {
|
||||
section('AAR content with --obfuscate');
|
||||
|
||||
await inDirectory(flutterProject.rootPath, () async {
|
||||
await flutter('build', options: <String>[
|
||||
'aar',
|
||||
'--target-platform=android-arm',
|
||||
'--obfuscate',
|
||||
'--split-debug-info=foo/',
|
||||
'--no-debug',
|
||||
'--no-profile',
|
||||
'--verbose',
|
||||
]);
|
||||
});
|
||||
|
||||
final String outputAarDirectory = path.join(
|
||||
flutterProject.rootPath,
|
||||
'build/host/outputs/repo/com/example/${flutterProject.name}/flutter_release/1.0/flutter_release-1.0.aar',
|
||||
);
|
||||
final Iterable<String> aarFiles = await getFilesInAar(outputAarDirectory);
|
||||
|
||||
checkCollectionContains<String>(<String>[
|
||||
...flutterAssets,
|
||||
'jni/armeabi-v7a/libapp.so',
|
||||
], aarFiles);
|
||||
|
||||
// Verify that an identifier from the Dart project code is not present
|
||||
// in the compiled binary.
|
||||
await inDirectory(flutterProject.rootPath, () async {
|
||||
await exec('unzip', <String>[outputAarDirectory]);
|
||||
checkFileExists(path.join(flutterProject.rootPath, 'jni/armeabi-v7a/libapp.so'));
|
||||
final String response = await eval(
|
||||
'grep',
|
||||
<String>[flutterProject.name, 'jni/armeabi-v7a/libapp.so'],
|
||||
canFail: true,
|
||||
);
|
||||
if (response.trim().contains('matches')) {
|
||||
foundAarProjectName = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (foundApkProjectName) {
|
||||
return TaskResult.failure('Found project name in obfuscated APK dart library');
|
||||
}
|
||||
if (foundAarProjectName) {
|
||||
return TaskResult.failure('Found project name in obfuscated AAR dart library');
|
||||
}
|
||||
|
||||
return TaskResult.success(null);
|
||||
} on TaskResult catch (taskResult) {
|
||||
return taskResult;
|
||||
|
||||
@@ -51,6 +51,18 @@ Future<void> runPluginProjectTest(Future<void> testFunction(FlutterPluginProject
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs the given [testFunction] on a freshly generated Flutter module project.
|
||||
Future<void> runModuleProjectTest(Future<void> testFunction(FlutterModuleProject moduleProject)) async {
|
||||
final Directory tempDir = Directory.systemTemp.createTempSync('flutter_devicelab_gradle_module_test.');
|
||||
final FlutterModuleProject moduleProject = await FlutterModuleProject.create(tempDir, 'hello_module');
|
||||
|
||||
try {
|
||||
await testFunction(moduleProject);
|
||||
} finally {
|
||||
rmTree(tempDir);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the list of files inside an Android Package Kit.
|
||||
Future<Iterable<String>> getFilesInApk(String apk) async {
|
||||
if (!File(apk).existsSync()) {
|
||||
@@ -357,6 +369,22 @@ class FlutterPluginProject {
|
||||
}
|
||||
}
|
||||
|
||||
class FlutterModuleProject {
|
||||
FlutterModuleProject(this.parent, this.name);
|
||||
|
||||
final Directory parent;
|
||||
final String name;
|
||||
|
||||
static Future<FlutterModuleProject> create(Directory directory, String name) async {
|
||||
await inDirectory(directory, () async {
|
||||
await flutter('create', options: <String>['--template=module', name]);
|
||||
});
|
||||
return FlutterModuleProject(directory, name);
|
||||
}
|
||||
|
||||
String get rootPath => path.join(parent.path, name);
|
||||
}
|
||||
|
||||
Future<void> _runGradleTask({String workingDirectory, String task, List<String> options}) async {
|
||||
final ProcessResult result = await _resultOfGradleTask(
|
||||
workingDirectory: workingDirectory,
|
||||
|
||||
Reference in New Issue
Block a user