Skip to content

Commit

Permalink
Merge pull request fluttercommunity#322 from RatakondalaArun/fix/flut…
Browse files Browse the repository at this point in the history
…ter-v2.8.0-support-321

Fix/flutter v2.8.0 support 321
  • Loading branch information
MarkOSullivan94 authored Jun 5, 2022
2 parents fbbdadc + 6915e2f commit cae647e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
22 changes: 18 additions & 4 deletions lib/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,29 @@ List<String> transformAndroidManifestWithNewLauncherIcon(
}).toList();
}

/// Retrieves the minSdk value from the Android build.gradle file
/// Retrieves the minSdk value from the Android build.gradle file or local.properties file
int minSdk() {
final File androidGradleFile = File(constants.androidGradleFile);
final List<String> lines = androidGradleFile.readAsLinesSync();
final androidGradleFile = File(constants.androidGradleFile);
final androidLocalPropertiesFile = File(constants.androidLocalPropertiesFile);

// look in build.gradle first
final minSdkValue = getMinSdkFromFile(androidGradleFile);

// look in local.properties. Didn't find minSdk, assume the worst
return minSdkValue != 0
? minSdkValue
: getMinSdkFromFile(androidLocalPropertiesFile);
}

/// Retrieves the minSdk value from [File]
int getMinSdkFromFile(File file) {
final List<String> lines = file.readAsLinesSync();
for (String line in lines) {
if (line.contains('minSdkVersion')) {
// remove anything from the line that is not a digit
final String minSdk = line.replaceAll(RegExp(r'[^\d]'), '');
return int.parse(minSdk);
// when minSdkVersion value not found
return int.tryParse(minSdk) ?? 0;
}
}
return 0; // Didn't find minSdk, assume the worst
Expand Down
13 changes: 10 additions & 3 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
String androidResFolder(String? flavor) => "android/app/src/${flavor ?? 'main'}/res/";
String androidColorsFile(String? flavor) => "android/app/src/${flavor ?? 'main'}/res/values/colors.xml";
String androidResFolder(String? flavor) =>
"android/app/src/${flavor ?? 'main'}/res/";
String androidColorsFile(String? flavor) =>
"android/app/src/${flavor ?? 'main'}/res/values/colors.xml";
const String androidManifestFile = 'android/app/src/main/AndroidManifest.xml';
const String androidGradleFile = 'android/app/build.gradle';
const String androidLocalPropertiesFile = 'android/local.properties';
const String androidFileName = 'ic_launcher.png';
const String androidAdaptiveForegroundFileName = 'ic_launcher_foreground.png';
const String androidAdaptiveBackgroundFileName = 'ic_launcher_background.png';
String androidAdaptiveXmlFolder(String? flavor) => androidResFolder(flavor) + 'mipmap-anydpi-v26/';
String androidAdaptiveXmlFolder(String? flavor) =>
androidResFolder(flavor) + 'mipmap-anydpi-v26/';
const String androidDefaultIconName = 'ic_launcher';

const String iosDefaultIconFolder =
Expand All @@ -21,6 +25,9 @@ const String errorMissingPlatform =
const String errorMissingRegularAndroid =
'Adaptive icon config found but no regular Android config. '
'Below API 26 the regular Android config is required';
const String errorMissingMinSdk =
'Cannot not find minSdk from android/app/build.gradle or android/local.properties'
'Specify minSdk in either android/app/build.gradle or android/local.properties';
const String errorIncorrectIconName =
'The icon name must contain only lowercase a-z, 0-9, or underscore: '
'E.g. "ic_my_new_icon"';
Expand Down
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ Future<void> createIconsFromConfig(Map<String, dynamic> config,

if (isNeedingNewAndroidIcon(config) || hasAndroidAdaptiveConfig(config)) {
final int minSdk = android_launcher_icons.minSdk();
if (minSdk == 0) {
throw const InvalidConfigException(errorMissingMinSdk);
}
if (minSdk < 26 &&
hasAndroidAdaptiveConfig(config) &&
!hasAndroidConfig(config)) {
Expand Down

0 comments on commit cae647e

Please sign in to comment.