mobilehtml5app

command
v0.0.0-...-8e96db4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2015 License: Apache-2.0 Imports: 14 Imported by: 0

README

This command generates a mobile app project with a Go language HTTP Server backend and a HTML5 Webview frontend

For usage details, refer to the godoc documentation.

Documentation

Overview

Command mobilehtml5app generates a simple framework to develop Go language mobile applications with HTML5 based frontends using WebViews and a golang backend. It currently supports Android only.

Usage

First create a folder within your GOPATH where you want your project to reside and chdir into it. From within this folder run the mobilehtml5app command as discussed in the platform specific sections below. This generates a Go language HTTP server scaffolding for your app and a mobile platform specific App project with a WebView that loads webpages from the server.

Under the hoods, the command will generate a file webapp.go that exports Start() and Stop() functions to start and stop the backend server which are called by lifecycle function hooks of the native portion of the App which houses the webview The file webapp.go also will have two sample handlers to illustrate how to create and register your HTTP handlers. The gomobile bind command is used to generate the required shared library and is hooked up to the native build process to automatically re-build the go shared library.

The webapp uses an server that integrates graceful shutdown and parameterized routing. It requires handlers to satisfy the ContextHandler interface similar to http.Handler but taking a context.Context as the first parameter. Server shutdown is signaled (when the user closes the app etc.) by the Done() channel in the Context being closed and handlers that spawn long-running processes should check for it. Named routing parameters and any custom server instance specific settings are also passed as through the Context and can be accessed via Context.Value(). For more details on the server see http://godoc.org/github.com/srinathh/mobilehtml5app/server

You may want to set the environment variable $GO15VENDOREXPERIMENT=1 to use the vendored versions of the packages github.com/julienschmidt/httprouter and github.com/tylerb/graceful which are used in the Server.

Android apps

To create an Android project run the following command in the project folder you create for your mobile app under your GOPATH.

mobilehtml5app -apitarget <Build API Target> -name <Project Name>

This will generate webapp.go and an Android gradle based project in a subfolder called androidapp. You can build the Android project thorugh the command line. To work with it it in Android Studio, make sure to select "Import Project" in the first screen rather than "Open Project".

There are two options for the WebView - the Android System WebView or the Apache CrossWalk project XWalkView. The Android System WebView is a reliable HTML5 platform only if you are targeting Android Kit-Kat (4.4) or higher devices in which the WebView is based on Chromium. The CrossWalk project XWalkView has compatibility from Android Ice Cream Sandwitch (4.0) version onwards and is the default version used.

The full set of command line options for building Android apps are:

-apitarget string
	Required. Android build target. To list possible targets run
	$ANDROID_HOME/tools/android list targets
-gradle string
	Optional. Gradle version. (default "2.4")
-name string
	Required. Android project name composed of a-z A-Z 0-9 _
-plugin string
	Optional. Android gradle plugin version. (default "1.3.0")
-target string
	Optional. Supports only android for now. (default "android")
-title string
	Optional. App Title defaults to -name if omitted.
-webview string
	Optional. Can be either xwalk (to use CrossWalk XWalkView) or system
	(to use Android WebView). Note that only KitKat (API19) and above
	have a system WebView supporting modern HTML5 capabilities based on
	Chromium and we set 19 as the minSdkVersion. (default "xwalk")

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL