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
This commit is contained in:
@@ -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
|
||||
@@ -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 ->
|
||||
@@ -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)
|
||||
|
||||
@@ -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, '');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user