diff --git a/templates/android_project/AndroidManifest_shared.xml b/templates/android_project/AndroidManifest_shared.xml new file mode 100644 index 00000000..b842c0a4 --- /dev/null +++ b/templates/android_project/AndroidManifest_shared.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/android_project/AndroidManifest.xml b/templates/android_project/AndroidManifest_static.xml similarity index 88% rename from templates/android_project/AndroidManifest.xml rename to templates/android_project/AndroidManifest_static.xml index d1bad411..414bf893 100644 --- a/templates/android_project/AndroidManifest.xml +++ b/templates/android_project/AndroidManifest_static.xml @@ -18,17 +18,18 @@ - + android:icon="@drawable/icon" > - + diff --git a/templates/android_project/Makefile b/templates/android_project/Makefile index 05e64925..6c36f504 100644 --- a/templates/android_project/Makefile +++ b/templates/android_project/Makefile @@ -25,8 +25,9 @@ PLATFORM ?= PLATFORM_ANDROID # Android project name (.apk) -PROJECT_NAME = raylibGame -PROJECT_DIR = ./ +PROJECT_NAME = raylib_game +OUTPUT_PATH = output +SOURCE_PATH = src # Generated shared library name # NOTE: It should match the name defined in the AndroidManifest.xml @@ -36,11 +37,17 @@ LIBRARY_NAME = raylib_game RAYLIB_LIBTYPE ?= STATIC OPENAL_LIBTYPE ?= STATIC +LIBS_PATH = libs\static + # add shared libs to APK if required ifeq ($(RAYLIB_LIBTYPE),SHARED) + LIBS_PATH = libs\shared + NATIVE_LOADER = NativeLoader.java PROJECT_SHARED_LIBS = lib/armeabi-v7a/libraylib.so endif ifeq ($(OPENAL_LIBTYPE),SHARED) + LIBS_PATH = libs\shared + NATIVE_LOADER = NativeLoader.java PROJECT_SHARED_LIBS += lib/armeabi-v7a/libopenal.so endif @@ -70,7 +77,7 @@ CFLAGS += -Wall -Wa,--noexecstack -Wformat -Werror=format-security -no-canonical CFLAGS += -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=16 # 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 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 LDFLAGS += -u ANativeActivity_onCreate # 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 # 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_project_code \ copy_project_shared_libs \ + copy_project_resources \ config_project_package \ compile_project_class \ compile_project_class_dex \ @@ -100,77 +108,92 @@ all: create_temp_project_dirs \ # Create required temp directories for APK building create_temp_project_dirs: - if not exist temp mkdir temp - if not exist temp\obj mkdir temp\obj - if not exist temp\src mkdir temp\src - if not exist lib mkdir lib - if not exist lib\armeabi-v7a mkdir lib\armeabi-v7a - if not exist temp\bin mkdir temp\bin - + if not exist $(OUTPUT_PATH) mkdir $(OUTPUT_PATH) + if not exist $(OUTPUT_PATH)\obj mkdir $(OUTPUT_PATH)\obj + if not exist $(OUTPUT_PATH)\src mkdir $(OUTPUT_PATH)\src + if not exist $(OUTPUT_PATH)\lib mkdir $(OUTPUT_PATH)\lib + if not exist $(OUTPUT_PATH)\lib\armeabi-v7a mkdir $(OUTPUT_PATH)\lib\armeabi-v7a + 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 -# OUTPUT: $(PROJECT_DIR)/temp/obj/libnative_app_glue.a +# OUTPUT: $(PROJECT_DIR)/obj/libnative_app_glue.a 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) - $(AR) rcs $(PROJECT_DIR)/lib/libnative_app_glue.a temp/obj/native_app_glue.o + $(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 $(OUTPUT_PATH)/obj/libnative_app_glue.a $(OUTPUT_PATH)/obj/native_app_glue.o # Compile project code as shared libraries # OUTPUT: $(PROJECT_DIR)/lib/lib$(LIBRARY_NAME).so compile_project_code: - $(CC) -c src/game_basic.c -o temp/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) -c $(SOURCE_PATH)/game_basic.c -o $(OUTPUT_PATH)/obj/game_basic.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot + $(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: - $(CC) -c src/raylib_stripped/core.c -o temp/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 src/raylib_stripped/utils.c -o temp/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) -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) -c $(SOURCE_PATH)/raylib_stripped/core.c -o $(OUTPUT_PATH)/obj/core.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot + $(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 $(SOURCE_PATH)/raylib_stripped/utils.c -o $(OUTPUT_PATH)/obj/utils.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 $(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: 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 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 - + +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 # OUTPUT: $(PROJECT_DIR)/temp/$(PROJECT_NAME).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 # OUTPUT: $(PROJECT_DIR)/temp/src/com/raylib/$(LIBRARY_NAME)/R.java # NOTE: DEPENDS on res/values/strings.xml 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 # OUTPUT: $(PROJECT_DIR)/temp/obj/com/raylib/$(LIBRARY_NAME)/R.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 # Create temp/bin/classes.dex # OUTPUT: $(PROJECT_DIR)/bin/classes.dex # NOTE: DEPENDS on temp/obj/com/raylib/$(LIBRARY_NAME)/R.class 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 # 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 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 add -v $(PROJECT_DIR)/temp/bin/$(PROJECT_NAME).unsigned.apk lib/armeabi-v7a/lib$(LIBRARY_NAME).so $(PROJECT_SHARED_LIBS) + $(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 + 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 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 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 install_project_apk_package: @@ -183,7 +206,7 @@ logcat_project_apk_package: deploy: $(ANDROID_PLATFORM_TOOLS)/adb install -r $(PROJECT_NAME).apk $(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 -d logcat raylib:V *:S diff --git a/templates/android_project/NativeLoader.java b/templates/android_project/NativeLoader.java new file mode 100644 index 00000000..ebbc1800 --- /dev/null +++ b/templates/android_project/NativeLoader.java @@ -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"); + } + } \ No newline at end of file diff --git a/templates/android_project/src/include/AL/al.h b/templates/android_project/include/AL/al.h similarity index 100% rename from templates/android_project/src/include/AL/al.h rename to templates/android_project/include/AL/al.h diff --git a/templates/android_project/src/include/AL/alc.h b/templates/android_project/include/AL/alc.h similarity index 100% rename from templates/android_project/src/include/AL/alc.h rename to templates/android_project/include/AL/alc.h diff --git a/templates/android_project/src/include/AL/alext.h b/templates/android_project/include/AL/alext.h similarity index 100% rename from templates/android_project/src/include/AL/alext.h rename to templates/android_project/include/AL/alext.h diff --git a/templates/android_project/src/include/AL/efx-creative.h b/templates/android_project/include/AL/efx-creative.h similarity index 100% rename from templates/android_project/src/include/AL/efx-creative.h rename to templates/android_project/include/AL/efx-creative.h diff --git a/templates/android_project/src/include/AL/efx-presets.h b/templates/android_project/include/AL/efx-presets.h similarity index 100% rename from templates/android_project/src/include/AL/efx-presets.h rename to templates/android_project/include/AL/efx-presets.h diff --git a/templates/android_project/src/include/AL/efx.h b/templates/android_project/include/AL/efx.h similarity index 100% rename from templates/android_project/src/include/AL/efx.h rename to templates/android_project/include/AL/efx.h diff --git a/templates/android_project/src/include/raylib.h b/templates/android_project/include/raylib.h similarity index 100% rename from templates/android_project/src/include/raylib.h rename to templates/android_project/include/raylib.h diff --git a/templates/android_project/src/libs/libopenal.a b/templates/android_project/src/libs/libopenal.a deleted file mode 100644 index ffc90321..00000000 Binary files a/templates/android_project/src/libs/libopenal.a and /dev/null differ diff --git a/templates/android_project/src/libs/libraylib.a b/templates/android_project/src/libs/libraylib.a deleted file mode 100644 index 3406efc6..00000000 Binary files a/templates/android_project/src/libs/libraylib.a and /dev/null differ diff --git a/templates/android_project/src/libs_shared/libopenal.a b/templates/android_project/src/libs_shared/libopenal.a deleted file mode 100644 index ffc90321..00000000 Binary files a/templates/android_project/src/libs_shared/libopenal.a and /dev/null differ diff --git a/templates/android_project/src/libs_shared/libopenal.so b/templates/android_project/src/libs_shared/libopenal.so deleted file mode 100644 index d0f913a6..00000000 Binary files a/templates/android_project/src/libs_shared/libopenal.so and /dev/null differ diff --git a/templates/android_project/src/libs_shared/libraylib.a b/templates/android_project/src/libs_shared/libraylib.a deleted file mode 100644 index 3406efc6..00000000 Binary files a/templates/android_project/src/libs_shared/libraylib.a and /dev/null differ diff --git a/templates/android_project/assets/ambient.ogg b/templates/android_project/src/resources/ambient.ogg similarity index 100% rename from templates/android_project/assets/ambient.ogg rename to templates/android_project/src/resources/ambient.ogg diff --git a/templates/android_project/assets/coin.wav b/templates/android_project/src/resources/coin.wav similarity index 100% rename from templates/android_project/assets/coin.wav rename to templates/android_project/src/resources/coin.wav diff --git a/templates/android_project/assets/raylib_logo.png b/templates/android_project/src/resources/raylib_logo.png similarity index 100% rename from templates/android_project/assets/raylib_logo.png rename to templates/android_project/src/resources/raylib_logo.png