make remake ;)

This commit is contained in:
Er2 2022-01-15 15:23:41 +00:00
parent 9bada7a940
commit f040fa9862
4 changed files with 65 additions and 72 deletions

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
bin/
gen/
*.keystore
out.apk
*.tmp

View file

@ -10,10 +10,8 @@
android:targetSdkVersion="32"
/>
<!-- if want on TV:
android:banner="@drawable/banner"
-->
<application
android:banner="@drawable/banner"
android:icon="@drawable/icon"
android:label="Fireplace"
>

112
Makefile
View file

@ -1,92 +1,68 @@
NAME = Fireplace
PROJ = org.er2.fireplace
CLASS= org.er2.fireplace
ifeq ($TV,1)
SDK_VER = 24
SDK = 24.0.3
else
SDK_VER = 19
SDK = 19.1.0
endif
KEY_PATH = debug.keystore
KEY_NAME = androiddebugkey
KEY_PASS = android
SDK_ROOT = ~/Android/Sdk
JAVA_HOME:=$(if $(JAVA_HOME),$(JAVA_HOME),/usr/lib/jvm/java-1.11.0-openjdk-amd64)
SDK_VER = 24
SDK = 24.0.3
SDK_ROOT = ~/Android/Sdk
JAVA_HOME = /usr/lib/jvm/java-1.11.0-openjdk-amd64
# Android framework, DO NOT REMOVE!
VEDBASE = $(SDK_ROOT)/platforms/android-$(SDK_VER)/android.jar
ADB = $(SDK_ROOT)/platform-tools/adb
AAPT = $(SDK_ROOT)/build-tools/$(SDK)/aapt
DX = $(SDK_ROOT)/build-tools/$(SDK)/dx
ZIPALIGN=$(SDK_ROOT)/build-tools/$(SDK)/zipalign
# Tools
ADB = $(SDK_ROOT)/platform-tools/adb
AAPT = $(SDK_ROOT)/build-tools/$(SDK)/aapt
DX = $(SDK_ROOT)/build-tools/$(SDK)/dx
ZIPALIGN = $(SDK_ROOT)/build-tools/$(SDK)/zipalign
JAVAC = $(JAVA_HOME)/bin/javac
JARSIGNER = $(JAVA_HOME)/bin/jarsigner
PWD=$(shell pwd)
SRC = $(shell find src/ -name '*.java')
CLSS= $(SRC:src/%.java=gen/%.class)
OUT=$(PWD)/bin
GEN=$(PWD)/gen
RES=$(PWD)/res
SRC=$(PWD)/src
#ASS=$(PWD)/assets
all: build
build: out.apk
SRCS=$(shell find $(SRC) -name '*.java')
CLSS=$(SRCS:$(SRC)/%.java=$(GEN)/%.class)
out.apk: AndroidManifest.xml gen/classes.dex $(KEY_PATH)
@$(AAPT) p -I $(VEDBASE) -fM AndroidManifest.xml -S res/ -F $@.tmp
@cp gen/classes.dex . && $(AAPT) a $@.tmp classes.dex && rm -f classes.dex
@$(JARSIGNER) -keystore $(KEY_PATH) -storepass '$(KEY_PASS)' $@.tmp $(KEY_NAME)
@$(ZIPALIGN) -f 4 $@.tmp $@
KEY_PATH ?= debug.keystore
KEY_NAME ?= androiddebugkey
KEY_PASS ?= android
-@mv -f $@.tmp $@
all: debug
gen/classes.dex: prepare $(CLSS)
-@echo removing R classes to economy some space
@find gen/ -name 'R.class' -exec rm {} \;
@find gen/ -name 'R$$*.class' -exec rm {} \;
@$(DX) --dex --output=$@ gen/
debug:
@$(MAKE) DEBUG=true -C $(PWD) build
### Helpers
release:
@$(MAKE) -C $(PWD) build
prepare: res/*
-@echo Generating R.java
@mkdir -p gen
@$(AAPT) p -I $(VEDBASE) -fm -M AndroidManifest.xml -J gen -S res
APK=$(OUT)/$(NAME).apk
CDX=$(OUT)/classes.dex
build: $(APK)
$(APK): $(CDX) package sign zip
@if [ ! -f "$(APK)" ]; then mv $(OUT)/$(NAME).ap_ $(APK); fi
@$(RM) $(OUT)/$(NAME).ap_
prepare: clean
@mkdir -p $(OUT) $(GEN)
@$(AAPT) > /dev/null 2>&1; if ! [ $$? -ne 0 ]; then echo YOU NEED TO install lib32stdc++6 lib32z1; exit 1; fi
@$(AAPT) p $(if $(DEBUG),--debug-mode,) -I $(VEDBASE) -fm -M $(PWD)/AndroidManifest.xml -J $(GEN) -S $(RES)
$(CDX):
# dependencies is here to not re-build on every make
@make -C $(PWD) prepare $(CLSS)
@echo Removing R classes
@find $(GEN) -name 'R.class' -exec rm {} \;
@find $(GEN) -name 'R$$*.class' -exec rm {} \;
@$(DX) --dex --output=$@ $(GEN)
$(GEN)/%.class: $(SRC)/%.java
gen/%.class: src/%.java
-@echo Recompiling $@
@$(JAVAC) $(if $(DEBUG),-g,) -classpath $(VEDBASE) -sourcepath 'src:$(GEN)' -d '$(GEN)' -target 1.7 -source 1.7 $<
package: $(CDX) AndroidManifest.xml
@$(AAPT) p $(if $(DEBUG),--debug-mode,) -I $(VEDBASE) -f -M $(PWD)/AndroidManifest.xml -S $(RES) -F $(OUT)/$(NAME).ap_ # -A $(ASS)
@cd $(OUT) && $(AAPT) a $(NAME).ap_ classes.dex
sign: package $(KEY_PATH)
@$(JARSIGNER) -keystore $(KEY_PATH) -storepass '$(KEY_PASS)' $(OUT)/$(NAME).ap_ $(KEY_NAME)
zip: package
@$(ZIPALIGN) -f 4 $(OUT)/$(NAME).ap_ $(APK)
@$(JAVAC) -classpath $(VEDBASE) -sourcepath 'src/:gen/' -d 'gen/' $< -source 1.7 -target 1.7 > /dev/null 2>&1
$(KEY_PATH):
@yes | keytool -genkey -v -keystore $(KEY_PATH) -storepass '$(KEY_PASS)' -alias $(KEY_NAME) -keypass $(KEY_PASS) -keyalg RSA -keysize 2048 -validity 10000
### Tools
clean:
@rm -rf $(OUT) $(GEN)
rm -rf gen/ classes.dex out.apk out.apk.tmp
run: $(OUT)/$(NAME).apk
-@$(ADB) uninstall $(PROJ)
@$(ADB) install $^
@$(ADB) shell monkey -p $(PROJ) -c android.intent.category.LAUNCHER 1
deploy: out.apk
-@$(ADB) uninstall $(CLASS)
@$(ADB) install $<
@$(ADB) shell monkey -p $(CLASS) -c android.intent.category.LAUNCHER 1

View file

@ -9,3 +9,21 @@ and even use as screensaver!
#+caption: Screensaver or /Daydream/ on TV
[[./scr.jpg]]
* Make this
To make an APK file, you need:
- Android SDK 24.0.3
- OpenJDK (or other Java) JDK (full, not just JRE)
- GNU Make (as on Linux, no installed on macOS or other *BSD)
You maybe need to change some values in Makefile,
but on Debian no changes needed.
To build, just run ~make~.
If you need to install, connect your Android device
and run ~make deploy~.