Skip to content

Commit

Permalink
Fixes for building gfxr on Windows targetting Android (#159)
Browse files Browse the repository at this point in the history
Some changes to get Dive Android libraries building on Windows after the GFXR addition.

+ Triggering gfxr gradle builds and extracting/copying files is now only done inside CMakeLists.txt for the Linux host build, this has been implemented in `scripts/build_android.bat` for Windows.
+ The gfxr builds for different versions (Debug/Release) are separated so that it's easier to only build one by modifying `BUILD_TYPE` in `scripts/build_android.bat`
+ Different from the Linux host build, the replay folder is copied to `build_android/Debug/third_party/gfxreconstruct/android/tools/replay/` rather than `build_android/Debug/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/debug`
+ Updated documentation

I will make a followup CL to update building Android on Linux too.
  • Loading branch information
angela28chen authored Jan 13, 2025
1 parent a87e6c1 commit 696d6f4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 24 deletions.
43 changes: 23 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ if(DIVE_NO_DISASSEMBLY)
add_definitions(-DDIVE_NO_DISASSEMBLY=1)
endif()

option(DIVE_ENABLE_PERFETTO, "Enalbe functionality to get perfetto trace." OFF)
option(DIVE_ENABLE_PERFETTO, "Enable functionality to get perfetto trace." OFF)
include(perfetto.cmake)

add_subdirectory(capture_service)
Expand All @@ -104,30 +104,33 @@ if(NOT ANDROID)

add_subdirectory(third_party/gfxreconstruct)
else()
if(NOT CMAKE_HOST_WIN32)
message(CHECK_START "Build gfxr for android")
execute_process(
COMMAND ./gradlew assembleDebug
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android
)

execute_process(
COMMAND ./gradlew assembleDebug
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android
)

execute_process(
COMMAND ./gradlew assembleRelease
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android
)
execute_process(
COMMAND ./gradlew assembleRelease
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android
)

file(ARCHIVE_EXTRACT
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/layer/build/outputs/aar/layer-debug.aar"
DESTINATION "${CMAKE_SOURCE_DIR}/build_android/Debug/third_party/gfxreconstruct/android/layer"
)
file(ARCHIVE_EXTRACT
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/layer/build/outputs/aar/layer-debug.aar"
DESTINATION "${CMAKE_SOURCE_DIR}/build_android/Debug/third_party/gfxreconstruct/android/layer"
)

file(ARCHIVE_EXTRACT
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/layer/build/outputs/aar/layer-release.aar"
DESTINATION "${CMAKE_SOURCE_DIR}/build_android/Release/third_party/gfxreconstruct/android/layer"
)
file(ARCHIVE_EXTRACT
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/layer/build/outputs/aar/layer-release.aar"
DESTINATION "${CMAKE_SOURCE_DIR}/build_android/Release/third_party/gfxreconstruct/android/layer"
)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/debug DESTINATION ${CMAKE_SOURCE_DIR}/build_android/Debug/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/debug)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/debug DESTINATION ${CMAKE_SOURCE_DIR}/build_android/Debug/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/debug)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/release DESTINATION ${CMAKE_SOURCE_DIR}/build_android/Release/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/release)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/release DESTINATION ${CMAKE_SOURCE_DIR}/build_android/Release/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/release)
message(CHECK_PASS "successful")
endif()
endif()

option(DIVE_UNIT_TESTS, "Build unit tests for dive")
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ git submodule update --init --recursive
- gRPC [dependencies](https://github.com/grpc/grpc/blob/master/BUILDING.md#pre-requisites)
- Android NDK (currently we are using 25.2.9519653). Set the `ANDROID_NDK_HOME` environment variable.
```
export ANDROID_NDK_HOME=~/andriod_sdk/ndk/25.2.9519653
export ANDROID_NDK_HOME=~/android_sdk/ndk/25.2.9519653
```
- Mako Templates for Python: can be installed with following commandline
```
pip install Mako
```
- gfxreconstruct [dependencies](https://github.com/LunarG/gfxreconstruct/blob/dev/BUILD.md#android-development-requirements), if targetting Android

### Building Dive host tool on Linux
```
Expand Down Expand Up @@ -97,7 +98,14 @@ And on Windows, Open Developer Command Prompt for VS 2022(or 2019) and run
scripts\build_android.bat
```

It will build both debug and release version of the libraries under `build_android` folder.
It will build both debug and release version of the libraries under `build_android` folder. It will also build gfxreconstruct binaries under `third_party/gfxreconstruct/android` and copy them to under `build_android`.

Troubleshooting tips:
- Open the gradle project at `third_party/gfxreconstruct/android` in Android Studio and try making recommended changes to the project and building from there.
- Delete build folders for a clean build
- `third_party/gfxreconstruct/android/layer/build`
- `third_party/gfxreconstruct/android/tools/replay/build`
- `build_android`

### CLI Tool for capture and cleanup
#### Capture with command line tool for Android applications
Expand Down
45 changes: 43 additions & 2 deletions scripts/build_android.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
set PROJECT_ROOT=%~dp0\..
set BUILD_TYPE=Debug Release
set SRC_DIR=%PROJECT_ROOT%
set GFXR_ROOT_DIR=%PROJECT_ROOT%\\third_party\\gfxreconstruct\\android
set startTime=%time%

(for %%b in (%BUILD_TYPE%) do (
setlocal enabledelayedexpansion
echo %%b
echo.
echo %%b : Building dive android layer
set build=%%b
set BUILD_DIR=%PROJECT_ROOT%\\build_android\\!build!
echo "BUILD_DIR: " !BUILD_DIR!
echo BUILD_DIR: !BUILD_DIR!
md !BUILD_DIR!

pushd !BUILD_DIR!
cmake -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_HOME%/build/cmake/android.toolchain.cmake ^
-G "Ninja"^
Expand All @@ -47,5 +50,43 @@ set startTime=%time%
popd
))

pushd !GFXR_ROOT_DIR!
(for %%b in (%BUILD_TYPE%) do (
setlocal enabledelayedexpansion
echo.
echo %%b : Building gfxr android layer
set build=%%b

echo GFXR_ROOT_DIR: !GFXR_ROOT_DIR!
call gradlew assemble!build!
))
popd


(for %%b in (%BUILD_TYPE%) do (
setlocal enabledelayedexpansion
if "%%b" == "Release" set build_lowercase=release
if "%%b" == "Debug" set build_lowercase=debug
echo.
echo %%b : Moving gfxr files
set build=%%b
set BUILD_DIR=%PROJECT_ROOT%\\build_android\\!build!

set GFXR_BUILD_DIR=!BUILD_DIR!\\third_party\\gfxreconstruct\\android
if not exist !GFXR_BUILD_DIR! md !GFXR_BUILD_DIR!

echo Extracting gfxr android layer into build_android
set GFXR_LAYER_SRC=!GFXR_ROOT_DIR!\\layer\\build\\outputs\\aar\\layer-!build_lowercase!.aar
set GFXR_LAYER_DST=!GFXR_BUILD_DIR!\\layer
if not exist !GFXR_LAYER_DST! md !GFXR_LAYER_DST!
tar -xf !GFXR_LAYER_SRC! -C !GFXR_LAYER_DST!

echo Copying gfxr android replay into build_android
set GFXR_REPLAY_SRC=!GFXR_ROOT_DIR!\\tools\\replay\\build\\outputs\\apk\\!build_lowercase!
set GFXR_REPLAY_DST=!GFXR_BUILD_DIR!\\tools\\replay
if not exist !GFXR_REPLAY_DST! md !GFXR_REPLAY_DST!
copy !GFXR_REPLAY_SRC! !GFXR_REPLAY_DST!
))

echo Start Time: %startTime%
echo Finish Time: %time%

0 comments on commit 696d6f4

Please sign in to comment.