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 <crawshaw@golang.org>
This commit is contained in:
Родитель
9c997eaee4
Коммит
696db895ff
|
@ -0,0 +1,25 @@
|
|||
<?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>
|
|
@ -0,0 +1,15 @@
|
|||
#!/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
|
|
@ -0,0 +1,16 @@
|
|||
:: 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
|
До Ширина: | Высота: | Размер: 16 KiB После Ширина: | Высота: | Размер: 16 KiB |
|
@ -0,0 +1,15 @@
|
|||
<?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>
|
|
@ -0,0 +1,11 @@
|
|||
# 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)
|
|
@ -8,7 +8,6 @@ import (
|
|||
"image"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
_ "image/jpeg"
|
||||
|
@ -125,12 +124,13 @@ const (
|
|||
)
|
||||
|
||||
func loadTextures() []sprite.SubTex {
|
||||
f, err := os.Open("../../testdata/waza-gophers.jpeg")
|
||||
a, err := app.Open("waza-gophers.jpeg")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
img, _, err := image.Decode(f)
|
||||
defer a.Close()
|
||||
|
||||
img, _, err := image.Decode(a)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#!/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
|
|
@ -0,0 +1,44 @@
|
|||
:: 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
|
Загрузка…
Ссылка в новой задаче