-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
100 lines (85 loc) · 2.49 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Environment variables
ANDROID_HOME ?=
# Build tools & SDK versions
build_tools := 24.0.0-preview
target := android-n
# Variables
project := handbuilt
package := pl.czak.handbuilt
src_dir := src
res_dir := res
lib_dir := build/libraries
gen_dir := build/generated
int_dir := build/intermediate
out_dir := build/output
sources := $(shell find $(src_dir) -name '*.java')
resources := $(shell find $(res_dir) -type f)
generated := $(gen_dir)/pl/czak/handbuilt/R.java
libraries := $(lib_dir)/com/squareup/picasso/picasso/2.5.2/picasso-2.5.2.jar
# Final zipaligned APK
$(out_dir)/$(project).apk: $(out_dir)/$(project)-unaligned.apk
@echo -n Zipaligning...
@zipalign -f 4 $< $@
@echo Done.
# Packaging the APK
$(out_dir)/$(project)-unaligned.apk: $(out_dir) AndroidManifest.xml $(resources) $(int_dir)/classes.dex
@echo -n Packaging...
@aapt package -f \
-M AndroidManifest.xml \
-I $(ANDROID_HOME)/platforms/$(target)/android.jar \
-S $(res_dir) \
-F $@
@cd $(int_dir) && aapt add $(abspath $@) classes.dex > /dev/null
@echo Done.
@echo -n Signing the APK...
@jarsigner -verbose \
-keystore ~/.android/debug.keystore \
-storepass android \
-keypass android \
$@ \
androiddebugkey \
> /dev/null
@echo Done.
# Compilation & dexing w/ Jack
$(int_dir)/classes.dex: $(int_dir) $(sources) $(generated) $(libraries)
@echo -n Compiling with Jack...
@java -jar $(ANDROID_HOME)/build-tools/$(build_tools)/jack.jar \
--classpath $(ANDROID_HOME)/platforms/$(target)/android.jar \
$(foreach lib,$(libraries),--import $(lib)) \
--output-dex $(int_dir) \
$(sources) $(generated)
@echo Done.
# Generating R.java based on the manifest and resources
$(generated): $(gen_dir) AndroidManifest.xml $(resources)
@echo -n Generating R.java...
@aapt package -f \
-M AndroidManifest.xml \
-I $(ANDROID_HOME)/platforms/$(target)/android.jar \
-S $(res_dir) \
-J $(gen_dir) \
-m
@echo Done.
# Fetching dependencies from Maven Central
$(libraries):
@echo -n Fetching dependency $(notdir $@)...
@curl --silent \
--location \
--output $@ \
--create-dirs \
http://search.maven.org/remotecontent?filepath=$(subst $(lib_dir)/,,$@)
@echo Done.
# Subfolders in build/
$(gen_dir) $(out_dir) $(int_dir):
@mkdir -p $@
.PHONY: clean
clean:
rm -rf build
.PHONY: install
install: $(out_dir)/$(project).apk
adb install -r $<
.PHONY: uninstall
uninstall:
adb uninstall $(package)
.PHONY: run
run:
adb shell am start $(package)/.MainActivity