diff --git a/CHANGELOG.md b/CHANGELOG.md index 83fa5272e5..349c0f3906 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +# 0.5.2 (19th June 2018) + +- Previous release didn't fix adaptive icons, just prevented the error message from appearing. This should hopefully fix it! + # 0.5.1 (18th June 2018) - Fix for adaptive icons diff --git a/README.md b/README.md index 4711865a1e..fc06fb2b06 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ dev_dependencies: flutter_test: sdk: flutter - flutter_launcher_icons: "^0.5.1" + flutter_launcher_icons: "^0.5.2" ``` 2. Within the same pubspec.yaml file, add flutter_icons config section. @@ -35,7 +35,7 @@ dev_dependencies: flutter_test: sdk: flutter - flutter_launcher_icons: "^0.5.1" + flutter_launcher_icons: "^0.5.2" flutter_icons: android: true diff --git a/lib/android.dart b/lib/android.dart index 95dea40ee2..15d6fb80d0 100644 --- a/lib/android.dart +++ b/lib/android.dart @@ -1,5 +1,4 @@ import 'dart:io'; -import 'package:xml/xml.dart'; import 'package:flutter_launcher_icons/xml_templates.dart' as XmlTemplate; import 'package:image/image.dart'; @@ -9,7 +8,7 @@ const String android_manifest_file = "android/app/src/main/AndroidManifest.xml"; const String android_gradle_file = "android/app/build.gradle"; const String android_file_name = "ic_launcher.png"; const String android_adaptive_foreground_file_name = "ic_launcher_foreground.png"; -const String android_adaptive_xml_folder = android_res_folder + "mipmap-v26/"; +const String android_adaptive_xml_folder = android_res_folder + "mipmap-anydpi-v26/"; const String default_icon_name = "ic_launcher"; class AndroidIcon { @@ -62,20 +61,23 @@ createAdaptiveIcons(config) { // Create foreground images adaptive_foreground_icons.forEach((AndroidIcon e) => overwriteExistingIcons(e, foreground_image, android_adaptive_foreground_file_name)); - // Generate ic_launcher.xml // If is using a string for android config, generate .xml // Otherwise use ic_launcher.xml - if (isCustomAndroidFile(config)) { - new File(android_adaptive_xml_folder + getNewIconName(config) - + '.xml').create(recursive: true).then((File adaptive_icon) { - adaptive_icon.writeAsString(XmlTemplate.ic_launcher_xml); - }); + if (isCorrectMipmapDirectoryForAdaptiveIcon(android_adaptive_xml_folder)) { + if (isCustomAndroidFile(config)) { + new File(android_adaptive_xml_folder + getNewIconName(config) + + '.xml').create(recursive: true).then((File adaptive_icon) { + adaptive_icon.writeAsString(XmlTemplate.ic_launcher_xml); + }); + } else { + new File(android_adaptive_xml_folder + default_icon_name + '.xml') + .create(recursive: true).then((File adaptive_icon) { + adaptive_icon.writeAsString(XmlTemplate.ic_launcher_xml); + }); + } } else { - new File(android_adaptive_xml_folder + default_icon_name + '.xml') - .create(recursive: true).then((File adaptive_icon) { - adaptive_icon.writeAsString(XmlTemplate.ic_launcher_xml); - }); + print("Error: Unable to generate adaptive icon"); } // Check if colors.xml exists in the project @@ -113,6 +115,21 @@ createAdaptiveIcons(config) { }); } +/** + * Ensures the correct path is used for generating adaptive icons + * + * "Next you must create alternative drawable resources in your app for use with + * Android 8.0 (API level 26) in res/mipmap-anydpi/ic_launcher.xml" + * Source: https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive + */ +bool isCorrectMipmapDirectoryForAdaptiveIcon(String path) { + if (path != "android/app/src/main/res/mipmap-anydpi-v26/") { + return false; + } else { + return true; + } +} + // Check to see if specified Android config is a string or bool // String - Generate new launcher icon with the string specified // bool - override the default flutter project icon diff --git a/pubspec.yaml b/pubspec.yaml index c00781f708..97cbd0a544 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_launcher_icons description: A package which simplifies the task of updating your Flutter app's launcher icon. Fully flexible, allowing you to choose what platform you wish to update the launcher icon for and if you want, the option to keep your old launcher icon in case you want to revert back sometime in the future. -version: 0.5.1 +version: 0.5.2 homepage: https://github.com/franzsilva/flutter_launcher_icons authors: - Franz Silva diff --git a/test/android_test.dart b/test/android_test.dart new file mode 100644 index 0000000000..77afa072c6 --- /dev/null +++ b/test/android_test.dart @@ -0,0 +1,34 @@ +import 'package:test/test.dart'; +import 'package:flutter_launcher_icons/android.dart' as Android; + +/** + * Unit tests for android.dart + */ + +void main() { + test('Adaptive icon mipmap path is correct', () { + String path1 = "android/app/src/main/res/"; + String path2 = "mipmap-anydpi-v26/"; + expect(Android.isCorrectMipmapDirectoryForAdaptiveIcon(path1), false); + expect(Android.isCorrectMipmapDirectoryForAdaptiveIcon(path2), false); + expect(Android.isCorrectMipmapDirectoryForAdaptiveIcon(Android.android_adaptive_xml_folder), true); + }); + + test('Correct number of adaptive foreground icons', () { + expect(Android.adaptive_foreground_icons.length, 5); + }); + + test('Correct number of android launcher icons', () { + expect(Android.android_icons.length, 5); + }); + + test('Config contains string for generating new launcher icons', () { + Map flutter_icons_config = {"image_path": "assets/images/icon-710x599.png", + "android": true, "ios": true}; + expect(Android.isCustomAndroidFile(flutter_icons_config), false); + + Map flutter_icons_new_icon_config = {"image_path": "assets/images/icon-710x599.png", + "android": "New Icon", "ios": true}; + expect(Android.isCustomAndroidFile(flutter_icons_new_icon_config), true); + }); +} \ No newline at end of file diff --git a/test/flutter_icons_test.dart b/test/main_test.dart similarity index 98% rename from test/flutter_icons_test.dart rename to test/main_test.dart index 161cc56eca..62fa3c323e 100644 --- a/test/flutter_icons_test.dart +++ b/test/main_test.dart @@ -3,6 +3,10 @@ import 'package:flutter_launcher_icons/ios.dart' as IOS; import 'package:flutter_launcher_icons/android.dart' as Android; import 'package:flutter_launcher_icons/main.dart' as Main; +/** + * Unit tests for main.dart + */ + void main() { test('iOS icon list is correct size', () { expect(IOS.ios_icons.length, 15);