Protect flutter analyze --suggestions from erroring on missing AGP value. (#137719)

Fixes #137600 
Protect flutter analyze --suggestions from null error when AGP value is missing
Update template with a reference to new agp definition location 
Look for AGP version being set in settings.gradle (change to templates happened in dbe0ccd885 (diff-20537fb84ee37894a3f3d9723a06bcf2674290ee25aa83332c2524a1f7546a6d)
This commit is contained in:
Reid Baker
2023-11-02 17:14:58 -04:00
committed by GitHub
parent 969a8750a5
commit 4d21a026e5
6 changed files with 144 additions and 18 deletions

View File

@@ -469,6 +469,51 @@ allprojects {
);
});
testWithoutContext('returns the AGP version when in settings', () async {
final Directory androidDirectory = fileSystem.directory('/android')
..createSync();
// File must exist and can not have agp defined.
androidDirectory.childFile('build.gradle').writeAsStringSync(r'');
androidDirectory.childFile('settings.gradle').writeAsStringSync(r'''
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
}
settings.ext.flutterSdkPath = flutterSdkPath()
includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
plugins {
id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
}
}
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
// Decoy value to ensure we ignore commented out lines.
// id "com.android.application" version "6.1.0" apply false
id "com.android.application" version "7.3.0" apply false
}
include ":app"
''');
expect(
getAgpVersion(androidDirectory, BufferLogger.test()),
'7.3.0',
);
});
group('validates gradle/agp versions', () {
final List<GradleAgpTestData> testData = <GradleAgpTestData>[
// Values too new *these need to be updated* when

View File

@@ -659,6 +659,48 @@ dependencies {
androidSdk: androidSdk,
);
});
group('_', () {
final FakeProcessManager processManager;
final Java java;
final AndroidStudio androidStudio;
final FakeAndroidSdkWithDir androidSdk;
final FileSystem fileSystem = getFileSystemForPlatform();
java = FakeJava(version: Version(11, 0, 2));
processManager = FakeProcessManager.empty();
androidStudio = FakeAndroidStudio();
androidSdk =
FakeAndroidSdkWithDir(fileSystem.currentDirectory);
fileSystem.currentDirectory
.childDirectory(androidStudio.javaPath!)
.createSync();
_testInMemory(
'null agp only',
() async {
const String gradleV = '7.0.3';
final FlutterProject? project = await configureGradleAgpForTest(
gradleV: gradleV,
agpV: '',
);
final CompatibilityResult value =
await project!.android.hasValidJavaGradleAgpVersions();
expect(value.success, isFalse);
// Should not have the valid string.
expect(
value.description,
isNot(
contains(RegExp(AndroidProject.validJavaGradleAgpString))));
// On gradle/agp error print help url null value for agp.
expect(value.description,
contains(RegExp(AndroidProject.gradleAgpCompatUrl)));
expect(value.description, contains(RegExp(gradleV)));
expect(value.description, contains(RegExp('null')));
},
java: java,
androidStudio: androidStudio,
processManager: processManager,
androidSdk: androidSdk,
);
});
});
group('language', () {