Skip to content

Commit

Permalink
Set default flutter source directory for gradle builds (flutter#142934)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Feb 8, 2024
1 parent 4b0abc7 commit 2299ec7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/flutter_tools/gradle/src/main/groovy/flutter.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FlutterExtension {
* Specifies the relative directory to the Flutter project directory.
* In an app project, this is ../.. since the app's Gradle build file is under android/app.
*/
String source
String source = "../.."

/** Allows to override the target file. Otherwise, the target is lib/main.dart. */
String target
Expand Down Expand Up @@ -834,7 +834,7 @@ class FlutterPlugin implements Plugin<Project> {
}

private Properties getPluginList() {
File pluginsFile = new File(project.projectDir.parentFile.parentFile, '.flutter-plugins')
File pluginsFile = new File(getFlutterSourceDirectory(), '.flutter-plugins')
Properties allPlugins = readPropertiesIfExist(pluginsFile)
Properties androidPlugins = new Properties()
allPlugins.each { name, path ->
Expand Down Expand Up @@ -871,7 +871,7 @@ class FlutterPlugin implements Plugin<Project> {
// This means, `plugin-a` depends on `plugin-b` and `plugin-c`.
// `plugin-b` depends on `plugin-c`.
// `plugin-c` doesn't depend on anything.
File pluginsDependencyFile = new File(project.projectDir.parentFile.parentFile, '.flutter-plugins-dependencies')
File pluginsDependencyFile = new File(getFlutterSourceDirectory(), '.flutter-plugins-dependencies')
if (pluginsDependencyFile.exists()) {
def object = new JsonSlurper().parseText(pluginsDependencyFile.text)
assert(object instanceof Map)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/cache.dart';

import '../src/common.dart';
import 'test_data/deferred_components_project.dart';
import 'test_data/project.dart';
import 'test_utils.dart';

void main() {
late Directory tempDir;

setUp(() {
Cache.flutterRoot = getFlutterRoot();
tempDir =
createResolvedTempDirectorySync('flutter_gradle_source_path_test.');
});

tearDown(() async {
tryToDelete(tempDir);
});

test('gradle task builds without setting a source path in app/build.gradle',
() async {
final Project project = DeferredComponentsProject(
MissingFlutterSourcePathDeferredComponentsConfig(),
);
final String flutterBin = fileSystem.path.join(
getFlutterRoot(),
'bin',
'flutter',
);

final Directory exampleAppDir = tempDir.childDirectory('example');
await project.setUpIn(exampleAppDir);

// Run flutter build apk to build example project.
final ProcessResult buildApkResult = processManager.runSync(<String>[
flutterBin,
...getLocalEngineArguments(),
'build',
'apk',
'--debug',
], workingDirectory: exampleAppDir.path);

expect(buildApkResult, const ProcessResultMatcher());
});
}

class MissingFlutterSourcePathDeferredComponentsConfig
extends BasicDeferredComponentsConfig {
final String _flutterSourcePath = '''
flutter {
source '../..'
}
''';

@override
String get appBuild {
if (!super.appBuild.contains(_flutterSourcePath)) {
throw Exception(
'Flutter source path not found in original configuration!');
}
return super.appBuild.replaceAll(_flutterSourcePath, '');
}
}

0 comments on commit 2299ec7

Please sign in to comment.