diff --git a/.gitignore b/.gitignore
index 556cceb..52c570b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
!/app/obj/.gitkeep
/app/app.apk
/app/Makefile.app-config
+/app/output.map
diff --git a/README.md b/README.md
index 08438b0..6ccea5c 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,10 @@
-# Android App (build via docker/podman)
+# Android App Written in C (build via docker/podman)
-The goal of this repo, is to create a container that can serve to produce an "empty android Application" (i.e `app.apk` file).
-As such the philosophy is to keep the process "simple" as to now make the understanding too difficult.
+This repo provides its user with the ability to setup and compile a Android-App that is
+based on `android.app.NativeActiviy` and thus can be completely compiled C source-code.
+
+It is an adoptation (and hopefully somehow simplification of this repo [`rawdrawandroid`](https://github.com/cnlohr/rawdrawandroid)
+and this many thanks and credits to most of the c-code goes to CNLohr.
## usage
@@ -12,7 +15,7 @@ As such the philosophy is to keep the process "simple" as to now make the unders
./build-android-app.sh
```
-2. follow the configuration
+2. follow the configuration (configuration is less than in the normal case of [android-app](https://git.alexmahr.de/lion/android-app) as the API-Level is inserted fixed as "29" )
3. upon success the apk file created is in app/result/app.apk and can be installed via `adb`
```
adb install -r app/result/app.apk
@@ -22,6 +25,7 @@ adb install -r app/result/app.apk
* work within container (debian based image)
* use Makefile as a build tool
+* avoid the "unhappiness" of having to deal with neither KOTLIN nor JAVA
## benefits of this (compared to AndroidStudio)
@@ -31,63 +35,4 @@ adb install -r app/result/app.apk
* oftentimes faster compile time (as compared with AndroidStudio Gradle builds)
* quick "webview" which can serve as starting point for people that can to PWA and websites
* Assisted initial configuration provides access to configure almost all types of [Android app permissions](app/.Makefile.scripts/make--app-config.sh#L127)
-* no need to have Kotlin, Gradle setup
-/
-## basic info
-
-This repo should allow to generate an empty "android app". by simply cloning this repo and
-```
-./build-android-app.sh
-```
-It does so via:
-
-1. building a container (in any of the runtime/daemons it finds: i.e. docker,podman,etc..)
-2. running this container having the `./app` folder being mounted within as `/app`
-3. executing the [`app/Makefile`](app/Makefile) which will then:
-4. either work with the configuration stored in an `app/app-config.sh` in case such file exists or
-5. if not go through a `whiptail` text menu wizzard to configure a new empty app. (Makefile recipe: `./app-config.sh`)
-6. it will then download the required android sdk files as necessary (Makefile recipe: `./android-sdk/installed`)
-7. go through the further steps to setup the blank app.
-
-
-
-## files and purpose
-
-Upon `clone` of this repo the `app` folder is setup with these files:
-```
-# The (GNU) Makefile which...
-app/Makefile
-# ... has recipes that call scripts in folder....
-app/.Makefile.scripts
-# .. which creates an `app-config.sh`, a file to keep
-# the configuration (app name,lable,api-levels,permissions etc)...
-app/.Makefile.scripts/make--app-config.sh
-# .. which creates an `AndroidManifest.xml`
-app/.Makefile.scripts/make--AndroidManifest.xml
-# .. which creates an `AppActivity.java` file (which just setup a Webview and loads `assets/index.html`)
-app/.Makefile.scripts/make--AppActivity.java.sh
-# .. which installs the necessary Android SDK in the correct versions
-app/.Makefile.scripts/make--android-sdk.sh
-app/assets
-# the index.html file
-app/assets/index.html
-app/res
-app/res/drawable
-# the icon of the app
-app/res/drawable/appicon.xml
-```
-
-Upon further `./build-android-app.sh` execution more folders will appear
-```
-# a folder in which the Android-sdk stuff (installed via sdkmanager) is stored
-android-sdk
-# folders used during build...
-# ... for temporary files
-bin/
-obj/
-result/
-# app configuration resulting from text whiptail menu
-app-config.sh
-# the Manifest file as resulted from data from app-config.sh
-AndroidManifest.xml
-```
+* no need to have Kotlin, Gradle setup, nor use JAVA
diff --git a/app/.Makefile.scripts/make--AndroidManifest.xml b/app/.Makefile.scripts/make--AndroidManifest.xml
index 179d48f..66c1391 100755
--- a/app/.Makefile.scripts/make--AndroidManifest.xml
+++ b/app/.Makefile.scripts/make--AndroidManifest.xml
@@ -13,11 +13,12 @@ cat > "AndroidManifest.xml" << ANDROIDMANIFEST
$(sed 's/^/ /' <<< "$APP_PERMISSIONS")
-
-
+
+
@@ -26,4 +27,3 @@ $(sed 's/^/ /' <<< "$APP_PERMISSIONS")
ANDROIDMANIFEST
-
diff --git a/app/.Makefile.scripts/make--android-sdk.sh b/app/.Makefile.scripts/make--android-sdk.sh
index 1b14330..e3810be 100755
--- a/app/.Makefile.scripts/make--android-sdk.sh
+++ b/app/.Makefile.scripts/make--android-sdk.sh
@@ -34,46 +34,7 @@ type sdkmanager 2>/dev/null || (
mv -v cmdline-tools "$BUILD_TOOLS_LATEST" || true
)
-test -f android-sdk/.installed.buildtools.version.$APP_VERSION_SDK_TARGET || {
- EXACTVERSION_BUILDTOOLS="$(
- sdkmanager --list 2>/dev/null |
- sed 's/^ *//' |
- grep -e 'build-tools;'"$APP_VERSION_SDK_TARGET"'\.[0-9]*\.[0-9]*\ ' |
- cut -f1 -d' ' |
- sort |
- tail -n 1
- )"
- test -z "$EXACTVERSION_BUILDTOOLS" && {
- echo "ERROR cannot get '$EXACTVERSION_BUILDTOOLS'" >&2
- echo "dropping to shell..." >&2
- exec bash
- }
- sdkmanager --list_installed | grep -q "$EXACTVERSION_BUILDTOOLS" || {
- sdkmanager --install "$EXACTVERSION_BUILDTOOLS"
- }
- echo "$EXACTVERSION_BUILDTOOLS" > android-sdk/.installed.buildtools.version.$APP_VERSION_SDK_TARGET
- ln -rvsf android-sdk/.installed.buildtools.version.{$APP_VERSION_SDK_TARGET,current}
+test -f android-sdk/installed || {
+ sdkmanager --install "build-tools;29.0.3" "cmake;3.10.2.4988404" "ndk;21.1.6352462" "platform-tools" "platforms;android-29" "tools" &&
+ touch android-sdk/installed || exit 1
}
-
-test -f android-sdk/.installed.platforms.version.$APP_VERSION_SDK_TARGET || {
- EXACTVERSION_PLATFORM="$(
- sdkmanager --list 2>/dev/null |
- sed 's/^ *//' |
- grep -e 'platforms;android-'"$APP_VERSION_SDK_TARGET"'\ ' |
- cut -f1 -d' ' |
- sort |
- tail -n 1
- )"
- test -z "$EXACTVERSION_PLATFORM" && {
- echo "ERROR cannot get '$EXACTVERSION_PLATFORM'" >&2
- echo "dropping to shell..." >&2
- exec bash
- }
- sdkmanager --list_installed | grep -q "$EXACTVERSION_PLATFORM" || {
- sdkmanager --install "$EXACTVERSION_PLATFORM"
- }
- echo "$EXACTVERSION_PLATFORM" > android-sdk/.installed.platforms.version.$APP_VERSION_SDK_TARGET
- ln -rvsf android-sdk/.installed.platforms.version.{$APP_VERSION_SDK_TARGET,current}
-}
-
-touch android-sdk/installed
diff --git a/app/.Makefile.scripts/make--app-config.sh b/app/.Makefile.scripts/make--app-config.sh
index 7a497f0..8732e46 100755
--- a/app/.Makefile.scripts/make--app-config.sh
+++ b/app/.Makefile.scripts/make--app-config.sh
@@ -3,7 +3,8 @@
test -f app-config.sh && {
source app-config.sh
}
-
+APP_VERSION_SDK_TARGET='29'
+APP_VERSION_SDK_MIN='29'
set -e
diff --git a/app/Makefile b/app/Makefile
index a8041f1..b7fe88d 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -9,48 +9,88 @@ SHELL=/bin/makefile-bash-wrapper.sh
# (as explained https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#include)
include Makefile.app-config
+# litanay of variabes used
+NDK:=./android-sdk/ndk/21.1.6352462
+NDK_TOOLCHAIN:=$(NDK)/toolchains/llvm/prebuilt/linux-x86_64
+NDK_TOOLCHAIN_INCLUDE:=$(NDK_TOOLCHAIN)/sysroot/usr/include
+ANDROIDVERSION:=29
+CC_ARM64:=$(NDK_TOOLCHAIN)/bin/aarch64-linux-android29-clang
+CFLAGS?=-ffunction-sections -Os -fdata-sections -Wall -fvisibility=hidden
+CFLAGS += -fvisibility=hidden
+# APP_PACKAGE is set to (-D) i.e preprocessor value and used to set string when logging
+CFLAGS+=-Os -DANDROID -DAPP_PACKAGE=\"$(APP_PACKAGE)\"
+# the -D will likely set a Variable to be used in the Preprocessor
+CFLAGS +=-DANDROID_FULLSCREEN
+CFLAGS+= -I./src/nativecode/rawdraw -I./src/nativecode -I$(NDK)/sysroot/usr/include
+CFLAGS+= -I$(NDK)/sysroot/usr/include/android -I$(NDK_TOOLCHAIN_INCLUDE) -I$(NDK_TOOLCHAIN_INCLUDE)/android
+CFLAGS+= -fPIC -DANDROIDVERSION=$(ANDROIDVERSION)
+CFLAGS_ARM64:=-m64
+LDFLAGS?=-Wl,--gc-sections -Wl,-Map=output.map -s
+LDFLAGS += -s
+# LDFLAGS += -static-libstdc++
+LDFLAGS += -lm -lGLESv3 -lEGL -landroid -llog -lOpenSLES
+LDFLAGS += -shared -uANativeActivity_onCreate
+# locatoins of "mostly c" source files
+SRC?=./src/nativecode/test.c
+RAWDRAWANDROIDSRCS=./src/nativecode/android_native_app_glue.c
+ANDROIDSRCS:= $(SRC) $(RAWDRAWANDROIDSRCS)
+
+
# symlink
./app.apk: ./result/app.apk
ln -sfrv ./result/app.apk ./app.apk
# zipalign and sign again (second signing)
-./result/app.apk : ./result/signed.apk app-config.sh ./keystore
+./result/app.apk : ./result/unsigned.apk app-config.sh ./keystore
$(BUILDTOOLS)/zipalign -v -f 4 $< $@
$(BUILDTOOLS)/apksigner sign --ks keystore --key-pass pass:armena --ks-pass pass:armena $@
-# sign the apk file (first sign)
-./result/signed.apk : ./result/unsigned.apk ./keystore
- jarsigner -verbose -keystore ./keystore -storepass armena -keypass armena -signedjar $@ $< helljniKey
+## sign the apk file (first sign)
+#./result/signed.apk : ./result/unsigned.apk ./keystore
+# jarsigner -verbose -keystore ./keystore -storepass armena -keypass armena -signedjar $@ $< helljniKey
# make a "keystore" for the cryptographic signing stuff
./keystore :
- keytool -genkeypair -validity 1000 -dname "CN=alexander,O=Android,C=JPN" -keystore $@ \
+ keytool -genkeypair -validity 2000 -dname "CN=$(APP_PACKAGE),O=Android,C=IT" -keystore $@ \
-storepass armena -keypass armena -alias helljniKey -keyalg RSA -v
# aapt "package" together the dalvik/hex stuff (and "assets" and "res")
-./result/unsigned.apk : ./result/bin/classes.dex ./assets ./AndroidManifest.xml
+./result/unsigned.apk : ./assets ./AndroidManifest.xml ./result/bin/lib/arm64-v8a/libnativecode.so $(shell find ./res -type f)
rm -rvf "$@"
$(BUILDTOOLS)/aapt package \
-v -u -f -M ./AndroidManifest.xml -S ./res \
-I $(ANDROID_JAR) -A ./assets -F $@ ./result/bin
-# convert "java class"es files (i.e bytecode) to dalvic/d8 android thing
-./result/bin/classes.dex : ./obj/$(PACKAGE)/AppActivity.class
- mkdir -p ./result/bin
- $(BUILDTOOLS)/d8 ./obj/$(PACKAGE)/*.class \
- --lib $(ANDROID_JAR) --output ./result/bin
+supi:
+ echo $(shell find ./res -type f)
-# compile (javac) the class from
-./obj/$(PACKAGE)/AppActivity.class : ./src/$(PACKAGE)/AppActivity.java ./src/$(PACKAGE)/R.java
- mkdir -p ./obj/$(PACKAGE)
- javac -d ./obj -classpath $(ANDROID_JAR) -sourcepath ./src $<
+alex: ./result/bin/classes.dex
+ echo $< > $@
+
+## convert "java class"es files (i.e bytecode) to dalvic/d8 android thing
+#./result/bin/classes.dex : ./obj/$(PACKAGE)/AppActivity.class
+# mkdir -p ./result/bin
+# $(BUILDTOOLS)/d8 ./obj/$(PACKAGE)/*.class \
+# --lib $(ANDROID_JAR) --output ./result/bin; RESULT=$$?; echo result was $$RESULT; (exit $$RESULT)
-# make the resources "R.java" thing
-./src/$(PACKAGE)/R.java : $(shell find ./res -type f) app-config.sh ./AndroidManifest.xml ./android-sdk/installed | ./src/$(PACKAGE)
- $(BUILDTOOLS)/aapt package \
- -v -f -m -S ./res -J ./src -M ./AndroidManifest.xml \
- -I $(ANDROID_JAR)
+./result/bin/lib/arm64-v8a/libnativecode.so: $(ANDROIDSRCS)
+ mkdir -p "$$(dirname "$@")"
+ $(CC_ARM64) $(CFLAGS) $(CFLAGS_ARM64) -o $@ $^ -L$(NDK_TOOLCHAIN)/sysroot/usr/lib/aarch64-linux-android/$(ANDROIDVERSION) $(LDFLAGS)
+
+
+
+## compile (javac) the class from
+#./obj/$(PACKAGE)/AppActivity.class : ./src/$(PACKAGE)/AppActivity.java ./src/$(PACKAGE)/R.java
+# mkdir -p ./obj/$(PACKAGE)
+# javac -d ./obj -classpath $(ANDROID_JAR) -sourcepath ./src $<
+#
+#
+## make the resources "R.java" thing
+#./src/$(PACKAGE)/R.java : $(shell find ./res -type f) app-config.sh ./AndroidManifest.xml ./android-sdk/installed | ./src/$(PACKAGE)
+# $(BUILDTOOLS)/aapt package \
+# -v -f -m -S ./res -J ./src -M ./AndroidManifest.xml \
+# -I $(ANDROID_JAR)
# generate the AppActivity.java (template
# the "|" denotes an "order-only" prerequiste (as in https://stackoverflow.com/a/58040049/1711186)
@@ -61,19 +101,21 @@ include Makefile.app-config
mkdir -p $@
# install the necessary android sdks
-./android-sdk/installed: app-config.sh
+./android-sdk/installed: app-config.sh ./.Makefile.scripts/make--android-sdk.sh
./.Makefile.scripts/make--android-sdk.sh
# generate the AndroidManifest.xml
-./AndroidManifest.xml: app-config.sh
+./AndroidManifest.xml: app-config.sh ./.Makefile.scripts/make--AndroidManifest.xml
./.Makefile.scripts/make--AndroidManifest.xml
Makefile.app-config: app-config.sh Makefile
source app-config.sh; \
tee $@ << MAKEFILE_APP_CONFIG
- BUILDTOOLS:=$${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.buildtools.version.current)
- ANDROID_JAR:=$${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.platforms.version.current)/android.jar
+ ANDROIDVERSION:=$$APP_VERSION_SDK_TARGET;
+ BUILDTOOLS:=$${ANDROID_SDK_ROOT}/build-tools/29.0.3/
+ ANDROID_JAR:=$${ANDROID_SDK_ROOT}/platforms/android-29/android.jar
PACKAGE:=$$(echo "$$APP_PACKAGE" | tr '.' '/')
+ APP_PACKAGE=$${APP_PACKAGE}
MAKEFILE_APP_CONFIG
# use whiptail textgui to make configuration (android API level, app-name, app-label etc...)
diff --git a/app/assets/index.html b/app/assets/index.html
index 1c1ad7c..b99d44a 100644
--- a/app/assets/index.html
+++ b/app/assets/index.html
@@ -18,23 +18,72 @@