README.md 3.71 KB
Newer Older
Adam Barth's avatar
Adam Barth committed
1
Getting Started with Sky
2 3 4 5
========================

Sky apps are written in Dart. To get started, we need to set up Dart SDK:

Adam Barth's avatar
Adam Barth committed
6 7
 - Install the [Dart SDK](https://www.dartlang.org/downloads/):
   - Mac: `brew tap dart-lang/dart && brew install dart`
Adam Barth's avatar
Adam Barth committed
8
   - Linux: See [https://www.dartlang.org/downloads/linux.html](https://www.dartlang.org/downloads/linux.html)
9 10
 - Ensure that `$DART_SDK` is set to the path of your Dart SDK and that the
   `dart` and `pub` executables are on your `$PATH`.
11

Adam Barth's avatar
Adam Barth committed
12
Once you have installed Dart SDK, create a new directory and add a
Adam Barth's avatar
Adam Barth committed
13
[pubspec.yaml](https://www.dartlang.org/tools/pub/pubspec.html):
14 15 16 17 18

```yaml
name: your_app_name
dependencies:
  sky: any
Adam Barth's avatar
Adam Barth committed
19
  sky_tools: any
20 21
```

Adam Barth's avatar
Adam Barth committed
22 23
Next, create a `lib` directory (which is where your Dart code will go) and use
the `pub` tool to fetch the Sky package and its dependencies:
24

25
 - `mkdir lib`
Adam Barth's avatar
Adam Barth committed
26
 - `pub upgrade`
27

Adam Barth's avatar
Adam Barth committed
28 29
Sky assumes the entry point for your application is a `main` function in
`lib/main.dart`:
30 31 32 33 34 35

```dart
import 'package:sky/widgets/basic.dart';

class HelloWorldApp extends App {
  Widget build() {
36
    return new Center(child: new Text('Hello, world!'));
37 38 39 40 41 42 43 44
  }
}

void main() {
  runApp(new HelloWorldApp());
}
```

Ian Hickson's avatar
Ian Hickson committed
45
Execution starts in `main`, which in this example runs a new instance of the `HelloWorldApp`.
Ian Hickson's avatar
Ian Hickson committed
46
The `HelloWorldApp` builds a `Text` widget containing the traditional `Hello, world!`
47
string and centers it on the screen using a `Center` widget. To learn more about
48 49
the widget system, please see the
[widgets tutorial](https://github.com/domokit/sky_engine/blob/master/sky/packages/sky/lib/widgets/README.md).
50

Adam Barth's avatar
Adam Barth committed
51
Setting up your Android device
52
-------------------------
53 54 55 56

Currently Sky requires an Android device running the Lollipop (or newer) version
of the Android operating system.

Adam Barth's avatar
Adam Barth committed
57 58 59
 - Install the `adb` tool from the [Android SDK](https://developer.android.com/sdk/installing/index.html?pkg=tools):
  - Mac: `brew install android-platform-tools`
  - Linux: `sudo apt-get install android-tools-adb`
60 61

 - Enable developer mode on your device by visiting `Settings > About phone`
62 63
   and tapping the `Build number` field five times.

Adam Barth's avatar
Adam Barth committed
64
 - Enable `Android debugging` in `Settings > Developer options`.
65

66
 - Using a USB cable, plug your phone into your computer. If prompted on your
67 68 69 70 71 72
   device, authorize your computer to access your device.

Running a Sky application
-------------------------

The `sky` pub package includes a `sky_tool` script to assist in running
Adam Barth's avatar
Adam Barth committed
73
Sky applications inside the `SkyShell.apk` harness.  The `sky_tool` script
74 75 76
expects to be run from the root directory of your application's package (i.e.,
the same directory that contains the `pubspec.yaml` file). To run your app,
follow these instructions:
77

78
 - `./packages/sky/sky_tool start` to start the dev server and upload your
79
   app to the device.
Adam Barth's avatar
Adam Barth committed
80
   (NOTE: add a `--install` flag to install `SkyShell.apk` if it is not already
81 82
   installed on the device.)

83
 - Use `adb logcat` to view any errors or Dart `print()` output from the app.
Collin Jackson's avatar
Collin Jackson committed
84
   `adb logcat -s sky` can be used to filter only adb messages from
Adam Barth's avatar
Adam Barth committed
85
   `SkyShell.apk`.
86 87 88 89 90 91

Debugging
---------

Sky uses [Observatory](https://www.dartlang.org/tools/observatory/) for
debugging and profiling. While running your Sky app using `sky_tool`, you can
92 93
access Observatory by navigating your web browser to
[http://localhost:8181/](http://localhost:8181/).
94 95 96 97 98 99

Building a standalone APK
-------------------------

Although it is possible to build a standalone APK containing your application,
doing so right now is difficult. If you're feeling brave, you can see how we
100 101 102 103
build the `Stocks.apk` in
[example/stocks](https://github.com/domokit/sky_engine/tree/master/sky/packages/sky/example/stocks).
Eventually we plan to make this much easier and support platforms other than
Android, but that work still in progress.