Commit ce278e97 authored by Devon Carew's avatar Devon Carew

Merge pull request #1902 from devoncarew/tools_cleanup

fixes found when running through the getting started process
parents 35eb6c4a b7b06c2a
...@@ -181,9 +181,8 @@ class AdbDevice { ...@@ -181,9 +181,8 @@ class AdbDevice {
} }
} }
// Convert `Nexus_7` / `Nexus_5X` style names to `Nexus 7` ones.
if (modelID != null) if (modelID != null)
modelID = modelID.replaceAll('_', ' '); modelID = cleanAdbDeviceName(modelID);
} }
static final RegExp deviceRegex = new RegExp(r'^(\S+)\s+(\S+)(.*)'); static final RegExp deviceRegex = new RegExp(r'^(\S+)\s+(\S+)(.*)');
...@@ -235,6 +234,16 @@ class AdbDevice { ...@@ -235,6 +234,16 @@ class AdbDevice {
} }
} }
String cleanAdbDeviceName(String name) {
// Some emulators use `___` in the name as separators.
name = name.replaceAll('___', ', ');
// Convert `Nexus_7` / `Nexus_5X` style names to `Nexus 7` ones.
name = name.replaceAll('_', ' ');
return name;
}
List<int> _createAdbRequest(String payload) { List<int> _createAdbRequest(String payload) {
List<int> data = payload.codeUnits; List<int> data = payload.codeUnits;
......
...@@ -23,7 +23,10 @@ import '../base/os.dart'; ...@@ -23,7 +23,10 @@ import '../base/os.dart';
// Perhaps something like `flutter config --android-home=foo/bar`. // Perhaps something like `flutter config --android-home=foo/bar`.
/// 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.
String getAdbPath() { String getAdbPath([AndroidSdk existingSdk]) {
if (existingSdk?.adbPath != null)
return existingSdk.adbPath;
AndroidSdk sdk = AndroidSdk.locateAndroidSdk(); AndroidSdk sdk = AndroidSdk.locateAndroidSdk();
if (sdk?.latestVersion == null) { if (sdk?.latestVersion == null) {
......
...@@ -8,6 +8,7 @@ import 'dart:io'; ...@@ -8,6 +8,7 @@ import 'dart:io';
import 'package:crypto/crypto.dart'; import 'package:crypto/crypto.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import '../android/android_sdk.dart';
import '../application_package.dart'; import '../application_package.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/globals.dart'; import '../base/globals.dart';
...@@ -17,6 +18,7 @@ import '../build_configuration.dart'; ...@@ -17,6 +18,7 @@ import '../build_configuration.dart';
import '../device.dart'; import '../device.dart';
import '../flx.dart' as flx; import '../flx.dart' as flx;
import '../toolchain.dart'; import '../toolchain.dart';
import 'adb.dart';
import 'android.dart'; import 'android.dart';
const String _defaultAdbPath = 'adb'; const String _defaultAdbPath = 'adb';
...@@ -249,7 +251,12 @@ class AndroidDevice extends Device { ...@@ -249,7 +251,12 @@ class AndroidDevice extends Device {
if (route != null) if (route != null)
cmd.addAll(<String>['--es', 'route', route]); cmd.addAll(<String>['--es', 'route', route]);
cmd.add(apk.launchActivity); cmd.add(apk.launchActivity);
runCheckedSync(cmd); String result = runCheckedSync(cmd);
// This invocation returns 0 even when it fails.
if (result.contains('Error: ')) {
printError(result.trim());
return false;
}
return true; return true;
} }
...@@ -410,10 +417,10 @@ class AndroidDevice extends Device { ...@@ -410,10 +417,10 @@ class AndroidDevice extends Device {
} }
List<AndroidDevice> getAdbDevices() { List<AndroidDevice> getAdbDevices() {
if (androidSdk == null) String adbPath = getAdbPath(androidSdk);
if (adbPath == null)
return <AndroidDevice>[]; return <AndroidDevice>[];
String adbPath = androidSdk.adbPath;
List<AndroidDevice> devices = []; List<AndroidDevice> devices = [];
List<String> output = runSync(<String>[adbPath, 'devices', '-l']).trim().split('\n'); List<String> output = runSync(<String>[adbPath, 'devices', '-l']).trim().split('\n');
...@@ -445,9 +452,8 @@ List<AndroidDevice> getAdbDevices() { ...@@ -445,9 +452,8 @@ List<AndroidDevice> getAdbDevices() {
String modelID = match[3]; String modelID = match[3];
String deviceCodeName = match[4]; String deviceCodeName = match[4];
// Convert `Nexus_7` / `Nexus_5X` style names to `Nexus 7` ones.
if (modelID != null) if (modelID != null)
modelID = modelID.replaceAll('_', ' '); modelID = cleanAdbDeviceName(modelID);
devices.add(new AndroidDevice( devices.add(new AndroidDevice(
deviceID, deviceID,
......
...@@ -369,6 +369,17 @@ Future<int> buildAndroid({ ...@@ -369,6 +369,17 @@ Future<int> buildAndroid({
String flxPath: '', String flxPath: '',
ApkKeystoreInfo keystore ApkKeystoreInfo keystore
}) async { }) async {
// Validate that we can find an android sdk.
if (androidSdk == null) {
printError('No Android SDK found.');
return 1;
}
if (!androidSdk.validateSdkWellFormed(complain: true)) {
printError('Try re-installing or updating your Android SDK.');
return 1;
}
if (!force && !_needsRebuild(outputFile, manifest)) { if (!force && !_needsRebuild(outputFile, manifest)) {
printTrace('APK up to date. Skipping build step.'); printTrace('APK up to date. Skipping build step.');
return 0; return 0;
...@@ -437,13 +448,17 @@ Future buildAll( ...@@ -437,13 +448,17 @@ Future buildAll(
continue; continue;
} }
await buildAndroid( int result = await buildAndroid(
toolchain: toolchain, toolchain: toolchain,
configs: configs, configs: configs,
enginePath: enginePath, enginePath: enginePath,
force: false, force: false,
target: target target: target
); );
if (result != 0)
return result;
} }
} }
return 0;
} }
...@@ -57,7 +57,7 @@ class CreateCommand extends Command { ...@@ -57,7 +57,7 @@ class CreateCommand extends Command {
All done! To run your application: All done! To run your application:
\$ cd ${out.path} \$ cd ${out.path}
\$ flutter start \$ flutter run
'''; ''';
if (argResults['pub']) { if (argResults['pub']) {
...@@ -152,8 +152,8 @@ class FlutterSimpleTemplate extends Template { ...@@ -152,8 +152,8 @@ class FlutterSimpleTemplate extends Template {
// Android files. // Android files.
files['android/AndroidManifest.xml'] = _apkManifest; files['android/AndroidManifest.xml'] = _apkManifest;
// Create a file here, so we create the directory for the user and it gets committed with git. // Create a file here in order to create the res/ directory and ensure it gets committed to git.
files['android/res/README.md'] = _androidResReadme; files['android/res/.empty'] = _androidEmptyFile;
// iOS files. // iOS files.
files.addAll(iosTemplateFiles); files.addAll(iosTemplateFiles);
...@@ -285,6 +285,6 @@ final String _apkManifest = ''' ...@@ -285,6 +285,6 @@ final String _apkManifest = '''
</manifest> </manifest>
'''; ''';
final String _androidResReadme = ''' final String _androidEmptyFile = '''
Place Android resources here (http://developer.android.com/guide/topics/resources/overview.html). Place Android resources here (http://developer.android.com/guide/topics/resources/overview.html).
'''; ''';
...@@ -356,7 +356,7 @@ class AndroidDeviceDiscovery { ...@@ -356,7 +356,7 @@ class AndroidDeviceDiscovery {
void _initAdb() { void _initAdb() {
if (_adb == null) { if (_adb == null) {
_adb = new Adb(getAdbPath()); _adb = new Adb(getAdbPath(androidSdk));
if (!_adb.exists()) if (!_adb.exists())
_adb = null; _adb = null;
} }
......
...@@ -23,9 +23,6 @@ class LogsCommand extends FlutterCommand { ...@@ -23,9 +23,6 @@ class LogsCommand extends FlutterCommand {
bool get requiresProjectRoot => false; bool get requiresProjectRoot => false;
Future<int> runInProject() async { Future<int> runInProject() async {
DeviceManager deviceManager = new DeviceManager();
deviceManager.specifiedDeviceId = globalResults['device-id'];
List<Device> devices = await deviceManager.getDevices(); List<Device> devices = await deviceManager.getDevices();
if (devices.isEmpty && deviceManager.hasSpecifiedDeviceId) { if (devices.isEmpty && deviceManager.hasSpecifiedDeviceId) {
......
...@@ -131,7 +131,6 @@ Future<int> startApp( ...@@ -131,7 +131,6 @@ Future<int> startApp(
bool startPaused: false, bool startPaused: false,
int debugPort: observatoryDefaultPort int debugPort: observatoryDefaultPort
}) async { }) async {
String mainPath = findMainDartFile(target); String mainPath = findMainDartFile(target);
if (!FileSystemEntity.isFileSync(mainPath)) { if (!FileSystemEntity.isFileSync(mainPath)) {
String message = 'Tried to run $mainPath, but that file does not exist.'; String message = 'Tried to run $mainPath, but that file does not exist.';
...@@ -143,11 +142,13 @@ Future<int> startApp( ...@@ -143,11 +142,13 @@ Future<int> startApp(
if (install) { if (install) {
printTrace('Running build command.'); printTrace('Running build command.');
await buildAll( int result = await buildAll(
devices, applicationPackages, toolchain, configs, devices, applicationPackages, toolchain, configs,
enginePath: enginePath, enginePath: enginePath,
target: target target: target
); );
if (result != 0)
return result;
} }
if (stop) { if (stop) {
......
...@@ -348,7 +348,12 @@ class IOSSimulator extends Device { ...@@ -348,7 +348,12 @@ class IOSSimulator extends Device {
args.add("--observatory-port=$debugPort"); args.add("--observatory-port=$debugPort");
// Step 5: Launch the updated application in the simulator // Step 5: Launch the updated application in the simulator
SimControl.launch(id, app.id, args); try {
SimControl.launch(id, app.id, args);
} catch (error) {
printError('$error');
return false;
}
printTrace('Successfully started ${app.name} on $id'); printTrace('Successfully started ${app.name} on $id');
...@@ -388,6 +393,12 @@ class IOSSimulator extends Device { ...@@ -388,6 +393,12 @@ class IOSSimulator extends Device {
randomFile.closeSync(); randomFile.closeSync();
} }
} }
void ensureLogsExists() {
File logFile = new File(logFilePath);
if (!logFile.existsSync())
logFile.writeAsBytesSync(<int>[]);
}
} }
class _IOSDeviceLogReader extends DeviceLogReader { class _IOSDeviceLogReader extends DeviceLogReader {
...@@ -427,6 +438,8 @@ class _IOSSimulatorLogReader extends DeviceLogReader { ...@@ -427,6 +438,8 @@ class _IOSSimulatorLogReader extends DeviceLogReader {
final IOSSimulator device; final IOSSimulator device;
bool _lastWasFiltered = false;
String get name => device.name; String get name => device.name;
Future<int> logs({ bool clear: false }) async { Future<int> logs({ bool clear: false }) async {
...@@ -436,6 +449,8 @@ class _IOSSimulatorLogReader extends DeviceLogReader { ...@@ -436,6 +449,8 @@ class _IOSSimulatorLogReader extends DeviceLogReader {
if (clear) if (clear)
device.clearLogs(); device.clearLogs();
device.ensureLogsExists();
// Match the log prefix (in order to shorten it): // Match the log prefix (in order to shorten it):
// 'Jan 29 01:31:44 devoncarew-macbookpro3 SpringBoard[96648]: ...' // 'Jan 29 01:31:44 devoncarew-macbookpro3 SpringBoard[96648]: ...'
RegExp mapRegex = new RegExp(r'\S+ +\S+ +\S+ \S+ (.+)\[\d+\]\)?: (.*)$'); RegExp mapRegex = new RegExp(r'\S+ +\S+ +\S+ \S+ (.+)\[\d+\]\)?: (.*)$');
...@@ -453,19 +468,25 @@ class _IOSSimulatorLogReader extends DeviceLogReader { ...@@ -453,19 +468,25 @@ class _IOSSimulatorLogReader extends DeviceLogReader {
mapFunction: (String string) { mapFunction: (String string) {
Match match = mapRegex.matchAsPrefix(string); Match match = mapRegex.matchAsPrefix(string);
if (match != null) { if (match != null) {
_lastWasFiltered = true;
// Filter out some messages that clearly aren't related to Flutter. // Filter out some messages that clearly aren't related to Flutter.
if (string.contains(': could not find icon for representation -> com.apple.')) if (string.contains(': could not find icon for representation -> com.apple.'))
return null; return null;
String category = match.group(1); String category = match.group(1);
String content = match.group(2); String content = match.group(2);
if (category == 'Game Center' || category == 'itunesstored' || category == 'nanoregistrylaunchd') if (category == 'Game Center' || category == 'itunesstored' || category == 'nanoregistrylaunchd' ||
category == 'mstreamd' || category == 'syncdefaultsd' || category == 'companionappd' || category == 'searchd')
return null; return null;
if (category == 'FlutterRunner')
_lastWasFiltered = false;
if (category == 'FlutterRunner' || category == 'Runner')
return content; return content;
return '$category: $content'; return '$category: $content';
} }
match = lastMessageRegex.matchAsPrefix(string); match = lastMessageRegex.matchAsPrefix(string);
if (match != null) if (match != null && !_lastWasFiltered)
return '(${match.group(1)})'; return '(${match.group(1)})';
return string; return string;
} }
......
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