Skip to content

Commit 696db89

Browse files
dopsilvacrawshaw
authored andcommitted
example/sprite: make example lives
Add necessary files to build and run example/sprite. Change main.go to get image from assets. Change-Id: Ic3065aab97f59c34f2c0446ab4b46840305b5864 Reviewed-on: https://go-review.googlesource.com/1882 Reviewed-by: David Crawshaw <[email protected]>
1 parent 9c997ea commit 696db89

File tree

9 files changed

+147
-4
lines changed

9 files changed

+147
-4
lines changed

example/sprite/AndroidManifest.xml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2014 The Go Authors. All rights reserved.
4+
Use of this source code is governed by a BSD-style
5+
license that can be found in the LICENSE file.
6+
-->
7+
<manifest
8+
xmlns:android="http://schemas.android.com/apk/res/android"
9+
package="com.example.sprite"
10+
android:versionCode="1"
11+
android:versionName="1.0">
12+
13+
<uses-sdk android:minSdkVersion="9" />
14+
<application android:label="Sprite" android:hasCode="false">
15+
<activity android:name="android.app.NativeActivity"
16+
android:label="Sprite"
17+
android:configChanges="orientation|keyboardHidden">
18+
<meta-data android:name="android.app.lib_name" android:value="sprite" />
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
</manifest>

example/sprite/all.bash

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

example/sprite/all.bat

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
:: Copyright 2014 The Go Authors. All rights reserved.
2+
:: Use of this source code is governed by a BSD-style
3+
:: license that can be found in the LICENSE file.
4+
5+
@echo off
6+
7+
setlocal
8+
9+
echo # building sprite
10+
call make.bat
11+
12+
echo # installing bin/nativeactivity-debug.apk
13+
adb install -r bin/nativeactivity-debug.apk >nul
14+
15+
echo # starting android.app.NativeActivity
16+
adb shell am start -a android.intent.action.MAIN -n com.example.sprite/android.app.NativeActivity >nul
File renamed without changes.

example/sprite/build.xml

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

example/sprite/jni/Android.mk

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

example/sprite/main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"image"
99
"log"
1010
"math"
11-
"os"
1211
"time"
1312

1413
_ "image/jpeg"
@@ -125,12 +124,13 @@ const (
125124
)
126125

127126
func loadTextures() []sprite.SubTex {
128-
f, err := os.Open("../../testdata/waza-gophers.jpeg")
127+
a, err := app.Open("waza-gophers.jpeg")
129128
if err != nil {
130129
log.Fatal(err)
131130
}
132-
defer f.Close()
133-
img, _, err := image.Decode(f)
131+
defer a.Close()
132+
133+
img, _, err := image.Decode(a)
134134
if err != nil {
135135
log.Fatal(err)
136136
}

example/sprite/make.bash

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

example/sprite/make.bat

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
:: Copyright 2014 The Go Authors. All rights reserved.
2+
:: Use of this source code is governed by a BSD-style
3+
:: license that can be found in the LICENSE file.
4+
5+
@echo off
6+
7+
setlocal
8+
9+
if not exist make.bat goto error-invalid-path
10+
11+
if not exist jni\armeabi mkdir jni\armeabi
12+
13+
set CGO_ENABLED=1
14+
set GOOS=android
15+
set GOARCH=arm
16+
set GOARM=7
17+
18+
go build -ldflags="-shared" -o jni/armeabi/libsprite.so .
19+
if errorlevel 1 goto error-go-build
20+
21+
if defined NDK_ROOT goto ndk-build
22+
echo NDK_ROOT path not defined
23+
goto end
24+
25+
:ndk-build
26+
call %NDK_ROOT%\ndk-build.cmd NDK_DEBUG=1 >nul
27+
28+
if defined ANT_HOME goto ant-build
29+
echo ANT_HOME path not defined
30+
goto end
31+
32+
:ant-build
33+
call %ANT_HOME%\bin\ant.bat debug >nul
34+
goto end
35+
36+
:error-invalid-path
37+
echo make.bat must be run from %%GOPATH%%\src\golang.org\x\mobile\example\sprite
38+
goto end
39+
40+
:error-go-build
41+
echo Error building go lib
42+
goto end
43+
44+
:end

0 commit comments

Comments
 (0)