1
1

More than 1 year has passed since last update.

.NET MAUI (Hallo, World!~Androidアプリ編~)

Last updated at Posted at 2022-05-28

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]から選択できます。
image.png

起動しました。
image.png

余談:ホットリロードに対応

最近は当たり前ですが、ホットリロード対応です。(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" />

アプリケーションを再起動することなく編集内容が反映されました。
image.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1