Android: Organize tup rules; Fix manifest;

This commit is contained in:
bjorn 2020-06-25 13:27:18 -06:00
parent a1aa3c8ae8
commit 8b281d56e3
6 changed files with 35 additions and 17 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@ config/*
*.ttf.h
*.json.h
*.lua.h
AndroidManifest*.xml
/build.sh
/watch.sh
/debug.sh

22
Tupfile
View File

@ -68,17 +68,25 @@ SRC_@(GRAPHICS) += src/resources/shaders.c
# 2 [CC] compile .c -> .o
# 3 [LD] link .o -> exe
# 4 [CP] copy external libs -> libs folder
: foreach $(RES) $(RES_y) |> !xd |> %f.h
: foreach $(SRC) $(SRC_y) $(SRC_yy) | src/resources/*.h |> !cc |> .obj/%B.o
: .obj/*.o $(STATIC_LIBS) $(STATIC_LIBS_y) |> !ld |> $(PREFIX)lovr$(SUFFIX) | $(EXTRAS) $(EXTRAS_y)
: foreach $(LIBS) |> !cp |> $(LIB)/%b
# Android packaging
# Android
ifeq ($(PLATFORM),android)
: $(ROOT)/src/resources/LoadLibraries.java |> javac -classpath $(JAR) -d . %f |> org/lovr/app/LoadLibraries.class
: $(ROOT)/org/lovr/app/LoadLibraries.class |> dx --dex --output=%o %f |> classes.dex
: $(ROOT)/src/resources/AndroidManifest.xml | $(LIB)/*.so classes.dex |> aapt package -F %o -M %f -I $(JAR) && zip -qu0 tmp/lovr.unaligned.apk $(LIB)/*.so classes.dex |> tmp/lovr.unaligned.apk
: tmp/lovr.unaligned.apk |> $(TOOLS)/zipalign -f 4 %f %o |> tmp/lovr.unsigned.apk
: tmp/lovr.unsigned.apk |> $(TOOLS)/apksigner sign --ks @(ANDROID_KEYSTORE) --ks-pass @(ANDROID_KEYSTORE_PASS) --out %o %f |> lovr.apk
# There needs to be a Java class for the activity with 2 lines of code to load native libraries.
# It gets compiled to a class file with javac and then into bytecode using dx
CLASS = org/lovr/app/Activity.class
: src/resources/Activity.java |> ^ JAVAC %b^ javac -classpath $(ANDROID_JAR) -d . %f |> $(CLASS)
: $(CLASS) |> !dx |> classes.dex
# Create an apk from the Android manifest. The zip command is used afterwards to add raw files
# because it is way faster than calling aapt again and apks are just zips (TODO windows).
: @(ANDROID_MANIFEST) | $(LIB)/*.so classes.dex |> ^ AAPT %b^ aapt package -F %o -M %f -I $(ANDROID_JAR) -A @(ANDROID_ASSETS) && zip -qu0 %o $(LIB)/*.so classes.dex |> tmp/lovr.unaligned.apk
# Even though we have an apk, it isn't actually valid yet. It has to be aligned using the special
# zipalign tool, and then signed using apksigner.
: tmp/lovr.unaligned.apk |> !zipalign |> tmp/lovr.unsigned.apk
: tmp/lovr.unsigned.apk |> !apksigner |> lovr.apk
endif

View File

@ -176,7 +176,7 @@ endif
ifeq ($(PLATFORM),android)
CC = @(ANDROID_SDK)/sdk/ndk-bundle/toolchains/llvm/prebuilt/@(ANDROID_HOST_TAG)/bin/clang
TOOLS = @(ANDROID_SDK)/sdk/build-tools/@(ANDROID_BUILD_TOOLS_VERSION)
JAR = @(ANDROID_SDK)/sdk/platforms/android-@(ANDROID_API_VERSION)/android.jar
ANDROID_JAR = @(ANDROID_SDK)/sdk/platforms/android-@(ANDROID_API_VERSION)/android.jar
GLUE = @(ANDROID_SDK)/sdk/ndk-bundle/sources/android/native_app_glue
VRAPI_LIB_PATH = $(ROOT)/deps/VrApi/Libs/Android/@(ANDROID_ABI)/Release
CFLAGS += --target=@(ANDROID_TARGET)
@ -188,7 +188,10 @@ ifeq ($(PLATFORM),android)
PREFIX = $(LIB)/lib
SUFFIX = .so
: |> $(CC) $(CFLAGS) -Wno-format-pedantic -c $(GLUE)/android_native_app_glue.c -o %o |> .obj/android_native_app_glue.o
# Macros
!dx = |> ^ DX %b^ dx --dex --output=%o %f |>
!zipalign = |> ^ ZIPALIGN %f^ $(TOOLS)/zipalign -f 4 %f %o |>
!apksigner = |> ^ APKSIGNER %o^ $(TOOLS)/apksigner sign --ks @(ANDROID_KEYSTORE) --ks-pass @(ANDROID_KEYSTORE_PASS) --out %o %f |>
ifeq (@(CMAKE_DEPS),y)
ifeq (@(LUAJIT),y)
@ -254,7 +257,7 @@ CFLAGS += @(EXTRA_CFLAGS)
LDFLAGS += @(EXTRA_LDFLAGS)
## Macros
!cc = |> ^ CC %b^ $(CC) $(CFLAGS_y) $(CFLAGS) -c %f -o %o |>
!cc = |> ^ CC %b^ $(CC) $(CFLAGS_y) $(CFLAGS) -o %o -c %f |>
!ld = |> ^ LD %o^ $(CC) -o %o %f $(LDFLAGS_y) $(LDFLAGS) |>
!xd = |> ^ XD %f^ xxd -i %f > %o |>
!cp = |> ^ CP %b^ cp %f %o |>

View File

@ -4,8 +4,12 @@
#include <time.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <android_native_app_glue.h>
#include <android/log.h>
// This is probably bad, but makes things easier to build
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-pedantic"
#include <android_native_app_glue.c>
#pragma clang diagnostic pop
// The activity is considered ready if it's resumed and there's an active window. This is just an
// artifact of how Oculus' app model works and could be the wrong abstraction, feel free to change.

View File

@ -2,7 +2,7 @@ package org.lovr.app;
import android.app.NativeActivity;
public class LoadLibraries extends NativeActivity {
public class Activity extends NativeActivity {
static {
System.loadLibrary("lovr");
System.loadLibrary("vrapi");

View File

@ -1,13 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.lovr.app">
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="25"/>
<uses-feature android:glEsVersion="0x00030001" android:required="true"/>
<uses-feature android:name="android.hardware.vr.headtracking" android:required="false"/>
<application android:allowBackup="false" android:label="LÖVR">
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/>
<activity android:name="LoadLibraries">
<meta-data android:name="android.app.lib_name" android:value="lovr" />
<activity android:name="Activity">
<meta-data android:name="android.app.lib_name" android:value="lovr"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>