mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Remove support for imperative apply of Flutter Gradle Plugin (#160947)
imperative apply has been deprecated since #139690 part of #121541 Doing this will make things easier for us during the conversion of `flutter.groovy` into Kotlin.
This commit is contained in:
parent
a3a4995607
commit
4b23b81828
@ -1,15 +0,0 @@
|
||||
// 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.
|
||||
|
||||
include ':app', ':component1'
|
||||
|
||||
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
|
||||
def properties = new Properties()
|
||||
|
||||
assert localPropertiesFile.exists()
|
||||
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
|
||||
|
||||
def flutterSdkPath = properties.getProperty("flutter.sdk")
|
||||
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
|
||||
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
|
@ -0,0 +1,30 @@
|
||||
// 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.
|
||||
|
||||
pluginManagement {
|
||||
val flutterSdkPath =
|
||||
run {
|
||||
val properties = java.util.Properties()
|
||||
file("local.properties").inputStream().use { properties.load(it) }
|
||||
val flutterSdkPath = properties.getProperty("flutter.sdk")
|
||||
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
|
||||
flutterSdkPath
|
||||
}
|
||||
|
||||
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
|
||||
id("com.android.application") version "8.7.0" apply false
|
||||
id("org.jetbrains.kotlin.android") version "1.8.10" apply false
|
||||
}
|
||||
|
||||
include(":app", ":component1")
|
@ -2,14 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// This file exists solely for the compatibility with projects that have
|
||||
// This file existed solely for the compatibility with apps that have
|
||||
// not migrated to the declarative apply of the Flutter App Plugin Loader Gradle Plugin.
|
||||
// The old (imperative) apply of this plugin is not possible anymore.
|
||||
|
||||
logger.error("You are applying Flutter's app_plugin_loader Gradle plugin \
|
||||
imperatively using the apply script method, which is deprecated and will be \
|
||||
removed in a future release. Migrate to applying Gradle plugins with the \
|
||||
declarative plugins block: https://flutter.dev/to/flutter-gradle-plugin-apply\n\
|
||||
throw new GradleException("You are applying Flutter's app_plugin_loader Gradle plugin \
|
||||
imperatively using the apply script method, which is not possible anymore. \
|
||||
Migrate to applying Gradle plugins with the declarative plugins block: \
|
||||
https://flutter.dev/to/flutter-gradle-plugin-apply\n\
|
||||
")
|
||||
|
||||
def pathToThisDirectory = buildscript.sourceFile.parentFile
|
||||
apply from: "$pathToThisDirectory/src/main/groovy/app_plugin_loader.groovy"
|
||||
|
@ -28,7 +28,6 @@ gradlePlugin {
|
||||
dependencies {
|
||||
// When bumping, also update:
|
||||
// * ndkVersion in FlutterExtension in packages/flutter_tools/gradle/src/main/groovy/flutter.groovy
|
||||
// * AGP version in the buildscript block in packages/flutter_tools/gradle/src/main/groovy/flutter.groovy
|
||||
// * AGP version in the buildscript block in packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts
|
||||
// * AGP version constants in packages/flutter_tools/lib/src/android/gradle_utils.dart
|
||||
compileOnly("com.android.tools.build:gradle:7.3.0")
|
||||
|
@ -2,13 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// This file exists solely for the compatibility with projects that have
|
||||
// This file existed solely for the compatibility with apps that have
|
||||
// not migrated to the declarative apply of the Flutter Gradle Plugin.
|
||||
// The old (imperative) apply of this plugin is not possible anymore.
|
||||
|
||||
logger.error("You are applying Flutter's main Gradle plugin imperatively using \
|
||||
the apply script method, which is deprecated and will be removed in a future \
|
||||
release. Migrate to applying Gradle plugins with the declarative plugins \
|
||||
block: https://flutter.dev/to/flutter-gradle-plugin-apply\n")
|
||||
|
||||
def pathToThisDirectory = buildscript.sourceFile.parentFile
|
||||
apply from: "$pathToThisDirectory/src/main/groovy/flutter.groovy"
|
||||
throw new GradleException("You are applying Flutter's main Gradle plugin imperatively using \
|
||||
the apply script method, which is not possible anymore. \
|
||||
Migrate to applying Gradle plugins with the declarative plugins block: \
|
||||
https://flutter.dev/to/flutter-gradle-plugin-apply\n\
|
||||
")
|
||||
|
@ -102,40 +102,6 @@ class FlutterExtension {
|
||||
}
|
||||
}
|
||||
|
||||
// This buildscript block supplies dependencies for this file's own import
|
||||
// declarations above. It exists solely for compatibility with projects that
|
||||
// have not migrated to declaratively apply the Flutter Gradle Plugin;
|
||||
// for those that have, FGP's `build.gradle.kts` takes care of this.
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
// When bumping, also update:
|
||||
// * ndkVersion in FlutterExtension in packages/flutter_tools/gradle/src/main/groovy/flutter.groovy
|
||||
// * AGP version in the buildscript block in packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts
|
||||
// * AGP version constants in packages/flutter_tools/lib/src/android/gradle_utils.dart
|
||||
// * AGP version in dependencies block in packages/flutter_tools/gradle/build.gradle.kts
|
||||
classpath("com.android.tools.build:gradle:7.3.0")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Some apps don't set default compile options.
|
||||
* Apps can change these values in the app-level Gradle build file
|
||||
* (android/app/build.gradle or android/app/build.gradle.kts).
|
||||
* This just ensures that default values are set.
|
||||
*/
|
||||
android {
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: FlutterPlugin
|
||||
|
||||
class FlutterPlugin implements Plugin<Project> {
|
||||
|
||||
private static final String DEFAULT_MAVEN_HOST = "https://storage.googleapis.com"
|
||||
|
@ -1,200 +0,0 @@
|
||||
// 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 'dart:convert';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
void main() {
|
||||
late Directory tempDir;
|
||||
|
||||
setUp(() async {
|
||||
tempDir = createResolvedTempDirectorySync('run_test.');
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
tryToDelete(tempDir);
|
||||
});
|
||||
|
||||
testWithoutContext(
|
||||
'gradle prints warning when Flutter\'s Gradle plugins are applied using deprecated "apply plugin" way',
|
||||
() async {
|
||||
// Create a new flutter project.
|
||||
ProcessResult result = await processManager.run(<String>[
|
||||
flutterBin,
|
||||
'create',
|
||||
tempDir.path,
|
||||
'--project-name=testapp',
|
||||
], workingDirectory: tempDir.path);
|
||||
expect(result.exitCode, 0);
|
||||
// Ensure that gradle files exists from templates.
|
||||
result = await processManager.run(<String>[
|
||||
flutterBin,
|
||||
'build',
|
||||
'apk',
|
||||
'--config-only',
|
||||
], workingDirectory: tempDir.path);
|
||||
expect(result.exitCode, 0);
|
||||
|
||||
// Change build files to use deprecated "apply plugin:" way.
|
||||
// Contents are taken from https://github.com/flutter/flutter/issues/135392 (for Flutter 3.10)
|
||||
final File settings = tempDir.childDirectory('android').childFile('settings.gradle');
|
||||
final File buildGradle = tempDir.childDirectory('android').childFile('build.gradle');
|
||||
final File appBuildGradle = tempDir
|
||||
.childDirectory('android')
|
||||
.childDirectory('app')
|
||||
.childFile('build.gradle');
|
||||
settings.writeAsStringSync(r'''
|
||||
include ':app'
|
||||
|
||||
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
|
||||
def properties = new Properties()
|
||||
|
||||
assert localPropertiesFile.exists()
|
||||
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
|
||||
|
||||
def flutterSdkPath = properties.getProperty("flutter.sdk")
|
||||
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
|
||||
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
|
||||
''');
|
||||
buildGradle.writeAsStringSync(r'''
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.8.22'
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.1.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.layout.buildDirectory.value(rootProject.layout.buildDirectory.dir("../../build").get())
|
||||
subprojects {
|
||||
project.layout.buildDirectory.value(rootProject.layout.buildDirectory.dir(project.name).get())
|
||||
}
|
||||
subprojects {
|
||||
project.evaluationDependsOn(':app')
|
||||
}
|
||||
|
||||
tasks.register("clean", Delete) {
|
||||
delete rootProject.layout.buildDirectory
|
||||
}
|
||||
''');
|
||||
appBuildGradle.writeAsStringSync(r'''
|
||||
def localProperties = new Properties()
|
||||
def localPropertiesFile = rootProject.file('local.properties')
|
||||
if (localPropertiesFile.exists()) {
|
||||
localPropertiesFile.withReader('UTF-8') { reader ->
|
||||
localProperties.load(reader)
|
||||
}
|
||||
}
|
||||
|
||||
def flutterRoot = localProperties.getProperty('flutter.sdk')
|
||||
if (flutterRoot == null) {
|
||||
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
|
||||
}
|
||||
|
||||
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
|
||||
if (flutterVersionCode == null) {
|
||||
flutterVersionCode = '1'
|
||||
}
|
||||
|
||||
def flutterVersionName = localProperties.getProperty('flutter.versionName')
|
||||
if (flutterVersionName == null) {
|
||||
flutterVersionName = '1.0'
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
|
||||
|
||||
android {
|
||||
compileSdkVersion flutter.compileSdkVersion
|
||||
ndkVersion flutter.ndkVersion
|
||||
namespace "com.example.testapp"
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId "com.example.testapp"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
||||
minSdkVersion flutter.minSdkVersion
|
||||
targetSdkVersion flutter.targetSdkVersion
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig signingConfigs.debug
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flutter {
|
||||
source '../..'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
}
|
||||
''');
|
||||
|
||||
result = await processManager.run(<String>[
|
||||
flutterBin,
|
||||
'build',
|
||||
'apk',
|
||||
'--debug',
|
||||
], workingDirectory: tempDir.path);
|
||||
expect(result.exitCode, 0);
|
||||
// Verify that stderr output contains deprecation warnings.
|
||||
final List<String> actualLines = LineSplitter.split(result.stderr.toString()).toList();
|
||||
expect(
|
||||
actualLines.any(
|
||||
(String msg) =>
|
||||
msg.contains("You are applying Flutter's main Gradle plugin imperatively"),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
actualLines.any(
|
||||
(String msg) => msg.contains(
|
||||
"You are applying Flutter's app_plugin_loader Gradle plugin imperatively",
|
||||
),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
@ -1,260 +0,0 @@
|
||||
// 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 'dart:io';
|
||||
|
||||
import 'package:file_testing/file_testing.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import 'test_data/deferred_components_config.dart';
|
||||
import 'test_data/plugin_each_settings_gradle_project.dart';
|
||||
import 'test_data/plugin_project.dart';
|
||||
import 'test_data/project.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
void main() {
|
||||
late Directory tempDir;
|
||||
|
||||
setUp(() {
|
||||
Cache.flutterRoot = getFlutterRoot();
|
||||
tempDir = createResolvedTempDirectorySync('flutter_plugin_test.');
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
tryToDelete(tempDir);
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/97729 (#137115).
|
||||
/// Creates a project which uses a plugin, which is not supported on Android.
|
||||
/// This means it has no entry in pubspec.yaml for:
|
||||
/// flutter -> plugin -> platforms -> android
|
||||
///
|
||||
/// [createAndroidPluginFolder] indicates that the plugin can additionally
|
||||
/// have a functioning `android` folder.
|
||||
Future<ProcessResult> testUnsupportedPlugin({
|
||||
required Project project,
|
||||
required bool createAndroidPluginFolder,
|
||||
}) async {
|
||||
// Create dummy plugin that supports iOS and optionally Android.
|
||||
processManager.runSync(<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'create',
|
||||
'--template=plugin',
|
||||
'--platforms=ios${createAndroidPluginFolder ? ',android' : ''}',
|
||||
'test_plugin',
|
||||
], workingDirectory: tempDir.path);
|
||||
|
||||
final Directory pluginAppDir = tempDir.childDirectory('test_plugin');
|
||||
|
||||
final File pubspecFile = pluginAppDir.childFile('pubspec.yaml');
|
||||
String pubspecYamlSrc = pubspecFile.readAsStringSync().replaceAll('\r\n', '\n');
|
||||
if (createAndroidPluginFolder) {
|
||||
// Override pubspec to drop support for the Android implementation.
|
||||
pubspecYamlSrc = pubspecYamlSrc
|
||||
.replaceFirst(RegExp(r'name:.*\n'), 'name: test_plugin\n')
|
||||
.replaceFirst(
|
||||
'''
|
||||
android:
|
||||
package: com.example.test_plugin
|
||||
pluginClass: TestPlugin
|
||||
''',
|
||||
'''
|
||||
# android:
|
||||
# package: com.example.test_plugin
|
||||
# pluginClass: TestPlugin
|
||||
''',
|
||||
);
|
||||
|
||||
pubspecFile.writeAsStringSync(pubspecYamlSrc);
|
||||
|
||||
// Check the android directory and the build.gradle file within.
|
||||
final File pluginGradleFile = pluginAppDir
|
||||
.childDirectory('android')
|
||||
.childFile('build.gradle');
|
||||
expect(pluginGradleFile, exists);
|
||||
} else {
|
||||
expect(pubspecYamlSrc, isNot(contains('android:')));
|
||||
}
|
||||
|
||||
// Create a project which includes the plugin to test against
|
||||
final Directory pluginExampleAppDir = pluginAppDir.childDirectory('example');
|
||||
|
||||
await project.setUpIn(pluginExampleAppDir);
|
||||
|
||||
// Run flutter build apk to build plugin example project.
|
||||
return processManager.runSync(<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'build',
|
||||
'apk',
|
||||
'--debug',
|
||||
// TODO(bkonyi): remove once https://github.com/flutter/flutter/pull/158933 is resolved
|
||||
'--verbose',
|
||||
], workingDirectory: pluginExampleAppDir.path);
|
||||
}
|
||||
|
||||
test('skip plugin if it does not support the Android platform', () async {
|
||||
final Project project = PluginWithPathAndroidProject();
|
||||
final ProcessResult buildApkResult = await testUnsupportedPlugin(
|
||||
project: project,
|
||||
createAndroidPluginFolder: false,
|
||||
);
|
||||
expect(buildApkResult.stderr.toString(), isNot(contains('Please fix your settings.gradle')));
|
||||
expect(buildApkResult, const ProcessResultMatcher());
|
||||
}, skip: Platform.isWindows); // https://github.com/flutter/flutter/issues/157640
|
||||
|
||||
test(
|
||||
'skip plugin with android folder if it does not support the Android platform',
|
||||
() async {
|
||||
final Project project = PluginWithPathAndroidProjectWithoutDeferred();
|
||||
final ProcessResult buildApkResult = await testUnsupportedPlugin(
|
||||
project: project,
|
||||
createAndroidPluginFolder: true,
|
||||
);
|
||||
expect(buildApkResult.stderr.toString(), isNot(contains('Please fix your settings.gradle')));
|
||||
expect(buildApkResult, const ProcessResultMatcher());
|
||||
|
||||
// Regression check for https://github.com/flutter/flutter/issues/158962.
|
||||
{
|
||||
final Directory androidDir = project.dir.childDirectory('android');
|
||||
expect(
|
||||
androidDir.childFile('settings.gradle.kts'),
|
||||
exists,
|
||||
reason: 'Modern flutter create --platforms android template creates this',
|
||||
);
|
||||
expect(
|
||||
androidDir.childFile('settings.gradle'),
|
||||
isNot(exists),
|
||||
reason:
|
||||
''
|
||||
'flutter create should have created a settings.gradle.kts file '
|
||||
'but not a settings.gradle file. Prior to the change in the PR '
|
||||
'addressing https://github.com/flutter/flutter/issues/158962 '
|
||||
'both files were created, which means that tooling picked one '
|
||||
'and not the other, which causes ambiguity for debugging test '
|
||||
'flakes.',
|
||||
);
|
||||
}
|
||||
},
|
||||
skip: Platform.isWindows, // https://github.com/flutter/flutter/issues/157640
|
||||
);
|
||||
|
||||
// TODO(54566): Remove test when issue is resolved.
|
||||
/// Test project with a `settings.gradle` (PluginEach) that apps were created
|
||||
/// with until Flutter v1.22.0.
|
||||
/// It uses the `.flutter-plugins` file to load EACH plugin.
|
||||
test(
|
||||
'skip plugin if it does not support the Android platform with a _plugin.each_ settings.gradle',
|
||||
() async {
|
||||
final Project project = PluginEachWithPathAndroidProject();
|
||||
final ProcessResult buildApkResult = await testUnsupportedPlugin(
|
||||
project: project,
|
||||
createAndroidPluginFolder: false,
|
||||
);
|
||||
expect(buildApkResult.stderr.toString(), isNot(contains('Please fix your settings.gradle')));
|
||||
expect(buildApkResult, const ProcessResultMatcher());
|
||||
},
|
||||
skip: Platform.isWindows, // https://github.com/flutter/flutter/issues/157640
|
||||
);
|
||||
|
||||
// TODO(54566): Remove test when issue is resolved.
|
||||
/// Test project with a `settings.gradle` (PluginEach) that apps were created
|
||||
/// with until Flutter v1.22.0.
|
||||
/// It uses the `.flutter-plugins` file to load EACH plugin.
|
||||
/// The plugin includes a functional 'android' folder.
|
||||
test(
|
||||
'skip plugin with android folder if it does not support the Android platform with a _plugin.each_ settings.gradle',
|
||||
() async {
|
||||
final Project project = PluginEachWithPathAndroidProject();
|
||||
final ProcessResult buildApkResult = await testUnsupportedPlugin(
|
||||
project: project,
|
||||
createAndroidPluginFolder: true,
|
||||
);
|
||||
expect(buildApkResult.stderr.toString(), isNot(contains('Please fix your settings.gradle')));
|
||||
expect(buildApkResult, const ProcessResultMatcher());
|
||||
},
|
||||
skip: Platform.isWindows, // https://github.com/flutter/flutter/issues/157640
|
||||
);
|
||||
|
||||
// TODO(54566): Remove test when issue is resolved.
|
||||
/// Test project with a `settings.gradle` (PluginEach) that apps were created
|
||||
/// with until Flutter v1.22.0.
|
||||
/// It is compromised by removing the 'include' statement of the plugins.
|
||||
/// As the "'.flutter-plugins'" keyword is still present, the framework
|
||||
/// assumes that all plugins are included, which is not the case.
|
||||
/// Therefore it should throw an error.
|
||||
test(
|
||||
'skip plugin if it does not support the Android platform with a compromised _plugin.each_ settings.gradle',
|
||||
() async {
|
||||
final Project project = PluginCompromisedEachWithPathAndroidProject();
|
||||
final ProcessResult buildApkResult = await testUnsupportedPlugin(
|
||||
project: project,
|
||||
createAndroidPluginFolder: true,
|
||||
);
|
||||
expect(
|
||||
buildApkResult,
|
||||
const ProcessResultMatcher(stderrPattern: 'Please fix your settings.gradle'),
|
||||
);
|
||||
},
|
||||
skip: Platform.isWindows, // https://github.com/flutter/flutter/issues/157640
|
||||
);
|
||||
}
|
||||
|
||||
const String pubspecWithPluginPath = r'''
|
||||
name: test
|
||||
environment:
|
||||
sdk: ^3.7.0-0
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
test_plugin:
|
||||
path: ../
|
||||
''';
|
||||
|
||||
/// Project that load's a plugin from the specified path.
|
||||
class PluginWithPathAndroidProjectWithoutDeferred extends PluginProject {
|
||||
// Intentionally omit; this test case has nothing to do with deferred
|
||||
// components and a DeferredComponentsConfig will cause duplicates of files
|
||||
// such as build.gradle{.kts}, settings.gradle{kts} and related to be
|
||||
// generated, which in turn adds ambiguity to how the tests are built and
|
||||
// executed.
|
||||
//
|
||||
// See https://github.com/flutter/flutter/issues/158962.
|
||||
@override
|
||||
DeferredComponentsConfig? get deferredComponents => null;
|
||||
|
||||
@override
|
||||
String get pubspec => pubspecWithPluginPath;
|
||||
}
|
||||
|
||||
/// Project that load's a plugin from the specified path.
|
||||
class PluginWithPathAndroidProject extends PluginProject {
|
||||
@override
|
||||
String get pubspec => pubspecWithPluginPath;
|
||||
}
|
||||
|
||||
// TODO(matanlurey): Remove class when `.flutter-plugins` is no longer emitted.
|
||||
// See https://github.com/flutter/flutter/issues/48918.
|
||||
|
||||
/// [PluginEachSettingsGradleProject] that load's a plugin from the specified
|
||||
/// path.
|
||||
class PluginEachWithPathAndroidProject extends PluginEachSettingsGradleProject {
|
||||
@override
|
||||
String get pubspec => pubspecWithPluginPath;
|
||||
}
|
||||
|
||||
// TODO(matanlurey): Remove class when `.flutter-plugins` is no longer emitted.
|
||||
// See https://github.com/flutter/flutter/issues/48918.
|
||||
|
||||
/// [PluginCompromisedEachSettingsGradleProject] that load's a plugin from the
|
||||
/// specified path.
|
||||
class PluginCompromisedEachWithPathAndroidProject
|
||||
extends PluginCompromisedEachSettingsGradleProject {
|
||||
@override
|
||||
String get pubspec => pubspecWithPluginPath;
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
// 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:file/file.dart';
|
||||
import 'package:file_testing/file_testing.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
/// Tests that apps can be built using the deprecated `android/settings.gradle` file.
|
||||
/// This test should be removed once apps have been migrated to this new file.
|
||||
// TODO(egarciad): Migrate existing files, https://github.com/flutter/flutter/issues/54566
|
||||
void main() {
|
||||
test('android project using deprecated settings.gradle will still build', () async {
|
||||
final String workingDirectory = fileSystem.path.join(
|
||||
getFlutterRoot(),
|
||||
'dev',
|
||||
'integration_tests',
|
||||
'gradle_deprecated_settings',
|
||||
);
|
||||
|
||||
final File settingsDotGradleFile = fileSystem.file(
|
||||
fileSystem.path.join(workingDirectory, 'android', 'settings.gradle'),
|
||||
);
|
||||
const String expectedSettingsDotGradle = r"""
|
||||
// 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.
|
||||
|
||||
// This is the `settings.gradle` file that apps were created with until Flutter
|
||||
// v1.22.0. This file has changed, so it must be migrated in existing projects.
|
||||
|
||||
include ':app'
|
||||
|
||||
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
|
||||
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
|
||||
def properties = new Properties()
|
||||
|
||||
def plugins = new Properties()
|
||||
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
|
||||
if (pluginsFile.exists()) {
|
||||
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
|
||||
}
|
||||
|
||||
plugins.each { name, path ->
|
||||
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
|
||||
include ":$name"
|
||||
project(":$name").projectDir = pluginDirectory
|
||||
}
|
||||
""";
|
||||
|
||||
expect(
|
||||
settingsDotGradleFile.readAsStringSync().trim().replaceAll('\r', ''),
|
||||
equals(expectedSettingsDotGradle.trim()),
|
||||
);
|
||||
|
||||
final ProcessResult result = await processManager.run(<String>[
|
||||
flutterBin,
|
||||
'build',
|
||||
'apk',
|
||||
'--debug',
|
||||
'--target-platform',
|
||||
'android-arm',
|
||||
'--verbose',
|
||||
], workingDirectory: workingDirectory);
|
||||
|
||||
expect(result, const ProcessResultMatcher());
|
||||
|
||||
final String apkPath = fileSystem.path.join(
|
||||
workingDirectory,
|
||||
'build',
|
||||
'app',
|
||||
'outputs',
|
||||
'flutter-apk',
|
||||
'app-debug.apk',
|
||||
);
|
||||
expect(fileSystem.file(apkPath), exists);
|
||||
});
|
||||
}
|
@ -91,34 +91,35 @@ loading-units:
|
||||
|
||||
@override
|
||||
String get androidSettings => r'''
|
||||
include ':app', ':component1'
|
||||
pluginManagement {
|
||||
def flutterSdkPath = {
|
||||
def properties = new Properties()
|
||||
file("local.properties").withInputStream { properties.load(it) }
|
||||
def flutterSdkPath = properties.getProperty("flutter.sdk")
|
||||
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
|
||||
return flutterSdkPath
|
||||
}()
|
||||
|
||||
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
|
||||
def properties = new Properties()
|
||||
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
|
||||
|
||||
assert localPropertiesFile.exists()
|
||||
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
def flutterSdkPath = properties.getProperty("flutter.sdk")
|
||||
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
|
||||
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
|
||||
plugins {
|
||||
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
|
||||
id "com.android.application" version "8.8.0-rc02" apply false
|
||||
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
|
||||
}
|
||||
|
||||
include ":app", ":component1"
|
||||
''';
|
||||
|
||||
@override
|
||||
String get androidBuild => r'''
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.8.22'
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.1.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
@ -141,27 +142,11 @@ tasks.register("clean", Delete) {
|
||||
|
||||
@override
|
||||
String get appBuild => r'''
|
||||
def localProperties = new Properties()
|
||||
def localPropertiesFile = rootProject.file('local.properties')
|
||||
if (localPropertiesFile.exists()) {
|
||||
localPropertiesFile.withReader('UTF-8') { reader ->
|
||||
localProperties.load(reader)
|
||||
}
|
||||
}
|
||||
|
||||
def flutterRoot = localProperties.getProperty('flutter.sdk')
|
||||
if (flutterRoot == null) {
|
||||
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
|
||||
}
|
||||
|
||||
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
|
||||
if (flutterVersionCode == null) {
|
||||
flutterVersionCode = '1'
|
||||
}
|
||||
|
||||
def flutterVersionName = localProperties.getProperty('flutter.versionName')
|
||||
if (flutterVersionName == null) {
|
||||
flutterVersionName = '1.0'
|
||||
plugins {
|
||||
id "com.android.application"
|
||||
id "kotlin-android"
|
||||
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
|
||||
id "dev.flutter.flutter-gradle-plugin"
|
||||
}
|
||||
|
||||
def keystoreProperties = new Properties()
|
||||
@ -170,10 +155,6 @@ if (keystorePropertiesFile.exists()) {
|
||||
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
|
||||
|
||||
android {
|
||||
namespace = "com.example.splitaot"
|
||||
compileSdk flutter.compileSdkVersion
|
||||
@ -199,10 +180,10 @@ android {
|
||||
defaultConfig {
|
||||
// Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId "ninja.qian.splitaottest1"
|
||||
minSdkVersion flutter.minSdkVersion
|
||||
targetSdkVersion flutter.targetSdkVersion
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
minSdk flutter.minSdkVersion
|
||||
targetSdk flutter.targetSdkVersion
|
||||
versionCode flutter.versionCode
|
||||
versionName flutter.versionName
|
||||
}
|
||||
signingConfigs {
|
||||
release {
|
||||
@ -226,7 +207,7 @@ flutter {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.22"
|
||||
implementation "com.google.android.play:core:1.8.0"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user