Unverified Commit 2299ec78 authored by Gustl22's avatar Gustl22 Committed by GitHub

Set default flutter source directory for gradle builds (#142934)

See [#142498](https://github.com/flutter/flutter/pull/142498#discussion_r1478602032)
See this discussion: https://discord.com/channels/608014603317936148/1186378330178601000
parent 4b0abc77
...@@ -67,7 +67,7 @@ class FlutterExtension { ...@@ -67,7 +67,7 @@ class FlutterExtension {
* Specifies the relative directory to the Flutter project directory. * 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. * 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. */ /** Allows to override the target file. Otherwise, the target is lib/main.dart. */
String target String target
...@@ -834,7 +834,7 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -834,7 +834,7 @@ class FlutterPlugin implements Plugin<Project> {
} }
private Properties getPluginList() { 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 allPlugins = readPropertiesIfExist(pluginsFile)
Properties androidPlugins = new Properties() Properties androidPlugins = new Properties()
allPlugins.each { name, path -> allPlugins.each { name, path ->
...@@ -871,7 +871,7 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -871,7 +871,7 @@ class FlutterPlugin implements Plugin<Project> {
// This means, `plugin-a` depends on `plugin-b` and `plugin-c`. // This means, `plugin-a` depends on `plugin-b` and `plugin-c`.
// `plugin-b` depends on `plugin-c`. // `plugin-b` depends on `plugin-c`.
// `plugin-c` doesn't depend on anything. // `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()) { if (pluginsDependencyFile.exists()) {
def object = new JsonSlurper().parseText(pluginsDependencyFile.text) def object = new JsonSlurper().parseText(pluginsDependencyFile.text)
assert(object instanceof Map) assert(object instanceof Map)
......
// 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, '');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment