Skip to content

Commit

Permalink
add: fallback to local.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
RatakondalaArun committed Jan 2, 2022
1 parent fbbdadc commit cf0d068
Show file tree
Hide file tree
Showing 2 changed files with 25 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
10 changes: 7 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 Down

0 comments on commit cf0d068

Please sign in to comment.