| 
 | 1 | +// Copyright 2014 The Flutter Authors. All rights reserved.  | 
 | 2 | +// Use of this source code is governed by a BSD-style license that can be  | 
 | 3 | +// found in the LICENSE file.  | 
 | 4 | + | 
 | 5 | +import 'package:flutter_tools/src/base/file_system.dart';  | 
 | 6 | +import 'package:flutter_tools/src/base/io.dart';  | 
 | 7 | + | 
 | 8 | +import '../src/common.dart';  | 
 | 9 | +import 'test_utils.dart';  | 
 | 10 | + | 
 | 11 | +void main() {  | 
 | 12 | +  late Directory tempDir;  | 
 | 13 | +  late String flutterBin;  | 
 | 14 | +  late Directory exampleAppDir;  | 
 | 15 | + | 
 | 16 | +  setUp(() async {  | 
 | 17 | +    tempDir = createResolvedTempDirectorySync('flutter_plugin_test.');  | 
 | 18 | +    flutterBin = fileSystem.path.join(  | 
 | 19 | +      getFlutterRoot(),  | 
 | 20 | +      'bin',  | 
 | 21 | +      'flutter',  | 
 | 22 | +    );  | 
 | 23 | +    exampleAppDir = tempDir.childDirectory('aaa').childDirectory('example');  | 
 | 24 | + | 
 | 25 | +    processManager.runSync(<String>[  | 
 | 26 | +      flutterBin,  | 
 | 27 | +      ...getLocalEngineArguments(),  | 
 | 28 | +      'create',  | 
 | 29 | +      '--template=plugin',  | 
 | 30 | +      '--platforms=android',  | 
 | 31 | +      'aaa',  | 
 | 32 | +    ], workingDirectory: tempDir.path);  | 
 | 33 | +  });  | 
 | 34 | + | 
 | 35 | +  tearDown(() async {  | 
 | 36 | +    tryToDelete(tempDir);  | 
 | 37 | +  });  | 
 | 38 | + | 
 | 39 | +  test(  | 
 | 40 | +    'build succeeds targeting string compileSdkVersion',  | 
 | 41 | +    () async {  | 
 | 42 | +      final File buildGradleFile = exampleAppDir.childDirectory('android').childDirectory('app').childFile('build.gradle');  | 
 | 43 | +      // write a build.gradle with compileSdkVersion as `android-Tiramisu` which is a string preview version  | 
 | 44 | +      buildGradleFile.writeAsStringSync(  | 
 | 45 | +        buildGradleFile.readAsStringSync().replaceFirst('compileSdkVersion flutter.compileSdkVersion', 'compileSdkVersion "android-Tiramisu"'),  | 
 | 46 | +        flush: true  | 
 | 47 | +      );  | 
 | 48 | +      expect(buildGradleFile.readAsStringSync(), contains('compileSdkVersion "android-Tiramisu"'));  | 
 | 49 | + | 
 | 50 | +      final ProcessResult result = await processManager.run(<String>[  | 
 | 51 | +        flutterBin,  | 
 | 52 | +        ...getLocalEngineArguments(),  | 
 | 53 | +        'build',  | 
 | 54 | +        'apk',  | 
 | 55 | +        '--debug',  | 
 | 56 | +      ], workingDirectory: exampleAppDir.path);  | 
 | 57 | +      expect(result.stdout, contains('Built build/app/outputs/flutter-apk/app-debug.apk.'));  | 
 | 58 | +      expect(exampleAppDir.childDirectory('build')  | 
 | 59 | +        .childDirectory('app')  | 
 | 60 | +        .childDirectory('outputs')  | 
 | 61 | +        .childDirectory('apk')  | 
 | 62 | +        .childDirectory('debug')  | 
 | 63 | +        .childFile('app-debug.apk').existsSync(), true);  | 
 | 64 | +    },  | 
 | 65 | +  );  | 
 | 66 | + | 
 | 67 | +  test(  | 
 | 68 | +    'build succeeds targeting string compileSdkPreview',  | 
 | 69 | +    () async {  | 
 | 70 | +      final File buildGradleFile = exampleAppDir.childDirectory('android').childDirectory('app').childFile('build.gradle');  | 
 | 71 | +      // write a build.gradle with compileSdkPreview as `Tiramisu` which is a string preview version  | 
 | 72 | +      buildGradleFile.writeAsStringSync(  | 
 | 73 | +        buildGradleFile.readAsStringSync().replaceFirst('compileSdkVersion flutter.compileSdkVersion', 'compileSdkPreview "Tiramisu"'),  | 
 | 74 | +        flush: true  | 
 | 75 | +      );  | 
 | 76 | +      expect(buildGradleFile.readAsStringSync(), contains('compileSdkPreview "Tiramisu"'));  | 
 | 77 | + | 
 | 78 | +      final ProcessResult result = await processManager.run(<String>[  | 
 | 79 | +        flutterBin,  | 
 | 80 | +        ...getLocalEngineArguments(),  | 
 | 81 | +        'build',  | 
 | 82 | +        'apk',  | 
 | 83 | +        '--debug',  | 
 | 84 | +      ], workingDirectory: exampleAppDir.path);  | 
 | 85 | +      expect(result.stdout, contains('Built build/app/outputs/flutter-apk/app-debug.apk.'));  | 
 | 86 | +      expect(exampleAppDir.childDirectory('build')  | 
 | 87 | +        .childDirectory('app')  | 
 | 88 | +        .childDirectory('outputs')  | 
 | 89 | +        .childDirectory('apk')  | 
 | 90 | +        .childDirectory('debug')  | 
 | 91 | +        .childFile('app-debug.apk').existsSync(), true);  | 
 | 92 | +    },  | 
 | 93 | +  );  | 
 | 94 | +}  | 
0 commit comments