More work on Android building...

This commit is contained in:
Ray San 2017-10-10 14:06:21 +02:00
parent 2051be3825
commit ef6674a99d
19 changed files with 116 additions and 37 deletions

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
* raylib Android project template
*
* This template has been created using raylib 1.8 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014-2017 Ramon Santamaria (@raysan5)
*
-->
<!-- NOTE: Game package name must be unique for every app/game -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.raylib.game_sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="16" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<!--<supports-gl-texture android:name="GL_OES_compressed_ETC1_RGB8_texture" android:required="true"/>-->
<!-- We do not have Java code. Therefore android:hasCode is set to false. -->
<!-- <application android:allowBackup="false" android:hasCode="false" -->
<application android:allowBackup="false"
android:label="@string/app_name"
android:icon="@drawable/icon" >
<!-- Our activity is the built-in NativeActivity framework class. -->
<!-- <activity android:name="android.app.NativeActivity" -->
<activity android:name="com.raylib.game_sample.NativeLoader"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="landscape"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true" >
<!-- android:screenOrientation="portrait" -->
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name" android:value="raylib_game" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -20,15 +20,16 @@
<!-- We do not have Java code. Therefore android:hasCode is set to false. --> <!-- We do not have Java code. Therefore android:hasCode is set to false. -->
<application android:allowBackup="false" android:hasCode="false" <application android:allowBackup="false" android:hasCode="false"
android:label="@string/app_name" android:label="@string/app_name"
android:icon="@drawable/icon" android:icon="@drawable/icon" >
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
<!-- Our activity is the built-in NativeActivity framework class. --> <!-- Our activity is the built-in NativeActivity framework class. -->
<activity android:name="android.app.NativeActivity" <activity android:name="android.app.NativeActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|keyboardHidden|screenSize" android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="landscape" android:screenOrientation="landscape"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true" > android:clearTaskOnLaunch="true" >
<!-- android:theme="@android:style/Theme.NoTitleBar.Fullscreen" -->
<!-- android:screenOrientation="portrait" --> <!-- android:screenOrientation="portrait" -->
<!-- Tell NativeActivity the name of our .so --> <!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name" android:value="raylib_game" /> <meta-data android:name="android.app.lib_name" android:value="raylib_game" />
<intent-filter> <intent-filter>

View File

@ -25,8 +25,9 @@
PLATFORM ?= PLATFORM_ANDROID PLATFORM ?= PLATFORM_ANDROID
# Android project name (.apk) # Android project name (.apk)
PROJECT_NAME = raylibGame PROJECT_NAME = raylib_game
PROJECT_DIR = ./ OUTPUT_PATH = output
SOURCE_PATH = src
# Generated shared library name # Generated shared library name
# NOTE: It should match the name defined in the AndroidManifest.xml # NOTE: It should match the name defined in the AndroidManifest.xml
@ -36,11 +37,17 @@ LIBRARY_NAME = raylib_game
RAYLIB_LIBTYPE ?= STATIC RAYLIB_LIBTYPE ?= STATIC
OPENAL_LIBTYPE ?= STATIC OPENAL_LIBTYPE ?= STATIC
LIBS_PATH = libs\static
# add shared libs to APK if required # add shared libs to APK if required
ifeq ($(RAYLIB_LIBTYPE),SHARED) ifeq ($(RAYLIB_LIBTYPE),SHARED)
LIBS_PATH = libs\shared
NATIVE_LOADER = NativeLoader.java
PROJECT_SHARED_LIBS = lib/armeabi-v7a/libraylib.so PROJECT_SHARED_LIBS = lib/armeabi-v7a/libraylib.so
endif endif
ifeq ($(OPENAL_LIBTYPE),SHARED) ifeq ($(OPENAL_LIBTYPE),SHARED)
LIBS_PATH = libs\shared
NATIVE_LOADER = NativeLoader.java
PROJECT_SHARED_LIBS += lib/armeabi-v7a/libopenal.so PROJECT_SHARED_LIBS += lib/armeabi-v7a/libopenal.so
endif endif
@ -70,7 +77,7 @@ CFLAGS += -Wall -Wa,--noexecstack -Wformat -Werror=format-security -no-canonical
CFLAGS += -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=16 CFLAGS += -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=16
# Paths containing required header files # Paths containing required header files
INCLUDE_PATHS = -I. -Isrc/include -I$(ANDROID_NDK)/sources/android/native_app_glue INCLUDE_PATHS = -I. -Iinclude -I$(ANDROID_NDK)/sources/android/native_app_glue
# Linker options # Linker options
LDFLAGS = -Wl,-soname,lib$(LIBRARY_NAME).so -Wl,--exclude-libs,libatomic.a LDFLAGS = -Wl,-soname,lib$(LIBRARY_NAME).so -Wl,--exclude-libs,libatomic.a
@ -78,7 +85,7 @@ LDFLAGS += -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl
# Force linking of library module to define symbol # Force linking of library module to define symbol
LDFLAGS += -u ANativeActivity_onCreate LDFLAGS += -u ANativeActivity_onCreate
# Library paths containing required libs # Library paths containing required libs
LDFLAGS += -L. -Lsrc -Llib -Lsrc/libs LDFLAGS += -L. -L$(SOURCE_PATH) -L$(LIBS_PATH) -L$(OUTPUT_PATH)/obj
# Define any libraries to link into executable # Define any libraries to link into executable
# if you want to link libraries (libname.so or libname.a), use the -lname # if you want to link libraries (libname.so or libname.a), use the -lname
@ -90,6 +97,7 @@ all: create_temp_project_dirs \
compile_native_app_glue \ compile_native_app_glue \
compile_project_code \ compile_project_code \
copy_project_shared_libs \ copy_project_shared_libs \
copy_project_resources \
config_project_package \ config_project_package \
compile_project_class \ compile_project_class \
compile_project_class_dex \ compile_project_class_dex \
@ -100,77 +108,92 @@ all: create_temp_project_dirs \
# Create required temp directories for APK building # Create required temp directories for APK building
create_temp_project_dirs: create_temp_project_dirs:
if not exist temp mkdir temp if not exist $(OUTPUT_PATH) mkdir $(OUTPUT_PATH)
if not exist temp\obj mkdir temp\obj if not exist $(OUTPUT_PATH)\obj mkdir $(OUTPUT_PATH)\obj
if not exist temp\src mkdir temp\src if not exist $(OUTPUT_PATH)\src mkdir $(OUTPUT_PATH)\src
if not exist lib mkdir lib if not exist $(OUTPUT_PATH)\lib mkdir $(OUTPUT_PATH)\lib
if not exist lib\armeabi-v7a mkdir lib\armeabi-v7a if not exist $(OUTPUT_PATH)\lib\armeabi-v7a mkdir $(OUTPUT_PATH)\lib\armeabi-v7a
if not exist temp\bin mkdir temp\bin if not exist $(OUTPUT_PATH)\bin mkdir $(OUTPUT_PATH)\bin
if not exist $(OUTPUT_PATH)\res mkdir $(OUTPUT_PATH)\res
if not exist $(OUTPUT_PATH)\assets mkdir $(OUTPUT_PATH)\assets
# Compile native_app_glue as static library # Compile native_app_glue as static library
# OUTPUT: $(PROJECT_DIR)/temp/obj/libnative_app_glue.a # OUTPUT: $(PROJECT_DIR)/obj/libnative_app_glue.a
compile_native_app_glue: compile_native_app_glue:
$(CC) -c $(ANDROID_NDK)/sources/android/native_app_glue/android_native_app_glue.c -o temp/obj/native_app_glue.o $(CFLAGS) $(CC) -c $(ANDROID_NDK)/sources/android/native_app_glue/android_native_app_glue.c -o $(OUTPUT_PATH)/obj/native_app_glue.o $(CFLAGS)
$(AR) rcs $(PROJECT_DIR)/lib/libnative_app_glue.a temp/obj/native_app_glue.o $(AR) rcs $(OUTPUT_PATH)/obj/libnative_app_glue.a $(OUTPUT_PATH)/obj/native_app_glue.o
# Compile project code as shared libraries # Compile project code as shared libraries
# OUTPUT: $(PROJECT_DIR)/lib/lib$(LIBRARY_NAME).so # OUTPUT: $(PROJECT_DIR)/lib/lib$(LIBRARY_NAME).so
compile_project_code: compile_project_code:
$(CC) -c src/game_basic.c -o temp/obj/game_basic.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot $(CC) -c $(SOURCE_PATH)/game_basic.c -o $(OUTPUT_PATH)/obj/game_basic.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot
$(CC) -o lib/armeabi-v7a/lib$(LIBRARY_NAME).so temp/obj/game_basic.o -shared $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) $(CC) -o $(OUTPUT_PATH)/lib/armeabi-v7a/lib$(LIBRARY_NAME).so $(OUTPUT_PATH)/obj/game_basic.o -shared $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS)
compile_project_code_raylib_stripped: compile_project_code_raylib_stripped:
$(CC) -c src/raylib_stripped/core.c -o temp/obj/core.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot $(CC) -c $(SOURCE_PATH)/raylib_stripped/core.c -o $(OUTPUT_PATH)/obj/core.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot
$(CC) -c src/raylib_stripped/rlgl.c -o temp/obj/rlgl.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot -DGRAPHICS_API_OPENGL_ES2 $(CC) -c $(SOURCE_PATH)/raylib_stripped/rlgl.c -o $(OUTPUT_PATH)/obj/rlgl.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot -DGRAPHICS_API_OPENGL_ES2
$(CC) -c src/raylib_stripped/utils.c -o temp/obj/utils.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot $(CC) -c $(SOURCE_PATH)/raylib_stripped/utils.c -o $(OUTPUT_PATH)/obj/utils.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot
$(CC) -c src/game_raylib_stripped.c -o temp/obj/game_raylib_stripped.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot $(CC) -c $(SOURCE_PATH)/game_raylib_stripped.c -o $(OUTPUT_PATH)/obj/game_raylib_stripped.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot
$(CC) -o lib/armeabi-v7a/lib$(LIBRARY_NAME).so temp/obj/game_raylib_stripped.o temp/obj/core.o temp/obj/rlgl.o temp/obj/utils.o -shared $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) $(CC) -o lib/armeabi-v7a/lib$(LIBRARY_NAME).so $(OUTPUT_PATH)/obj/game_raylib_stripped.o $(OUTPUT_PATH)/obj/core.o $(OUTPUT_PATH)/obj/rlgl.o $(OUTPUT_PATH)/obj/utils.o -shared $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS)
copy_project_shared_libs: copy_project_shared_libs:
ifeq ($(RAYLIB_LIBTYPE),SHARED) ifeq ($(RAYLIB_LIBTYPE),SHARED)
copy /Y src\libs_shared\libraylib.so lib\armeabi-v7a\libraylib.so copy /Y $(LIBS_PATH)\libraylib.so $(OUTPUT_PATH)\lib\armeabi-v7a\libraylib.so
endif endif
ifeq ($(OPENAL_LIBTYPE),SHARED) ifeq ($(OPENAL_LIBTYPE),SHARED)
copy /Y src\libs_shared\libopenal.so lib\armeabi-v7a\libopenal.so copy /Y $(LIBS_PATH)\libopenal.so $(OUTPUT_PATH)\lib\armeabi-v7a\libopenal.so
endif endif
copy_project_resources:
xcopy res $(OUTPUT_PATH)\res /Y /E /F
xcopy src\resources $(OUTPUT_PATH)\assets /Y /E /F
ifeq ($(RAYLIB_LIBTYPE),SHARED)
xcopy AndroidManifest_shared.xml $(OUTPUT_PATH)\AndroidManifest.xml* /Y /F
endif
ifeq ($(RAYLIB_LIBTYPE),STATIC)
xcopy AndroidManifest_static.xml $(OUTPUT_PATH)\AndroidManifest.xml* /Y /F
endif
generate_loader_script:
@echo "package com.raylib.game_sample; public class NativeLoader extends android.app.NativeActivity { static { System.loadLibrary("openal"); System.loadLibrary("raylib"); System.loadLibrary("raylib_game"); }}" > $(OUTPUT_PATH)/obj/NativeLoader.java
# Generate key for APK signing # Generate key for APK signing
# OUTPUT: $(PROJECT_DIR)/temp/$(PROJECT_NAME).keystore # OUTPUT: $(PROJECT_DIR)/temp/$(PROJECT_NAME).keystore
generate_apk_keystore: generate_apk_keystore:
$(JAVA_HOME)/bin/keytool -genkeypair -validity 1000 -dname "CN=raylib,O=Android,C=JPN" -keystore temp/$(PROJECT_NAME).keystore -storepass $(KEYSTORE_PASS) -keypass $(KEYSTORE_PASS) -alias $(PROJECT_NAME)Key -keyalg RSA $(JAVA_HOME)/bin/keytool -genkeypair -validity 1000 -dname "CN=raylib,O=Android,C=JPN" -keystore $(OUTPUT_PATH)/$(PROJECT_NAME).keystore -storepass $(KEYSTORE_PASS) -keypass $(KEYSTORE_PASS) -alias $(PROJECT_NAME)Key -keyalg RSA
# Create temp/src/com/raylib/$(LIBRARY_NAME)/R.java # Create temp/src/com/raylib/$(LIBRARY_NAME)/R.java
# OUTPUT: $(PROJECT_DIR)/temp/src/com/raylib/$(LIBRARY_NAME)/R.java # OUTPUT: $(PROJECT_DIR)/temp/src/com/raylib/$(LIBRARY_NAME)/R.java
# NOTE: DEPENDS on res/values/strings.xml # NOTE: DEPENDS on res/values/strings.xml
config_project_package: config_project_package:
$(ANDROID_BUILD_TOOLS)/aapt package -v -f -m -S res -J temp/src -M AndroidManifest.xml -I $(ANDROID_HOME)/platforms/android-16/android.jar $(ANDROID_BUILD_TOOLS)/aapt package -f -m -S $(OUTPUT_PATH)/res -J $(OUTPUT_PATH)/src -M $(OUTPUT_PATH)/AndroidManifest.xml -I $(ANDROID_HOME)/platforms/android-16/android.jar
# Create temp/obj/com/raylib/$(LIBRARY_NAME)/R.class # Create temp/obj/com/raylib/$(LIBRARY_NAME)/R.class
# OUTPUT: $(PROJECT_DIR)/temp/obj/com/raylib/$(LIBRARY_NAME)/R.class # OUTPUT: $(PROJECT_DIR)/temp/obj/com/raylib/$(LIBRARY_NAME)/R.class
compile_project_class: compile_project_class:
$(JAVA_HOME)/bin/javac -verbose -source 1.7 -target 1.7 -d temp/obj -bootclasspath $(JAVA_HOME)/jre/lib/rt.jar -classpath $(ANDROID_HOME)/platforms/android-16/android.jar;temp/obj -sourcepath temp/src temp/src/com/raylib/game_sample/R.java $(JAVA_HOME)/bin/javac -verbose -source 1.7 -target 1.7 -d $(OUTPUT_PATH)/obj -bootclasspath $(JAVA_HOME)/jre/lib/rt.jar -classpath $(ANDROID_HOME)/platforms/android-16/android.jar;$(OUTPUT_PATH)/obj -sourcepath $(OUTPUT_PATH)/src $(OUTPUT_PATH)/src/com/raylib/game_sample/R.java $(NATIVE_LOADER)
#$(JAVA_HOME)/bin/javac -source 1.7 -target 1.7 -d temp/obj -bootclasspath $(JAVA_HOME)/jre/lib/rt.jar -classpath $(ANDROID_HOME)/platforms/android-16/android.jar -sourcepath temp/src temp/src/com/raylib/game_sample/R.java #$(JAVA_HOME)/bin/javac -source 1.7 -target 1.7 -d temp/obj -bootclasspath $(JAVA_HOME)/jre/lib/rt.jar -classpath $(ANDROID_HOME)/platforms/android-16/android.jar -sourcepath temp/src temp/src/com/raylib/game_sample/R.java
# Create temp/bin/classes.dex # Create temp/bin/classes.dex
# OUTPUT: $(PROJECT_DIR)/bin/classes.dex # OUTPUT: $(PROJECT_DIR)/bin/classes.dex
# NOTE: DEPENDS on temp/obj/com/raylib/$(LIBRARY_NAME)/R.class # NOTE: DEPENDS on temp/obj/com/raylib/$(LIBRARY_NAME)/R.class
compile_project_class_dex: compile_project_class_dex:
$(ANDROID_BUILD_TOOLS)/dx --verbose --dex --output=temp/bin/classes.dex temp/obj $(ANDROID_BUILD_TOOLS)/dx --verbose --dex --output=$(OUTPUT_PATH)/bin/classes.dex $(OUTPUT_PATH)/obj
# Create temp/bin/$(PROJECT_NAME).unsigned.apk # Create temp/bin/$(PROJECT_NAME).unsigned.apk
# NOTE: DEPENDS on temp/bin/classes.dex and lib/lib$(LIBRARY_NAME).so # NOTE: DEPENDS on temp/bin/classes.dex and lib/lib$(LIBRARY_NAME).so
# NOTE: Use -A resources to define additional directory in which to find raw asset files # NOTE: Use -A resources to define additional directory in which to find raw asset files
create_project_apk_package: create_project_apk_package:
$(ANDROID_BUILD_TOOLS)/aapt package -v -f -M AndroidManifest.xml -S res -A assets -I $(ANDROID_HOME)/platforms/android-16/android.jar -F temp/bin/$(PROJECT_NAME).unsigned.apk temp/bin $(ANDROID_BUILD_TOOLS)/aapt package -f -M $(OUTPUT_PATH)/AndroidManifest.xml -S $(OUTPUT_PATH)/res -A $(OUTPUT_PATH)/assets -I $(ANDROID_HOME)/platforms/android-16/android.jar -F $(OUTPUT_PATH)/bin/$(PROJECT_NAME).unsigned.apk $(OUTPUT_PATH)/bin
$(ANDROID_BUILD_TOOLS)/aapt add -v $(PROJECT_DIR)/temp/bin/$(PROJECT_NAME).unsigned.apk lib/armeabi-v7a/lib$(LIBRARY_NAME).so $(PROJECT_SHARED_LIBS) cd $(OUTPUT_PATH) && $(ANDROID_BUILD_TOOLS)/aapt add bin/$(PROJECT_NAME).unsigned.apk lib/armeabi-v7a/lib$(LIBRARY_NAME).so $(PROJECT_SHARED_LIBS)
# Create temp/bin/$(PROJECT_NAME).signed.apk # Create temp/bin/$(PROJECT_NAME).signed.apk
sign_project_apk_package: sign_project_apk_package:
$(JAVA_HOME)/bin/jarsigner -keystore temp/$(PROJECT_NAME).keystore -storepass $(KEYSTORE_PASS) -keypass $(KEYSTORE_PASS) -signedjar $(PROJECT_DIR)/temp/bin/$(PROJECT_NAME).signed.apk temp/bin/$(PROJECT_NAME).unsigned.apk $(PROJECT_NAME)Key $(JAVA_HOME)/bin/jarsigner -keystore $(OUTPUT_PATH)/$(PROJECT_NAME).keystore -storepass $(KEYSTORE_PASS) -keypass $(KEYSTORE_PASS) -signedjar $(OUTPUT_PATH)/bin/$(PROJECT_NAME).signed.apk $(OUTPUT_PATH)/bin/$(PROJECT_NAME).unsigned.apk $(PROJECT_NAME)Key
# Create temp/bin/$(PROJECT_NAME).apk # Create temp/bin/$(PROJECT_NAME).apk
zipalign_project_apk_package: zipalign_project_apk_package:
$(ANDROID_BUILD_TOOLS)/zipalign -f 4 temp/bin/$(PROJECT_NAME).signed.apk $(PROJECT_NAME).apk $(ANDROID_BUILD_TOOLS)/zipalign -f 4 $(OUTPUT_PATH)/bin/$(PROJECT_NAME).signed.apk $(PROJECT_NAME).apk
# Deploy $(PROJECT_NAME).apk to device # Deploy $(PROJECT_NAME).apk to device
install_project_apk_package: install_project_apk_package:
@ -183,7 +206,7 @@ logcat_project_apk_package:
deploy: deploy:
$(ANDROID_PLATFORM_TOOLS)/adb install -r $(PROJECT_NAME).apk $(ANDROID_PLATFORM_TOOLS)/adb install -r $(PROJECT_NAME).apk
$(ANDROID_PLATFORM_TOOLS)/adb logcat -c $(ANDROID_PLATFORM_TOOLS)/adb logcat -c
$(ANDROID_PLATFORM_TOOLS)/adb logcat raylib:V *:S $(ANDROID_PLATFORM_TOOLS)/adb logcat *:W
#$(ANDROID_PLATFORM_TOOLS)/adb logcat *:W #$(ANDROID_PLATFORM_TOOLS)/adb logcat *:W
#$(ANDROID_PLATFORM_TOOLS)/adb -d logcat raylib:V *:S #$(ANDROID_PLATFORM_TOOLS)/adb -d logcat raylib:V *:S

View File

@ -0,0 +1,11 @@
package com.raylib.game_sample;
public class NativeLoader extends android.app.NativeActivity
{
static
{
System.loadLibrary("openal");
System.loadLibrary("raylib");
System.loadLibrary("raylib_game");
}
}

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB