enable build of apk app in container

This commit is contained in:
Alexander Mahr 2023-07-17 09:45:48 +02:00
parent 34503d3f82
commit 5262bf8ff2
15 changed files with 154 additions and 22 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
apk/ToyKey.keystore
apk/obj
apk/obj/*
apk/bin/!.gikeep

View file

@ -1,8 +1,7 @@
FROM alpine:latest FROM archlinux:latest
RUN apk update RUN pacman -Syu --noconfirm
RUN apk add coreutils bash shadow make zip RUN pacman -S --noconfirm coreutils bash shadow make unzip jdk11-openjdk wget
RUN apk add openjdk11-jdk
ENV ANDROID_SDK_ROOT="/opt/android" ENV ANDROID_SDK_ROOT="/opt/android"
ENV BUILD_TOOLS_LATEST="$ANDROID_SDK_ROOT/cmdline-tools/latest" ENV BUILD_TOOLS_LATEST="$ANDROID_SDK_ROOT/cmdline-tools/latest"
RUN BUILD_TOOLS="$(realpath -m "$BUILD_TOOLS_LATEST/..")";\ RUN BUILD_TOOLS="$(realpath -m "$BUILD_TOOLS_LATEST/..")";\
@ -16,12 +15,15 @@ RUN BUILD_TOOLS="$(realpath -m "$BUILD_TOOLS_LATEST/..")";\
rm cmdline-tools.zip;\ rm cmdline-tools.zip;\
mv -v cmdline-tools "$BUILD_TOOLS_LATEST" || true mv -v cmdline-tools "$BUILD_TOOLS_LATEST" || true
ENV PATH="$PATH:$BUILD_TOOLS_LATEST/bin" ENV PATH="$PATH:$BUILD_TOOLS_LATEST/bin"
ENV JAVA_HOME="/usr/lib/jvm/java-11-openjdk/"
#ENTRYPOINT bash -c 'sleep 10000'
ENV LIBRARY_PATH="$LIBRARY_PATH:$BUILD_TOOLS_LATEST/lib" ENV LIBRARY_PATH="$LIBRARY_PATH:$BUILD_TOOLS_LATEST/lib"
RUN touch /file
RUN yes | sdkmanager --install "build-tools;33.0.2" RUN yes | sdkmanager --install "build-tools;33.0.2"
RUN yes | sdkmanager --install "platforms;android-33" RUN yes | sdkmanager --install "platforms;android-33"
RUN apk add setpriv #RUN apk add setpriv
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
RUN chown 0:0 /entrypoint.sh RUN chown 0:0 /entrypoint.sh
RUN chmod 0700 /entrypoint.sh RUN chmod 0700 /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] RUN touch /file2
#

27
Dockerfile.alpine Normal file
View file

@ -0,0 +1,27 @@
FROM alpine:latest
RUN apk update
RUN apk add coreutils bash shadow make zipi gcompat libgcc libc++
RUN apk add openjdk11-jdk
ENV ANDROID_SDK_ROOT="/opt/android"
ENV BUILD_TOOLS_LATEST="$ANDROID_SDK_ROOT/cmdline-tools/latest"
RUN BUILD_TOOLS="$(realpath -m "$BUILD_TOOLS_LATEST/..")";\
mkdir -p "$BUILD_TOOLS";\
cd "$BUILD_TOOLS";\
pwd;\
wget -O cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip;\
unzip cmdline-tools.zip;\
ls ;\
ls cmdline-tools;\
rm cmdline-tools.zip;\
mv -v cmdline-tools "$BUILD_TOOLS_LATEST" || true
ENV PATH="$PATH:$BUILD_TOOLS_LATEST/bin"
ENV LIBRARY_PATH="$LIBRARY_PATH:$BUILD_TOOLS_LATEST/lib"
RUN yes | sdkmanager --install "build-tools;33.0.2"
RUN yes | sdkmanager --install "platforms;android-33"
RUN apk add setpriv
COPY entrypoint.sh /entrypoint.sh
RUN chown 0:0 /entrypoint.sh
RUN chmod 0700 /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

19
apk/AndroidManifest.xml Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellojni"
android:versionCode="3"
android:versionName="3.0">
<uses-sdk android:minSdkVersion="30"
android:targetSdkVersion="33"/>
<!-- android:maxSdkVersion="integer" /> -->
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="HelloJNI"
android:exported="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View file

@ -1,12 +1,14 @@
JAVA_HONE = /usr/lib/jvm/java-8-openjdk #JAVA_HONE = /usr/lib/jvm/java-8-openjdk
ANDROID_HOME = /root/sdk ANDROID_HOME = /opt/android
ANDROID_VERSION = 33.0.2
PLATFORM = android-$(shell echo $(ANDROID_VERSION) | sed 's/\..*//')
TOOLCHAIN = /Users/amon/grive/development/Android/NativeToolchain TOOLCHAIN = /Users/amon/grive/development/Android/NativeToolchain
GCC = $(TOOLCHAIN)/bin/aarch64-linux-android-gcc GCC = $(TOOLCHAIN)/bin/aarch64-linux-android-gcc
CXX_FLAGS = -march=armv8-a --sysroot=$(TOOLCHAIN)/sysroot CXX_FLAGS = -march=armv8-a --sysroot=$(TOOLCHAIN)/sysroot
say_hello: say_hello:
echo "this was a test" echo "this was a test $(PLATFORM)"
all: build deploy all: build deploy
@ -19,19 +21,26 @@ deploy :
build : ./bin/hellojni.apk build : ./bin/hellojni.apk
./bin/hellojni.apk : ./bin/signed.apk #./bin/hellojni.apk : ./bin/aligned.apk
$(ANDROID_HOME)/build-tools/23.0.3/zipalign -v -f 4 $< $@ # j
# cp $< $@
./bin/hellojni.apk : ./bin/signed.apk
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/zipalign -v -f 4 $< $@
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/apksigner sign --ks ToyKey.keystore $@
./bin/signed.apk : ./bin/unsigned.apk ./ToyKey.keystore ./bin/signed.apk : ./bin/unsigned.apk ./ToyKey.keystore
$(JAVA_HOME)/bin/jarsigner -verbose -keystore ./ToyKey.keystore -storepass armena -keypass armena -signedjar $@ $< helljniKey #$(JAVA_HOME)/bin/jarsigner -verbose -keystore ./ToyKey.keystore -storepass armena -keypass armena -signedjar $@ $< helljniKey
jarsigner -verbose -keystore ./ToyKey.keystore -storepass armena -keypass armena -signedjar $@ $< helljniKey
./bin/unsigned.apk : ./bin/classes.dex ./bin/unsigned.apk : ./bin/classes.dex
$(ANDROID_HOME)/build-tools/23.0.3/aapt package -v -f -M ./AndroidManifest.xml -S ./res \ $(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/aapt package -v -f -M ./AndroidManifest.xml -S ./res \
-I $(ANDROID_HOME)/platforms/android-23/android.jar -F $@ ./bin -I $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar -F $@ ./bin
# $(ANDROID_HOME)/build-tools/23.0.3/aapt add $@ lib/arm64-v8a/libhello.so # $(ANDROID_HOME)/build-tools/23.0.3/aapt add $@ lib/arm64-v8a/libhello.so
./bin/classes.dex : ./obj/com/example/hellojni/HelloJni.class ./bin/classes.dex : ./obj/com/example/hellojni/HelloJni.class
$(ANDROID_HOME)/build-tools/23.0.3/dx --dex --verbose --output=$@ ./obj #$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/d8 --dex --verbose --output=$@ ./obj
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/d8 $(shell find obj -name '*.class') --lib $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar --output bin
#./lib/arm64-v8a/libhello.so : ./jni/hello.o #./lib/arm64-v8a/libhello.so : ./jni/hello.o
# $(GCC) -shared $< -o $@ # $(GCC) -shared $< -o $@
@ -40,14 +49,17 @@ build : ./bin/hellojni.apk
# $(GCC) $(CXX_FLAGS) -fPIC -c $< -o $@ # $(GCC) $(CXX_FLAGS) -fPIC -c $< -o $@
./src/com/example/hellojni/R.java : $(shell find ./res -type f) ./src/com/example/hellojni/R.java : $(shell find ./res -type f)
$(ANDROID_HOME)/build-tools/23.0.3/aapt package -v -f -m -S ./res -J ./src -M ./AndroidManifest.xml \ $(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/aapt package -v -f -m -S ./res -J ./src -M ./AndroidManifest.xml \
-I $(ANDROID_HOME)/platforms/android-23/android.jar -I $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar
./obj/com/example/hellojni/HelloJni.class : ./src/com/example/hellojni/HelloJNI.java ./src/com/example/hellojni/R.java ./obj/com/example/hellojni/HelloJni.class : ./src/com/example/hellojni/HelloJNI.java ./src/com/example/hellojni/R.java
$(JAVA_HOME)/bin/javac -source 7 -target 7 -d ./obj -classpath $(ANDROID_HOME)/platforms/android-23/android.jar -sourcepath ./src $< #$(JAVA_HOME)/bin/javac -source 7 -target 7 -d ./obj -classpath $(ANDROID_HOME)/platforms/$(PLATFORMgg)/android.jar -sourcepath ./src $<
#javac -source 7 -target 7 -d ./obj -classpath $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar -sourcepath ./src $<
javac -d ./obj -classpath $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar -sourcepath ./src $<
./ToyKey.keystore : ./ToyKey.keystore :
$(JAVA_HOME)/bin/keytool -genkeypair -validity 1000 -dname "CN=some company,O=Android,C=JPN" -keystore $@ \ #$(JAVA_HOME)/bin/keytool -genkeypair -validity 1000 -dname "CN=some company,O=Android,C=JPN" -keystore $@
keytool -genkeypair -validity 1000 -dname "CN=some company,O=Android,C=JPN" -keystore $@ \
-storepass armena -keypass armena -alias helljniKey -keyalg RSA -v -storepass armena -keypass armena -alias helljniKey -keyalg RSA -v
clean: clean:

0
apk/bin/.gitkeep Normal file
View file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

13
apk/res/layout/main.xml Normal file
View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, HelloJni"
/>
</LinearLayout>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">HelloJni</string>
</resources>

View file

@ -0,0 +1,29 @@
package com.example.hellojni;
import android.util.Log;
import android.widget.TextView;
import android.app.Activity;
import android.os.Bundle;
public class HelloJNI extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText( "hallo " );
//stringFromJNI() );
// tv.setText("sup");
setContentView(tv);
}
public native String stringFromJNI();
/* static {
Log.i("amo", "Trying to load shared library!");
System.loadLibrary("hellojni");
}
*/
}

View file

@ -0,0 +1,22 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.example.hellojni;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040000;
}
}

View file

@ -4,6 +4,6 @@ services:
build: build:
context: . context: .
stop_grace_period: 1s stop_grace_period: 1s
#command: ["id; sleep infinity"] command: sh -c 'id; sleep infinity'
volumes: volumes:
- ./apk:/apk - ./apk:/apk