Open3

Android Game Development Extension for Visual Studio をCMakeで使いたかったけどダメだった

okuokuokuoku

https://developer.android.com/games/agde

Android用に、Google謹製のVisual Studio拡張がある。昔はnVIDIAとかが同様な拡張を配ってたけど、よりモダンなLLDB統合などをくっつけて登場。

何故かゲーム開発専用。まぁデザインツールとか一切ないから通常のアプリ開発には使えないしね。。

CMakeでは.vcxprojが生成できるものの、生成したプロジェクトを手修正しないと正常に使えない。というわけでCMake側をちょっとパッチすれば使えるようになると思われる。

okuokuokuoku

NDKが見つからない

適当に

cmake -G "Visual Studio 17 2022" -A Android-x86_64 ..

のようにしてconfigureしてみるとNDKが見つからないエラーが出る。

-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
CMake Error at CMakeLists.txt:19 (project):
  Failed to run MSBuild command:

    C:/Program Files/Microsoft Visual Studio/2022/Professional/MSBuild/Current/Bin/amd64/MSBuild.exe

  to get the value of VCTargetsPath:

    MSBuild version 17.5.1+f6fdcf537 for .NET Framework
    2023/07/27 19:31:31 にビルドを開始しました。
    Included response file: C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\MSBuild.rsp

    ノード 1 上のプロジェクト "C:\cygwin64\home\oku\yuniframe\root\temp\CMakeFiles\3.25.1\VCTargetsPath.vcxproj" (既定のターゲット)。
    C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Google\Google.Android.Cpp.Common.targets(455,5): error : Please install Android NDK [25.1.8937393] at the expected location 'C:\Users\oku\AppData\Local\Android\Sdk\ndk\25.1.8937393\' [C:\cygwin64\home\oku\yuniframe\root\temp\CMakeFiles\3.25.1\VCTargetsPath.vcxproj]
    プロジェクト "C:\cygwin64\home\oku\yuniframe\root\temp\CMakeFiles\3.25.1\VCTargetsPath.vcxproj" (既定のターゲット)  のビルドが終了しました -- 失敗。

    ビルドに失敗しました。

    "C:\cygwin64\home\oku\yuniframe\root\temp\CMakeFiles\3.25.1\VCTargetsPath.vcxproj" (既定のターゲット) (1) ->
    (AndroidPrebuildErrorChecking ターゲット) ->
      C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Google\Google.Android.Cpp.Common.targets(455,5): error : Please install Android NDK [25.1.8937393] at the expected location 'C:\Users\oku\AppData\Local\Android\Sdk\ndk\25.1.8937393\' [C:\cygwin64\home\oku\yuniframe\root\temp\CMakeFiles\3.25.1\VCTargetsPath.vcxproj]

        0 個の警告
        1 エラー

    経過時間 00:00:00.53


  Exit code: 1

これは Visual Studioの Tools → Android Game Development Extension → Android SDK Manager からインストールすればOK。

Show package detailsで個別のバージョンをインストールできる。ただし何故かSDKの場所を変更できなかった。

okuokuokuoku

CMAKE_C_COMPILER が設定されない。

これはCMake側で cl.exe 決め打ちなため。Tegra用のAndroid等は対応が入ってるのにGoogle謹製のに対応していないとは。。手で指定できる。

cmake -G "Visual Studio 17 2022" -A Android-x86_64 -DCMAKE_C_COMPILER=C:/Users/oku/AppData/Local/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -DCMAKE_CXX_COMPILER=C:/Users/oku/AppData/Local/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe ..

が、生成されたプロジェクトがビルドできないのでconfigureに失敗するのは変わらない。 --debug-trycompile を付けて確認したところ、ビルドがWindows想定になっていてダメそうだった。