example/sprite: switch to gomobile build

Fixes #10523.

Change-Id: Ic0bf345624f6584757e2af5cb91a679827ee3b13
Reviewed-on: https://go-review.googlesource.com/9340
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Burcu Dogan 2015-04-24 17:04:45 -07:00
parent 717c2c4312
commit 1cb3b97c74
8 changed files with 59 additions and 143 deletions

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sprite"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<application android:label="Sprite" android:hasCode="false">
<activity android:name="android.app.NativeActivity"
android:label="Sprite"
android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.lib_name" android:value="sprite" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -1,15 +0,0 @@
#!/usr/bin/env bash
# Copyright 2014 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# Script to build and launch the app on an android device.
set -e
./make.bash
adb install -r bin/nativeactivity-debug.apk
adb shell am start -a android.intent.action.MAIN \
-n com.example.sprite/android.app.NativeActivity

View File

@ -1,16 +0,0 @@
:: Copyright 2014 The Go Authors. All rights reserved.
:: Use of this source code is governed by a BSD-style
:: license that can be found in the LICENSE file.
@echo off
setlocal
echo # building sprite
call make.bat
echo # installing bin/nativeactivity-debug.apk
adb install -r bin/nativeactivity-debug.apk >nul
echo # starting android.app.NativeActivity
adb shell am start -a android.intent.action.MAIN -n com.example.sprite/android.app.NativeActivity >nul

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<project name="nativeactivity" default="help">
<property name="target" value="android-19" />
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<fail message="missing ANDROID_HOME env variable" unless="sdk.dir" />
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View File

@ -1,11 +0,0 @@
# Copyright 2014 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := sprite
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libsprite.so
include $(PREBUILT_SHARED_LIBRARY)

View File

@ -2,6 +2,65 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// TODO(jbd): Refer to http://golang.org/doc/install/source
// once Go 1.5 instructions are complete.
// An app that demonstrates the sprite package.
//
// Note: This demo is an early preview of Go 1.5. In order to build this
// program as an Android APK using the gomobile tool, you need to install
// Go 1.5 from the source.
//
// Clone the source from the tip under $HOME/go directory. On Windows,
// you may like to clone the repo to your user folder, %USERPROFILE%\go.
//
// $ git clone https://go.googlesource.com/go $HOME/go
//
// Go 1.5 requires Go 1.4. Read more about this requirement at
// http://golang.org/s/go15bootstrap.
// Set GOROOT_BOOTSTRAP to the GOROOT of your existing 1.4 installation or
// follow the steps below to checkout go1.4 from the source and build.
//
// $ git clone https://go.googlesource.com/go $HOME/go1.4
// $ cd $HOME/go1.4
// $ git checkout go1.4.1
// $ cd src && ./make.bash
//
// If you clone Go 1.4 to a different destination, set GOROOT_BOOTSTRAP
// environmental variable accordingly.
//
// Build Go 1.5 and add Go 1.5 bin to your path.
//
// $ cd $HOME/go/src && ./make.bash
// $ export PATH=$PATH:$HOME/go/bin
//
// Set a GOPATH if no GOPATH is set, add $GOPATH/bin to your path.
//
// $ export GOPATH=$HOME
// $ export PATH=$PATH:$GOPATH/bin
//
// Get the gomobile tool and initialize.
//
// $ go get golang.org/x/mobile/cmd/gomobile
// $ gomobile init
//
// It may take a while to initialize gomobile, please wait.
//
// Get the sprite example and use gomobile to build or install it on your device.
//
// $ go get -d golang.org/x/mobile/example/sprite
// $ gomobile build golang.org/x/mobile/example/sprite # will build an APK
//
// # plug your Android device to your computer or start an Android emulator.
// # if you have adb installed on your machine, use gomobile install to
// # build and deploy the APK to an Android target.
// $ gomobile install golang.org/x/mobile/example/sprite
//
// Switch to your device or emulator to start the Basic application from
// the launcher.
// You can also run the application on your desktop by running the command
// below. (Note: It currently doesn't work on Windows.)
// $ go install golang.org/x/mobile/example/sprite && sprite
package main
import (

View File

@ -1,17 +0,0 @@
#!/usr/bin/env bash
# Copyright 2014 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
set -e
if [ ! -f make.bash ]; then
echo 'make.bash must be run from $GOPATH/src/golang.org/x/mobile/example/sprite'
exit 1
fi
mkdir -p jni/armeabi
CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 \
go build -ldflags="-shared" -o jni/armeabi/libsprite.so .
ndk-build NDK_DEBUG=1
ant debug

View File

@ -1,44 +0,0 @@
:: Copyright 2014 The Go Authors. All rights reserved.
:: Use of this source code is governed by a BSD-style
:: license that can be found in the LICENSE file.
@echo off
setlocal
if not exist make.bat goto error-invalid-path
if not exist jni\armeabi mkdir jni\armeabi
set CGO_ENABLED=1
set GOOS=android
set GOARCH=arm
set GOARM=7
go build -ldflags="-shared" -o jni/armeabi/libsprite.so .
if errorlevel 1 goto error-go-build
if defined NDK_ROOT goto ndk-build
echo NDK_ROOT path not defined
goto end
:ndk-build
call %NDK_ROOT%\ndk-build.cmd NDK_DEBUG=1 >nul
if defined ANT_HOME goto ant-build
echo ANT_HOME path not defined
goto end
:ant-build
call %ANT_HOME%\bin\ant.bat debug >nul
goto end
:error-invalid-path
echo make.bat must be run from %%GOPATH%%\src\golang.org\x\mobile\example\sprite
goto end
:error-go-build
echo Error building go lib
goto end
:end