Don't use example folder as a project type signal (#97157)

The code to generate platform files used to use the presence of an
'example' folder to determine whether or not a project was a plugin (in
which case that generation is bypassed). Later, robust detection was
added based on the pubspec.yaml `plugin` key, but the old check was left
in place. This creates false positives where people who add an example
folder to their app project start getting mysterious failures.

Since the pubspec check is definitive, there's no reason to continue to
use the presence of `example` as an indicator at all.

Fixes https://github.com/flutter/flutter/issues/87007
This commit is contained in:
stuartmorgan 2022-01-24 22:28:38 -05:00 committed by GitHub
parent a190a45623
commit 2dd8cb1ca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -310,7 +310,7 @@ class FlutterProject {
bool winUwpPlatform = false,
DeprecationBehavior deprecationBehavior = DeprecationBehavior.none,
}) async {
if (!directory.existsSync() || hasExampleApp || isPlugin) {
if (!directory.existsSync() || isPlugin) {
return;
}
await refreshPluginsList(this, iosPlatform: iosPlatform, macOSPlatform: macOSPlatform);

View File

@ -156,6 +156,18 @@ void main() {
expectNotExists(project.ios.hostAppRoot.childDirectory('Flutter').childFile('Generated.xcconfig'));
expectNotExists(project.android.hostAppGradleRoot.childFile('local.properties'));
});
_testInMemory('works if there is an "example" folder', () async {
final FlutterProject project = await someProject();
// The presence of an "example" folder used to be used as an indicator
// that a project was a plugin, but shouldn't be as this creates false
// positives.
project.directory.childDirectory('example').createSync();
await project.regeneratePlatformSpecificTooling();
expectExists(project.ios.hostAppRoot.childDirectory('Runner').childFile('GeneratedPluginRegistrant.h'));
expectExists(androidPluginRegistrant(project.android.hostAppGradleRoot.childDirectory('app')));
expectExists(project.ios.hostAppRoot.childDirectory('Flutter').childFile('Generated.xcconfig'));
expectExists(project.android.hostAppGradleRoot.childFile('local.properties'));
});
_testInMemory('injects plugins for iOS', () async {
final FlutterProject project = await someProject();
await project.regeneratePlatformSpecificTooling();