Merge pull request #52 from devoncarew/older_android

support older android devices (>= 17)
diff --git a/bin/cache/.gitignore b/bin/cache/.gitignore
index a46a103..565eb5e 100644
--- a/bin/cache/.gitignore
+++ b/bin/cache/.gitignore
@@ -1,2 +1,3 @@
 *.snapshot
 *.stamp
+artifacts
diff --git a/bin/flutter b/bin/flutter
index a83fb57..31c9737 100755
--- a/bin/flutter
+++ b/bin/flutter
@@ -3,7 +3,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-FLUTTER_ROOT=$(dirname $(dirname "${BASH_SOURCE[0]}"))
+export FLUTTER_ROOT=$(dirname $(dirname "${BASH_SOURCE[0]}"))
 FLUTTER_TOOLS_DIR="$FLUTTER_ROOT/packages/flutter_tools"
 SNAPSHOT_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.snapshot"
 STAMP_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.stamp"
diff --git a/packages/flutter_tools/lib/src/artifacts.dart b/packages/flutter_tools/lib/src/artifacts.dart
index bc2a850..17da362 100644
--- a/packages/flutter_tools/lib/src/artifacts.dart
+++ b/packages/flutter_tools/lib/src/artifacts.dart
@@ -10,6 +10,7 @@
 
 import 'build_configuration.dart';
 import 'os_utils.dart';
+import 'process.dart';
 
 final Logger _logging = new Logger('sky_tools.artifacts');
 
@@ -155,7 +156,10 @@
     return null;
   }
 
+  // These values are initialized by FlutterCommandRunner on startup.
+  static String flutterRoot;
   static String packageRoot;
+
   static String _engineRevision;
 
   static String get engineRevision {
@@ -190,7 +194,11 @@
   }
 
   static Directory _getBaseCacheDir() {
-    Directory cacheDir = new Directory(path.join(packageRoot, 'sky_tools', 'cache'));
+    if (flutterRoot == null) {
+      _logging.severe('FLUTTER_ROOT not specified. Cannot find artifact cache.');
+      throw new ProcessExit(2);
+    }
+    Directory cacheDir = new Directory(path.join(flutterRoot, 'bin', 'cache', 'artifacts'));
     if (!cacheDir.existsSync())
       cacheDir.createSync(recursive: true);
     return cacheDir;
@@ -198,8 +206,6 @@
 
   static Directory _getCacheDirForArtifact(Artifact artifact) {
     Directory baseDir = _getBaseCacheDir();
-    // For now, all downloaded artifacts are release mode host binaries so use
-    // a path that mirrors a local release build.
     // TODO(jamesr): Add support for more configurations.
     String config = 'Release';
     Directory artifactSpecificDir = new Directory(path.join(
diff --git a/packages/flutter_tools/lib/src/commands/flutter_command_runner.dart b/packages/flutter_tools/lib/src/commands/flutter_command_runner.dart
index 36b39be..f4659be 100644
--- a/packages/flutter_tools/lib/src/commands/flutter_command_runner.dart
+++ b/packages/flutter_tools/lib/src/commands/flutter_command_runner.dart
@@ -29,6 +29,8 @@
             'shell commands executed.');
     argParser.addOption('package-root',
         help: 'Path to your packages directory.', defaultsTo: 'packages');
+    argParser.addOption('flutter-root',
+        help: 'The root directory of the Flutter repository.');
     argParser.addOption('android-device-id',
         help: 'Serial number of the target Android device.');
 
@@ -105,6 +107,7 @@
       Logger.root.level = Level.FINE;
 
     _globalResults = globalResults;
+    ArtifactStore.flutterRoot = globalResults['flutter-root'] ?? Platform.environment['FLUTTER_ROOT'];
     ArtifactStore.packageRoot = globalResults['package-root'];
 
     return super.runCommand(globalResults);
diff --git a/packages/flutter_tools/lib/src/commands/init.dart b/packages/flutter_tools/lib/src/commands/init.dart
index ed1db5b..a3b9914 100644
--- a/packages/flutter_tools/lib/src/commands/init.dart
+++ b/packages/flutter_tools/lib/src/commands/init.dart
@@ -9,6 +9,7 @@
 import 'package:mustache4dart/mustache4dart.dart' as mustache;
 import 'package:path/path.dart' as p;
 
+import '../artifacts.dart';
 import '../process.dart';
 
 class InitCommand extends Command {
@@ -30,17 +31,30 @@
       return 2;
     }
 
+    if (ArtifactStore.flutterRoot == null) {
+      stderr.writeln('Neither the --flutter-root command line flag nor the FLUTTER_ROOT environment');
+      stderr.writeln('variable was specified. Unable to find package:flutter.');
+      return 2;
+    }
+    String flutterRoot = p.absolute(ArtifactStore.flutterRoot);
+
+    String flutterPackagePath = p.join(flutterRoot, 'packages', 'flutter');
+    if (!FileSystemEntity.isFileSync(p.join(flutterPackagePath, 'pubspec.yaml'))) {
+      print('Unable to find package:flutter in ${flutterPackagePath}');
+      return 2;
+    }
+
     // TODO: Confirm overwrite of an existing directory with the user.
     Directory out = new Directory(argResults['out']);
 
-    new FlutterSimpleTemplate().generateInto(out);
+    new FlutterSimpleTemplate().generateInto(out, flutterPackagePath);
 
     print('');
 
     String message = '''All done! To run your application:
 
   \$ cd ${out.path}
-  \$ flutter start --checked
+  \$ flutter start
 ''';
 
     if (argResults['pub']) {
@@ -66,14 +80,16 @@
 
   Template(this.name, this.description);
 
-  void generateInto(Directory dir) {
+  void generateInto(Directory dir, String flutterPackagePath) {
     String dirPath = p.normalize(dir.absolute.path);
     String projectName = _normalizeProjectName(p.basename(dirPath));
     print('Creating ${p.basename(projectName)}...');
     dir.createSync(recursive: true);
 
+    String relativeFlutterPackagePath = p.relative(flutterPackagePath, from: dirPath);
+
     files.forEach((String path, String contents) {
-      Map m = {'projectName': projectName, 'description': description};
+      Map m = {'projectName': projectName, 'description': description, 'flutterPackagePath': relativeFlutterPackagePath};
       contents = mustache.render(contents, m);
       path = path.replaceAll('/', Platform.pathSeparator);
       File file = new File(p.join(dir.path, path));
@@ -129,9 +145,8 @@
 name: {{projectName}}
 description: {{description}}
 dependencies:
-  flutter: ">=0.0.2 <0.1.0"
-dev_dependencies:
-  sky_tools: any
+  flutter:
+    path: {{flutterPackagePath}}
 ''';
 
 const String _flutterYaml = r'''
diff --git a/packages/flutter_tools/test/init_test.dart b/packages/flutter_tools/test/init_test.dart
index c14e4f8..f93bf14 100644
--- a/packages/flutter_tools/test/init_test.dart
+++ b/packages/flutter_tools/test/init_test.dart
@@ -6,6 +6,7 @@
 
 import 'package:args/command_runner.dart';
 import 'package:path/path.dart' as p;
+import 'package:sky_tools/src/artifacts.dart';
 import 'package:sky_tools/src/commands/init.dart';
 import 'package:sky_tools/src/process.dart';
 import 'package:test/test.dart';
@@ -29,6 +30,7 @@
     if (!Platform.isWindows) {
       // Verify that we create a project that is well-formed.
       test('flutter-simple', () async {
+        ArtifactStore.flutterRoot = '../..';
         InitCommand command = new InitCommand();
         CommandRunner runner = new CommandRunner('test_flutter', '')
           ..addCommand(command);