MAUIでWindowsアプリのHallo World!
前回、Visual Studio 2022 17.3 (Preview)時点のMAUIで、WindowsアプリのHallo Worldを試しました。
MAUIでAndroidアプリのHallo World!
今回は、Androidアプリを実行します。
ビルド対象にAndroidアプリを追加する
前回、Windowsアプリだけを対象にしたので、Androidアプリを追加します。
これで、WindowsアプリとAndroidアプリを同時に開発できます。
.csprojファイルを編集します。
<!--
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
-->
<TargetFrameworks>net6.0-android</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
AndroidアプリでHallo World!
Android SDKがインストールされていない場合、ツールバーの[Windows Machine]を[Android Emulator]にすると、Android SDKとEmuratorのインストールがウィザードされます。
手順 は公式参照
ツールバーに作成したEmuratorが表示された状態でクリックすれば、Emuratorが起動しアプリが実行されます。
※右側に[Android デバイスマネージャ][Android SDK マネージャ]があるので、SDKやEmuratorを変更できます。
※USBデバッグを有効にした実機をUSB接続すれば、[Android Local Device]から選択できます。
余談:ホットリロードに対応
最近は当たり前ですが、ホットリロード対応です。(Windowsアプリでも)
アプリケーションを起動したままメインページを編集して保存します。
変更前
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />
変更後
<Button
x:Name="CounterBtn"
Text="クリックミー"
Background="red"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />