diff options
| author | Juan Ramos <juan@lunarg.com> | 2023-10-10 17:03:54 -0600 |
|---|---|---|
| committer | Juan Ramos <114601453+juan-lunarg@users.noreply.github.com> | 2023-10-10 17:28:58 -0600 |
| commit | d6a6498781cbdd63c0c018f5ffab39e16e920035 (patch) | |
| tree | e141912de38c710cab22d6da9d102cefe1315129 | |
| parent | 72291571c8e569cbcd5d924e0b1ad24cdefa4442 (diff) | |
| download | usermoji-d6a6498781cbdd63c0c018f5ffab39e16e920035.tar.xz | |
cmake: Remove ndk-build
Successfully ran VkCube.apk on my Pixel3
closes #850
21 files changed, 235 insertions, 664 deletions
diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml index b9efdb75..23d12188 100644 --- a/.github/workflows/tools.yml +++ b/.github/workflows/tools.yml @@ -192,23 +192,6 @@ jobs: - name: Build the tools run: ninja -C out/${{matrix.config}} - ndk-build: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3 - - name: Setup Environment - run: | - echo "ANDROID_SDK_HOME=$ANDROID_SDK_ROOT" >> $GITHUB_ENV - echo "ANDROID_NDK_HOME=$ANDROID_NDK_LATEST_HOME" >> $GITHUB_ENV - echo "$ANDROID_SDK_ROOT/build-tools/31.0.0" >> $GITHUB_PATH - echo "$ANDROID_NDK_LATEST_HOME" >> $GITHUB_PATH - $ANDROID_SDK_ROOT/tools/bin/sdkmanager "platforms;android-23" - keytool -genkey -v -keystore $HOME/.android/debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000 -dname "C=US, O=Android, CN=Android Debug" - - name: Build vkcube - run: | - cd build-android - ./build_all.sh - android: runs-on: ubuntu-22.04 strategy: @@ -1,3 +1,9 @@ +# By default we install dependencies to the external directory +/external/* + +# Ignore any build directories +*build*/ + CMakeCache.txt CMakeLists.txt.user CMakeUserPresets.json @@ -18,10 +24,6 @@ out64/* *.vcxproj *.sdf *.filters -build -build32 -dbuild -build-android/external *.config *.creator *.creator.user @@ -29,4 +31,3 @@ build-android/external *.includes .vscode/ .DS_Store -external/ @@ -516,73 +516,22 @@ Finally, rebuild the repository using `cmake` and `make`, as explained above. ## Building On Android -Install the required tools for Linux and Windows covered above, then add the -following. +TODO: https://github.com/KhronosGroup/Vulkan-Tools/issues/791 -### Android Build Requirements - -- Install [Android Studio 2.3](https://developer.android.com/studio/index.html) or later. -- From the "Welcome to Android Studio" splash screen, add the following components using - Configure > SDK Manager: - - SDK Platforms > Android 6.0 and newer - - SDK Tools > Android SDK Build-Tools - - SDK Tools > Android SDK Platform-Tools - - SDK Tools > NDK (Side by side) - -#### Add Android specifics to environment - -For each of the below, you may need to specify a different build-tools and ndk -versions, as Android Studio will roll them forward fairly regularly. - -On Linux: - - export ANDROID_SDK_HOME=$HOME/Android/sdk - export ANDROID_NDK_HOME=$HOME/Android/sdk/ndk/23.0.7599858 - export PATH=$ANDROID_NDK_HOME:$PATH - export PATH=$ANDROID_SDK_HOME/platform-tools:$PATH - export PATH=$ANDROID_SDK_HOME/build-tools/31.0.0:$PATH - -On Windows: - - set ANDROID_SDK_HOME=%LOCALAPPDATA%\Android\sdk - set ANDROID_NDK_HOME=%LOCALAPPDATA%\Android\sdk\ndk\23.0.7599858 - set PATH=%ANDROID_NDK_HOME%;%PATH% - set PATH=%ANDROID_SDK_HOME%\platform-tools;%PATH% - set PATH=%ANDROID_SDK_HOME%\build-tools\31.0.0;%PATH% - -On OSX: - - export ANDROID_SDK_HOME=$HOME/Library/Android/sdk - export ANDROID_NDK_HOME=$HOME/Library/Android/sdk/ndk/23.0.7599858 - export PATH=$ANDROID_NDK_PATH:$PATH - export PATH=$ANDROID_SDK_HOME/platform-tools:$PATH - export PATH=$ANDROID_SDK_HOME/build-tools/31.0.0:$PATH - -Note: If `jarsigner` is missing from your platform, you can find it in the -Android Studio install or in your Java installation. If you do not have Java, -you can get it with something like the following: - - sudo apt-get install openjdk-8-jdk - -### Android Build - -Use the following script to build the vkcube demo for Android: - - cd build-android - ./build_all.sh - -The APK can be installed on production devices with: +### Run vkcube - ./install_all.sh [-s <serial number>] +Use the following command to run vkcube for Android: -Note that there are no equivalent scripts on Windows yet, that work needs to -be completed. +```bash +cd build-android -### Run vkcube +# Optional +adb uninstall com.example.VkCube -Use the following command to run vkcube for Android: +adb install -r -g --no-incremental bin/VkCube.apk - adb shell am start com.example.VkCube/android.app.NativeActivity +adb shell am start com.example.VkCube/android.app.NativeActivity +``` ## Building on MacOS diff --git a/build-android/build_all.sh b/build-android/build_all.sh deleted file mode 100755 index 1a842e61..00000000 --- a/build-android/build_all.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/bash - -# Copyright 2017 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -ANDROID_BUILD_DIR=$(dirname $(readlink -f $0)) -PROJECT_DIR=$ANDROID_BUILD_DIR/.. - -if [ -z "${ANDROID_SDK_HOME}" ]; -then echo "Please set ANDROID_SDK_HOME, exiting"; exit 1; -else echo "ANDROID_SDK_HOME is ${ANDROID_SDK_HOME}"; -fi - -if [ -z "${ANDROID_NDK_HOME}" ]; -then echo "Please set ANDROID_NDK_HOME, exiting"; exit 1; -else echo "ANDROID_NDK_HOME is ${ANDROID_NDK_HOME}"; -fi - -if [[ $(uname) == "Linux" ]]; then - cores=$(nproc) || echo 4 -elif [[ $(uname) == "Darwin" ]]; then - cores=$(sysctl -n hw.ncpu) || echo 4 -fi - -function findtool() { - if [[ ! $(type -t $1) ]]; then - echo Command $1 not found, see ../BUILD.md; - exit 1; - fi -} - -# Check for dependencies -findtool aapt -findtool zipalign -findtool jarsigner - -set -ev - -DEMO_BUILD_DIR=$PROJECT_DIR/cube/android -echo DEMO_BUILD_DIR="${DEMO_BUILD_DIR}" - -function create_APK() { - aapt package -f -M AndroidManifest.xml -I "$ANDROID_SDK_HOME/platforms/android-23/android.jar" -S res -F bin/$1-unaligned.apk bin/libs - # update this logic to detect if key is already there. If so, use it, otherwise create it. - jarsigner -verbose -keystore ~/.android/debug.keystore -storepass android -keypass android bin/$1-unaligned.apk androiddebugkey - zipalign -f 4 bin/$1-unaligned.apk bin/$1.apk -} - -# -# update dependencies -# -( -pushd $ANDROID_BUILD_DIR -./update_external_sources_android.sh --no-build -popd -pushd $PROJECT_DIR -python3 scripts/generate_source.py $ANDROID_BUILD_DIR/third_party/Vulkan-Headers/registry --incremental -popd -) - -# -# build vkcube APK -# -( -pushd $DEMO_BUILD_DIR -ndk-build -j $cores -mkdir -p $DEMO_BUILD_DIR/cube/bin/libs/lib -cp -r $DEMO_BUILD_DIR/libs/* $DEMO_BUILD_DIR/cube/bin/libs/lib/ -cd $DEMO_BUILD_DIR/cube -create_APK vkcube -popd -) - -echo Builds succeeded -exit 0 diff --git a/build-android/install_all.sh b/build-android/install_all.sh deleted file mode 100755 index f2ecd902..00000000 --- a/build-android/install_all.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -# Copyright 2017 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -e - -# -# Parse parameters -# - -function printUsage { - echo "Supported parameters are:" - echo " -s|--serial <target device serial number> (optional)" - echo - echo "i.e. ${0##*/} -s <serial number>" - exit 1 -} - -if [[ $(($# % 2)) -ne 0 ]] -then - echo Parameters must be provided in pairs. - echo parameter count = $# - echo - printUsage - exit 1 -fi - -while [[ $# -gt 0 ]] -do - case $1 in - -s|--serial) - # include the flag, because we need to leave it off if not provided - serial="$2" - shift 2 - ;; - -*) - # unknown option - echo Unknown option: $1 - echo - printUsage - exit 1 - ;; - esac -done - -if [[ $serial ]]; then - echo serial = "${serial}" - serialFlag="-s $serial" - if [[ $(adb devices) != *"$serial"* ]] - then - echo Device not found: "${serial}" - echo - printUsage - exit 1 - fi -else - echo Using device $(adb get-serialno) -fi - -# Install everything built by build_all.sh -echo "adb $serialFlag install -r ../cube/android/cube/bin/vkcube.apk" -adb $serialFlag install -r ../cube/android/cube/bin/vkcube.apk - -exit $? diff --git a/build-android/update_external_sources_android.bat b/build-android/update_external_sources_android.bat deleted file mode 100755 index 5c6f2554..00000000 --- a/build-android/update_external_sources_android.bat +++ /dev/null @@ -1,134 +0,0 @@ -@echo off -REM Update source for vulkan-headers - -REM -REM Copyright 2016 The Android Open Source Project -REM Copyright (C) 2015 Valve Corporation -REM -REM Licensed under the Apache License, Version 2.0 (the "License"); -REM you may not use this file except in compliance with the License. -REM You may obtain a copy of the License at -REM -REM http://www.apache.org/licenses/LICENSE-2.0 -REM -REM Unless required by applicable law or agreed to in writing, software -REM distributed under the License is distributed on an "AS IS" BASIS, -REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -REM See the License for the specific language governing permissions and -REM limitations under the License. -REM - -setlocal EnableDelayedExpansion -set errorCode=0 -set ANDROID_BUILD_DIR=%~dp0 -set BUILD_DIR=%ANDROID_BUILD_DIR% -set BASE_DIR=%BUILD_DIR%\third_party -set VULKAN_HEADERS_DIR=%BASE_DIR%\Vulkan-Headers - -for %%X in (where.exe) do (set FOUND=%%~$PATH:X) -if not defined FOUND ( - echo Dependency check failed: - echo where.exe not found - echo This script requires Windows Vista or later, which includes where.exe. - set errorCode=1 -) - -where /q git.exe -if %ERRORLEVEL% equ 1 ( - echo Dependency check failed: - echo git.exe not found - echo Git for Windows can be downloaded here: https://git-scm.com/download/win - echo Install and ensure git.exe makes it into your PATH - set errorCode=1 -) - -where /q ndk-build.cmd -if %ERRORLEVEL% equ 1 ( - echo Dependency check failed: - echo ndk-build.cmd not found - echo Android NDK can be downloaded here: http://developer.android.com/ndk/guides/setup.html - echo Install and ensure ndk-build.cmd makes it into your PATH - set errorCode=1 -) - -REM ensure where is working with below false test -REM where /q foo -REM if %ERRORLEVEL% equ 1 ( -REM echo foo -REM ) - -:main - -if %errorCode% neq 0 (goto:error) - -REM Read the target versions from external file, which is shared with Linux script - -if not exist %ANDROID_BUILD_DIR%\vulkan-headers_revision_android ( - echo. - echo Missing vulkan-headers_revision_android file. Place it in %ANDROID_BUILD_DIR% - set errorCode=1 - goto:error -) - -set /p VULKAN_HEADERS_REVISION= < vulkan-headers_revision_android -echo VULKAN_HEADERS_REVISION=%VULKAN_HEADERS_REVISION% - - -echo Creating vulkan-headers in %BASE_DIR% - -set sync-vulkan-headers=1 - -if %sync-vulkan-headers% equ 1 ( - if %ERRORLEVEL% neq 0 (goto:error) - if not exist %VULKAN_HEADERS_DIR% ( - call:create_vulkan-headers - ) - if %errorCode% neq 0 (goto:error) - call:update_vulkan-headers - if %errorCode% neq 0 (goto:error) -) - -echo. -echo Exiting -goto:finish - -:error -echo. -echo Halting due to error -goto:finish - -:finish -if not "%cd%\" == "%BUILD_DIR%" ( cd %BUILD_DIR% ) -endlocal -REM This needs a fix to return error, something like exit %errorCode% -REM Right now it is returning 0 -goto:eof - - - -REM // ======== Functions ======== // - -:create_vulkan-headers - echo. - echo Creating local vulkan-headers repository %VULKAN_HEADERS_DIR% - if not exist "%VULKAN_HEADERS_DIR%\" mkdir %VULKAN_HEADERS_DIR% - cd %VULKAN_HEADERS_DIR% - git clone https://github.com/KhronosGroup/Vulkan-Headers.git . - git checkout %VULKAN_HEADERS_REVISION% - if not exist %VULKAN_HEADERS_DIR%\registry ( - echo vulkan-headers source download failed! - set errorCode=1 - ) -goto:eof - -:update_vulkan-headers - echo. - echo Updating %VULKAN_HEADERS_DIR% - cd %VULKAN_HEADERS_DIR% - git fetch --all - git checkout %VULKAN_HEADERS_REVISION% - if not exist %VULKAN_HEADERS_DIR%\registry ( - echo vulkan-headers source update failed! - set errorCode=1 - ) -goto:eof diff --git a/build-android/update_external_sources_android.sh b/build-android/update_external_sources_android.sh deleted file mode 100755 index d86682d9..00000000 --- a/build-android/update_external_sources_android.sh +++ /dev/null @@ -1,115 +0,0 @@ -#!/bin/bash -# Update source for vulkan-headers - -# Copyright 2016 The Android Open Source Project -# Copyright (C) 2015 Valve Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -e - -sync_vulkan_headers=1 - -ANDROIDBUILDDIR=$PWD -BUILDDIR=$ANDROIDBUILDDIR -BASEDIR=$BUILDDIR/third_party - -VULKAN_HEADERS_REVISION=$(cat $ANDROIDBUILDDIR/vulkan-headers_revision_android) - -echo "VULKAN_HEADERS_REVISION=$VULKAN_HEADERS_REVISION" - -VULKAN_HEADERS_URL=$(cat $ANDROIDBUILDDIR/vulkan-headers_url_android) - -if [[ $(uname) == "Linux" ]]; then - cores="$(nproc || echo 4)" -elif [[ $(uname) == "Darwin" ]]; then - cores=$(sysctl -n hw.ncpu) -fi - -# -# Parse parameters -# - -function printUsage { - echo "Supported parameters are:" - echo " --abi <abi> (optional)" - echo " --no-build (optional)" - echo - echo "i.e. ${0##*/} --abi arm64-v8a \\" - exit 1 -} - -while [[ $# -gt 0 ]] -do - case $1 in - --abi) - abi="$2" - shift 2 - ;; - --no-build) - nobuild=1 - shift 1 - ;; - *) - # unknown option - echo Unknown option: $1 - echo - printUsage - exit 1 - ;; - esac -done - -echo abi=$abi -if [[ -z $abi ]] -then - echo No abi provided, so building for all supported abis. -fi - -echo no-build=$nobuild -if [[ $nobuild ]] -then - echo Skipping build. -fi - -function create_vulkan-headers () { - rm -rf $BASEDIR/Vulkan-Headers - echo "Creating local Vulkan-Headers repository ($BASEDIR/Vulkan-Headers)." - mkdir -p $BASEDIR/Vulkan-Headers - cd $BASEDIR/Vulkan-Headers - git clone $VULKAN_HEADERS_URL . - git checkout $VULKAN_HEADERS_REVISION -} - -function update_vulkan-headers () { - echo "Updating $BASEDIR/Vulkan-Headers" - cd $BASEDIR/Vulkan-Headers - if [[ $(git config --get remote.origin.url) != $VULKAN_HEADERS_URL ]]; then - echo "Vulkan-Headers URL mismatch, recreating local repo" - create_vulkan-headers - return - fi - git fetch --all - git checkout $VULKAN_HEADERS_REVISION -} - -if [ $sync_vulkan_headers -eq 1 ]; then - if [ ! -d "$BASEDIR/Vulkan-Headers" -o ! -d "$BASEDIR/Vulkan-Headers/.git" ]; then - create_vulkan-headers - fi - update_vulkan-headers -fi - -echo "" -echo "${0##*/} finished." - diff --git a/build-android/vulkan-headers_revision_android b/build-android/vulkan-headers_revision_android deleted file mode 100644 index 15a8013f..00000000 --- a/build-android/vulkan-headers_revision_android +++ /dev/null @@ -1 +0,0 @@ -v1.3.267 diff --git a/build-android/vulkan-headers_url_android b/build-android/vulkan-headers_url_android deleted file mode 100644 index 9ce98515..00000000 --- a/build-android/vulkan-headers_url_android +++ /dev/null @@ -1 +0,0 @@ -https://github.com/KhronosGroup/Vulkan-Headers.git diff --git a/cube/android/.gitignore b/cube/android/.gitignore deleted file mode 100644 index 8008f254..00000000 --- a/cube/android/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -bin -libs -obj diff --git a/cube/android/cube/AndroidManifest.xml b/cube/android/AndroidManifest.xml index 1bf9080b..fbec106d 100644 --- a/cube/android/cube/AndroidManifest.xml +++ b/cube/android/AndroidManifest.xml @@ -6,15 +6,14 @@ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.INTERNET"/> - <!-- This is the platform API where NativeActivity was introduced. --> <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="23"/> <!-- This .apk has no Java code itself, so set hasCode to false. --> - <application android:label="@string/app_name" android:hasCode="false" android:debuggable='true'> + <application android:label="VkCube" android:hasCode="false" android:debuggable='true'> <!-- Our activity is the built-in NativeActivity framework class. This will take care of integrating with our NDK code. --> - <activity android:name="android.app.NativeActivity" android:label="@string/app_name" android:exported="true"> + <activity android:name="android.app.NativeActivity" android:label="VkCube" android:exported="true"> <!-- Tell NativeActivity the name of or .so --> <meta-data android:name="android.app.lib_name" android:value="VkCube"/> <intent-filter> diff --git a/cube/android/CMakeLists.txt b/cube/android/CMakeLists.txt index 9d4e69c8..5783fa90 100644 --- a/cube/android/CMakeLists.txt +++ b/cube/android/CMakeLists.txt @@ -48,6 +48,8 @@ target_sources(android_glue PRIVATE ${native_app_glue_dir}/android_native_app_glue.h ) +set_target_properties(vkcube PROPERTIES OUTPUT_NAME "VkCube") + target_link_libraries(vkcube PRIVATE android_glue log diff --git a/cube/android/README.md b/cube/android/README.md index 75b1747f..08ed7488 100644 --- a/cube/android/README.md +++ b/cube/android/README.md @@ -26,3 +26,16 @@ Then run the script: ./generate_vulkan_wrapper.py ../cube/android/vulkan_wrapper.cpp clang-format -i vulkan_wrapper.h clang-format -i vulkan_wrapper.cpp + +# Running vkcube on Android + +```bash +cd build-android + +# Optional +adb uninstall com.example.VkCube + +adb install -r -g --no-incremental bin/VkCube.apk + +adb shell am start com.example.VkCube/android.app.NativeActivity +```
\ No newline at end of file diff --git a/cube/android/cube-with-layers/AndroidManifest.xml b/cube/android/cube-with-layers/AndroidManifest.xml deleted file mode 100644 index 50b216e4..00000000 --- a/cube/android/cube-with-layers/AndroidManifest.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.VkCubeWithLayers" android:versionCode="1" android:versionName="1.0"> - - <!-- Allow this app to read and write files (for use by tracing libraries). --> - <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> - <uses-permission android:name="android.permission.INTERNET"/> - - <!-- This is the platform API where NativeActivity was introduced. --> - <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="23"/> - - <!-- This .apk has no Java code itself, so set hasCode to false. --> - <application android:label="@string/app_name" android:hasCode="false" android:debuggable='true'> - - <!-- Our activity is the built-in NativeActivity framework class. - This will take care of integrating with our NDK code. --> - <activity android:name="android.app.NativeActivity" android:label="@string/app_name" android:exported="true"> - <!-- Tell NativeActivity the name of or .so --> - <meta-data android:name="android.app.lib_name" android:value="VkCube"/> - <intent-filter> - <action android:name="android.intent.action.MAIN"/> - <category android:name="android.intent.category.LAUNCHER"/> - </intent-filter> - </activity> - </application> - -</manifest> diff --git a/cube/android/cube-with-layers/custom_rules.xml b/cube/android/cube-with-layers/custom_rules.xml deleted file mode 100644 index 0ca5933e..00000000 --- a/cube/android/cube-with-layers/custom_rules.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project name="NativeActivity" default="help"> - -<property name="cubeWithLayersDir" location="../libs-with-layers" /> -<property name="cubeDir" location="../libs" /> -<property name="layersDir" location="../../../build-android/libs" /> - -<echo>VkCubeWithLayers: Creating libs-with-layers</echo> -<mkdir dir="${cubeWithLayersDir}"/> - -<echo>VkCubeWithLayers: Copying libs from demos/android</echo> -<copy todir="${cubeWithLayersDir}"> -<fileset dir="${cubeDir}"/> -</copy> - -<echo>VkCubeWithLayers: Copying layers from build-android</echo> -<copy todir="${cubeWithLayersDir}"> -<fileset dir="${layersDir}"/> -</copy> - -<!-- Point ndk-build at the libs-with-layers common dir --> -<echo>VkCubeWithLayers: Overriding native.libs.absolute.dir with ${cubeWithLayersDir}</echo> -<property name="native.libs.absolute.dir" location="${cubeWithLayersDir}" /> - -</project> diff --git a/cube/android/cube-with-layers/res/values/strings.xml b/cube/android/cube-with-layers/res/values/strings.xml deleted file mode 100644 index ecd779e4..00000000 --- a/cube/android/cube-with-layers/res/values/strings.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<!-- This file contains resource definitions for displayed strings, allowing - them to be changed based on the locale and options. --> - -<resources> - <!-- Simple strings. --> - <string name="app_name">VkCubeWithLayers</string> - -</resources> diff --git a/cube/android/cube/custom_rules.xml b/cube/android/cube/custom_rules.xml deleted file mode 100644 index 31eb31ad..00000000 --- a/cube/android/cube/custom_rules.xml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project name="NativeActivity" default="help"> -<!-- Point ndk-build at the libs created in common dir --> -<echo>vkcube: Overriding native.libs.absolute.dir with ../libs</echo> -<property name="native.libs.absolute.dir" location="../libs" /> -</project> diff --git a/cube/android/cube/res/values/strings.xml b/cube/android/cube/res/values/strings.xml deleted file mode 100644 index 8adead25..00000000 --- a/cube/android/cube/res/values/strings.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<!-- This file contains resource definitions for displayed strings, allowing - them to be changed based on the locale and options. --> - -<resources> - <!-- Simple strings. --> - <string name="app_name">VkCube</string> - -</resources> diff --git a/cube/android/jni/Android.mk b/cube/android/jni/Android.mk deleted file mode 100644 index 090f7862..00000000 --- a/cube/android/jni/Android.mk +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright 2015 The Android Open Source Project -# Copyright (C) 2015 Valve Corporation - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -LOCAL_PATH := $(abspath $(call my-dir)) -SRC_DIR := $(LOCAL_PATH)/../../.. -DEMO_DIR := $(SRC_DIR)/cube - -include $(CLEAR_VARS) -LOCAL_MODULE := VkCube -LOCAL_SRC_FILES += $(DEMO_DIR)/cube.c \ - $(DEMO_DIR)/android/vulkan_wrapper.cpp \ - $(DEMO_DIR)/android/android_util.cpp -LOCAL_C_INCLUDES += $(SRC_DIR)/build-android/third_party/Vulkan-Headers/include \ - $(DEMO_DIR)/android/include \ - $(SRC_DIR)/libs \ - $(DEMO_DIR)/android/ \ - $(SRC_DIR)/build-android/generated/include -LOCAL_CFLAGS += -DVK_USE_PLATFORM_ANDROID_KHR --include=$(DEMO_DIR)/android/vulkan_wrapper.h -LOCAL_WHOLE_STATIC_LIBRARIES += android_native_app_glue -LOCAL_LDLIBS := -llog -landroid -LOCAL_LDFLAGS := -u ANativeActivity_onCreate -include $(BUILD_SHARED_LIBRARY) - -$(call import-module,android/native_app_glue) diff --git a/cube/android/jni/Application.mk b/cube/android/jni/Application.mk deleted file mode 100644 index 788ff73b..00000000 --- a/cube/android/jni/Application.mk +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2015 The Android Open Source Project -# Copyright (C) 2015 Valve Corporation - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -APP_ABI := armeabi-v7a arm64-v8a x86 x86_64 -APP_PLATFORM := android-23 -APP_STL := c++_static -APP_MODULES := VkCube -NDK_TOOLCHAIN_VERSION := clang diff --git a/scripts/android.py b/scripts/android.py new file mode 100644 index 00000000..f976a2f5 --- /dev/null +++ b/scripts/android.py @@ -0,0 +1,202 @@ +#!/usr/bin/env python3 +# Copyright (c) 2023 Valve Corporation +# Copyright (c) 2023 LunarG, Inc. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# NOTE: Android this documentation is crucial for understanding the layout of the NDK. +# https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md + +# NOTE: Environment variables we can rely on users/environments setting. +# https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md#environment-variables-2 + +import argparse +import os +import sys +import shutil +import subprocess + +# helper to define paths relative to the repo root +def RepoRelative(path): + return os.path.abspath(os.path.join(os.path.dirname(__file__), '..', path)) + +# Points to the directory containing the top level CMakeLists.txt +PROJECT_SRC_DIR = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], '..')) +if not os.path.isfile(f'{PROJECT_SRC_DIR}/CMakeLists.txt'): + print(f'PROJECT_SRC_DIR invalid! {PROJECT_SRC_DIR}') + sys.exit(1) + +# Runs a command in a directory and returns its return code. +# Directory is project root by default, or a relative path from project root +def RunShellCmd(command, start_dir = PROJECT_SRC_DIR, env=None, verbose=False): + # Flush stdout here. Helps when debugging on CI. + sys.stdout.flush() + + if start_dir != PROJECT_SRC_DIR: + start_dir = RepoRelative(start_dir) + cmd_list = command.split(" ") + + if verbose: + print(f'CICMD({cmd_list}, env={env})') + subprocess.check_call(cmd_list, cwd=start_dir, env=env) + +# Manifest file describing out test application +def get_android_manifest() -> str: + manifest = RepoRelative('cube/android/AndroidManifest.xml') + if not os.path.isfile(manifest): + print(f"Unable to find manifest for APK! {manifest}") + sys.exit(-1) + return manifest + +# Generate the APK from the CMake binaries +def generate_apk(SDK_ROOT : str, CMAKE_INSTALL_DIR : str) -> str: + apk_dir = RepoRelative('build-android/bin') + + # Delete APK directory since it could contain files from old runs + if os.path.isdir(apk_dir): + shutil.rmtree(apk_dir) + + shutil.copytree(CMAKE_INSTALL_DIR, apk_dir) + + android_manifest = get_android_manifest() + + android_jar = f"{SDK_ROOT}/platforms/android-26/android.jar" + if not os.path.isfile(android_jar): + print(f"Unable to find {android_jar}!") + sys.exit(-1) + + apk_name = 'VkCube' + + unaligned_apk = f'{apk_dir}/{apk_name}-unaligned.apk' + test_apk = f'{apk_dir}/{apk_name}.apk' + + # Create APK + RunShellCmd(f'aapt package -f -M {android_manifest} -I {android_jar} -F {unaligned_apk} {CMAKE_INSTALL_DIR}') + + # Align APK + RunShellCmd(f'zipalign -f 4 {unaligned_apk} {test_apk}') + + # Create Key (If it doesn't already exist) + debug_key = RepoRelative(f'{apk_dir}/debug.keystore') + ks_pass = 'android' + if not os.path.isfile(debug_key): + dname = 'CN=Android-Debug,O=Android,C=US' + RunShellCmd(f'keytool -genkey -v -keystore {debug_key} -alias androiddebugkey -storepass {ks_pass} -keypass {ks_pass} -keyalg RSA -keysize 2048 -validity 10000 -dname {dname}') + + # Sign APK + RunShellCmd(f'apksigner sign --verbose --ks {debug_key} --ks-pass pass:{ks_pass} {test_apk}') + +# Android APKs can contain binaries for multiple ABIs (armeabi-v7a, arm64-v8a, x86, x86_64). +# https://en.wikipedia.org/wiki/Apk_(file_format)#Package_contents +# +# As a result CMake will need to be run multiple times to create a complete test APK that can be run on any Android device. +def main(): + configs = ['Release', 'Debug'] + + parser = argparse.ArgumentParser() + parser.add_argument('--config', type=str, choices=configs, default=configs[0]) + parser.add_argument('--app-abi', dest='android_abi', type=str, default="arm64-v8a") + parser.add_argument('--app-stl', dest='android_stl', type=str, choices=["c++_static", "c++_shared"], default="c++_static") + parser.add_argument('--apk', action='store_true', help='Generate an APK as a post build step.') + parser.add_argument('--tests', action='store_true', help='Build tests.') + parser.add_argument('--clean', action='store_true', help='Cleans CMake build artifacts') + args = parser.parse_args() + + cmake_config = args.config + android_abis = args.android_abi.split(" ") + android_stl = args.android_stl + create_apk = args.apk + build_tests = args.tests + clean = args.clean + + if "ANDROID_NDK_HOME" not in os.environ: + print("Cannot find ANDROID_NDK_HOME!") + sys.exit(1) + + android_ndk_home = os.environ.get('ANDROID_NDK_HOME') + android_toolchain = f'{android_ndk_home}/build/cmake/android.toolchain.cmake' + + # The only tool we require for building is CMake/Ninja + required_cli_tools = ['cmake', 'ninja'] + + # If we are building an APK we need a few more tools. + if create_apk: + if "ANDROID_SDK_ROOT" not in os.environ: + print("Cannot find ANDROID_SDK_ROOT!") + sys.exit(1) + + android_sdk_root = os.environ.get('ANDROID_SDK_ROOT') + print(f"ANDROID_SDK_ROOT = {android_sdk_root}") + required_cli_tools += ['aapt', 'zipalign', 'keytool', 'apksigner'] + + print(f"ANDROID_NDK_HOME = {android_ndk_home}") + print(f"Build configured for {cmake_config} | {android_stl} | {android_abis} | APK {create_apk}") + + if not os.path.isfile(android_toolchain): + print(f'Unable to find android.toolchain.cmake at {android_toolchain}') + exit(-1) + + for tool in required_cli_tools: + path = shutil.which(tool) + if path is None: + print(f"Unable to find {tool}!") + exit(-1) + + print(f"Using {tool} : {path}") + + cmake_install_dir = RepoRelative('build-android/libs') + + # Delete install directory since it could contain files from old runs + if os.path.isdir(cmake_install_dir): + print("Cleaning CMake install") + shutil.rmtree(cmake_install_dir) + + for abi in android_abis: + build_dir = RepoRelative(f'build-android/cmake/{abi}') + lib_dir = f'lib/{abi}' + + if clean: + print("Deleting CMakeCache.txt") + + # Delete CMakeCache.txt to ensure clean builds + # NOTE: CMake 3.24 has --fresh which would be better to use in the future. + cmake_cache = f'{build_dir}/CMakeCache.txt' + if os.path.isfile(cmake_cache): + os.remove(cmake_cache) + + cmake_cmd = f'cmake -S . -B {build_dir} -G Ninja' + + cmake_cmd += f' -D CMAKE_BUILD_TYPE={cmake_config}' + cmake_cmd += f' -D UPDATE_DEPS=ON -D UPDATE_DEPS_DIR={build_dir}' + cmake_cmd += f' -D CMAKE_TOOLCHAIN_FILE={android_toolchain}' + cmake_cmd += f' -D CMAKE_ANDROID_ARCH_ABI={abi}' + cmake_cmd += f' -D CMAKE_INSTALL_LIBDIR={lib_dir}' + cmake_cmd += f' -D BUILD_TESTS={build_tests}' + cmake_cmd += f' -D CMAKE_ANDROID_STL_TYPE={android_stl}' + + cmake_cmd += ' -D ANDROID_PLATFORM=26' + cmake_cmd += ' -D ANDROID_USE_LEGACY_TOOLCHAIN_FILE=NO' + + RunShellCmd(cmake_cmd) + + build_cmd = f'cmake --build {build_dir}' + RunShellCmd(build_cmd) + + install_cmd = f'cmake --install {build_dir} --prefix {cmake_install_dir}' + RunShellCmd(install_cmd) + + if create_apk: + generate_apk(SDK_ROOT = android_sdk_root, CMAKE_INSTALL_DIR = cmake_install_dir) + +if __name__ == '__main__': + main() |
