Commit 24eeddc0 authored by John McCutchan's avatar John McCutchan Committed by GitHub

Request the user upgrade if the Android SDK version is 24 (#8462)

* Request the user upgrade if the Android SDK version is 24

* Update android_sdk_test.dart

* Update android_sdk.dart
parent bd3aac70
...@@ -2,14 +2,13 @@ ...@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:pub_semver/pub_semver.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/context.dart'; import '../base/context.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../base/platform.dart'; import '../base/platform.dart';
import '../base/process_manager.dart'; import '../base/process_manager.dart';
import '../base/version.dart';
import '../globals.dart'; import '../globals.dart';
AndroidSdk get androidSdk => context[AndroidSdk]; AndroidSdk get androidSdk => context[AndroidSdk];
...@@ -36,6 +35,9 @@ const Map<String, int> _namedVersionMap = const <String, int> { ...@@ -36,6 +35,9 @@ const Map<String, int> _namedVersionMap = const <String, int> {
'android-stable': 24, 'android-stable': 24,
}; };
/// The minimum Android SDK version we support.
const int minimumAndroidSdkVersion = 25;
/// Locate ADB. Prefer to use one from an Android SDK, if we can locate that. /// Locate ADB. Prefer to use one from an Android SDK, if we can locate that.
/// This should be used over accessing androidSdk.adbPath directly because it /// This should be used over accessing androidSdk.adbPath directly because it
/// will work for those users who have Android Platform Tools installed but /// will work for those users who have Android Platform Tools installed but
...@@ -188,7 +190,7 @@ class AndroidSdk { ...@@ -188,7 +190,7 @@ class AndroidSdk {
return new AndroidSdkVersion( return new AndroidSdkVersion(
this, this,
platformVersionName: platformName, platformVersionName: platformName,
buildToolsVersionName: buildToolsVersion.toString() buildToolsVersion: buildToolsVersion
); );
}).where((AndroidSdkVersion version) => version != null).toList(); }).where((AndroidSdkVersion version) => version != null).toList();
...@@ -204,12 +206,13 @@ class AndroidSdk { ...@@ -204,12 +206,13 @@ class AndroidSdk {
class AndroidSdkVersion implements Comparable<AndroidSdkVersion> { class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
AndroidSdkVersion(this.sdk, { AndroidSdkVersion(this.sdk, {
this.platformVersionName, this.platformVersionName,
this.buildToolsVersionName this.buildToolsVersion,
}); });
final AndroidSdk sdk; final AndroidSdk sdk;
final String platformVersionName; final String platformVersionName;
final String buildToolsVersionName; final Version buildToolsVersion;
String get buildToolsVersionName => buildToolsVersion.toString();
int get sdkLevel { int get sdkLevel {
if (_namedVersionMap.containsKey(platformVersionName)) if (_namedVersionMap.containsKey(platformVersionName))
...@@ -229,6 +232,10 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> { ...@@ -229,6 +232,10 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
String get apksignerPath => getBuildToolsPath('apksigner'); String get apksignerPath => getBuildToolsPath('apksigner');
List<String> validateSdkWellFormed({bool requireApkSigner = true}) { List<String> validateSdkWellFormed({bool requireApkSigner = true}) {
if (buildToolsVersion.major < minimumAndroidSdkVersion) {
return <String>['Minimum supported Android SDK version is $minimumAndroidSdkVersion '
'but this system has ${buildToolsVersion.major}. Please upgrade.'];
}
if (_exists(androidJarPath) != null) if (_exists(androidJarPath) != null)
return <String>[_exists(androidJarPath)]; return <String>[_exists(androidJarPath)];
......
...@@ -58,6 +58,20 @@ class Version implements Comparable<Version> { ...@@ -58,6 +58,20 @@ class Version implements Comparable<Version> {
} }
} }
/// Returns the primary version out of a list of candidates.
///
/// This is the highest-numbered stable version.
static Version primary(List<Version> versions) {
Version primary;
for (Version version in versions) {
if (primary == null || (version > primary)) {
primary = version;
}
}
return primary;
}
static Version get unknown => new Version(0, 0, 0, text: 'unknown'); static Version get unknown => new Version(0, 0, 0, text: 'unknown');
/// Two [Version]s are equal if their version numbers are. The version text /// Two [Version]s are equal if their version numbers are. The version text
......
...@@ -4,12 +4,11 @@ ...@@ -4,12 +4,11 @@
import 'dart:async'; import 'dart:async';
import 'package:pub_semver/pub_semver.dart' show Version;
import '../base/io.dart'; import '../base/io.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../base/platform.dart'; import '../base/platform.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../base/version.dart';
import '../doctor.dart'; import '../doctor.dart';
import 'mac.dart'; import 'mac.dart';
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'package:flutter_tools/src/android/android_sdk.dart'; import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/version.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'src/context.dart'; import 'src/context.dart';
...@@ -37,14 +38,14 @@ void main() { ...@@ -37,14 +38,14 @@ void main() {
testUsingContext('parse normal', () { testUsingContext('parse normal', () {
final AndroidSdk sdk = new AndroidSdk('.'); final AndroidSdk sdk = new AndroidSdk('.');
final AndroidSdkVersion ver = new AndroidSdkVersion(sdk, final AndroidSdkVersion ver = new AndroidSdkVersion(sdk,
platformVersionName: 'android-23', buildToolsVersionName: '23.0.0'); platformVersionName: 'android-23', buildToolsVersion: new Version.parse('23.0.0'));
expect(ver.sdkLevel, 23); expect(ver.sdkLevel, 23);
}); });
testUsingContext('parse android n', () { testUsingContext('parse android n', () {
final AndroidSdk sdk = new AndroidSdk('.'); final AndroidSdk sdk = new AndroidSdk('.');
final AndroidSdkVersion ver = new AndroidSdkVersion(sdk, final AndroidSdkVersion ver = new AndroidSdkVersion(sdk,
platformVersionName: 'android-N', buildToolsVersionName: '24.0.0'); platformVersionName: 'android-N', buildToolsVersion: new Version.parse('24.0.0'));
expect(ver.sdkLevel, 24); expect(ver.sdkLevel, 24);
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment