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