From 4ab7a6e944a8f542e9448656e68cb7e7c2181656 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 13 Jan 2024 13:01:43 +1100 Subject: [PATCH] Android test --- .github/workflows/build_android.yml | 96 +++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/build_android.yml diff --git a/.github/workflows/build_android.yml b/.github/workflows/build_android.yml new file mode 100644 index 0000000..d3548cb --- /dev/null +++ b/.github/workflows/build_android.yml @@ -0,0 +1,96 @@ +name: Build latest (Android) +on: [push] + +concurrency: + group: ${{ github.ref }}-android + cancel-in-progress: true + +jobs: + build: + if: github.ref_name == github.event.repository.default_branch + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + + - uses: nttld/setup-ndk@v1 + id: setup_ndk + with: + local-cache: true + ndk-version: r21e + link-to-sdk: true + - name: Compile android builds + shell: bash + id: compile + env: + COMMON_FLAGS: "-O1 -s -fno-stack-protector -fno-math-errno -Qn" + NIX32_FLAGS: "-no-pie -fno-pie -m32 -fvisibility=hidden -fcf-protection=none -rdynamic -DCC_BUILD_ICON" + run: | + LATEST_FLAG=-DCC_COMMIT_SHA=\"$(git rev-parse --short "$GITHUB_SHA")\" + + DROID_FLAGS="-fPIC -shared -s -O1 -fvisibility=hidden -rdynamic -funwind-tables" + DROID_LIBS="-lGLESv2 -lEGL -lm -landroid -llog" + NDK_ROOT="/home/buildbot/android/android-ndk-r22/toolchains/llvm/prebuilt/linux-x86_64/bin" + TOOLS_ROOT="/home/buildbot/android/sdk/build-tools/26.0.0" + SDK_ROOT="/home/buildbot/android/sdk/platforms/android-28" + + $NDK_ROOT/armv7a-linux-androideabi16-clang *.c $DROID_FLAGS -march=armv5 $DROID_LIBS $LATEST_FLAG -o cc-droid-arm_16 + $NDK_ROOT/armv7a-linux-androideabi16-clang *.c $DROID_FLAGS $DROID_LIBS $LATEST_FLAG -o cc-droid-arm_32 + $NDK_ROOT/aarch64-linux-android21-clang *.c $DROID_FLAGS $DROID_LIBS $LATEST_FLAG -o cc-droid-arm_64 + $NDK_ROOT/i686-linux-android16-clang *.c $DROID_FLAGS $DROID_LIBS $LATEST_FLAG -o cc-droid-x86_32 + $NDK_ROOT/x86_64-linux-android21-clang *.c $DROID_FLAGS $DROID_LIBS $LATEST_FLAG -o cc-droid-x86_64 + + cd $ROOT_DIR/android/app/src/main + # copy required native libraries + mkdir lib lib/armeabi lib/armeabi-v7a lib/arm64-v8a lib/x86 lib/x86_64 + cp $ROOT_DIR/src/cc-droid-arm_16 lib/armeabi/libclassicube.so + cp $ROOT_DIR/src/cc-droid-arm_32 lib/armeabi-v7a/libclassicube.so + cp $ROOT_DIR/src/cc-droid-arm_64 lib/arm64-v8a/libclassicube.so + cp $ROOT_DIR/src/cc-droid-x86_32 lib/x86/libclassicube.so + cp $ROOT_DIR/src/cc-droid-x86_64 lib/x86_64/libclassicube.so + + # The following commands are for manually building an .apk, see + # https://spin.atomicobject.com/2011/08/22/building-android-application-bundles-apks-by-hand/ + # https://github.com/cnlohr/rawdrawandroid/blob/master/Makefile + # https://stackoverflow.com/questions/41132753/how-can-i-build-an-android-apk-without-gradle-on-the-command-line + # https://github.com/skanti/Android-Manual-Build-Command-Line/blob/master/hello-jni/Makefile + # https://github.com/skanti/Android-Manual-Build-Command-Line/blob/master/hello-jni/CMakeLists.txt + + # compile java files into multiple .class files + cd $ROOT_DIR/android/app/src/main/java/com/classicube + javac *.java -d $ROOT_DIR/android/app/src/main/obj -classpath $SDK_ROOT/android.jar + + cd $ROOT_DIR/android/app/src/main + # compile the multiple .class files into one .dex file + $TOOLS_ROOT/dx --dex --output=obj/classes.dex ./obj + # create initial .apk with packaged version of resources + $TOOLS_ROOT/aapt package -f -M AndroidManifest.xml -S res -F obj/cc-unsigned.apk -I $SDK_ROOT/android.jar + # and add all the required files + cp obj/classes.dex classes.dex + $TOOLS_ROOT/aapt add -f obj/cc-unsigned.apk classes.dex lib/armeabi/libclassicube.so lib/armeabi-v7a/libclassicube.so lib/arm64-v8a/libclassicube.so lib/x86/libclassicube.so lib/x86_64/libclassicube.so + # sign the apk with debug key (https://stackoverflow.com/questions/16711233/) + cp obj/cc-unsigned.apk obj/cc-signed.apk + jarsigner -sigalg SHA1withRSA -digestalg SHA1 -keystore debug.keystore -storepass android -keypass android obj/cc-signed.apk androiddebugkey + # jarsigner -verbose + # create aligned .apk file + $TOOLS_ROOT/zipalign -f 4 obj/cc-signed.apk $ROOT_DIR/src/cc.apk + + - uses: ./.github/actions/notify_failure + if: ${{ always() && steps.compile.outcome == 'failure' }} + with: + NOTIFY_MESSAGE: 'Failed to compile android build' + WEBHOOK_URL: '${{ secrets.WEBHOOK_URL }}' + + - uses: ./.github/actions/upload_build + if: ${{ always() && steps.compile.outcome == 'success' }} + with: + SOURCE_FILE: 'src/cc-nix32-gl2' + DEST_NAME: 'ClassiCube-Linux32-ModernGL' \ No newline at end of file