SDV 開発用に IDE を設定する

Android Studio for Platform(ASfP)は、Android Automotive OS(AAOS)ソフトウェア定義車両(SDV)プラットフォーム開発に推奨される統合開発環境(IDE)です。ASfP は、SDV サービス バンドル用の Rust を含む、AAOS SDV プラットフォームで使用されるすべての言語をサポートしています。

このページでは、SDV 固有の設定のみについて説明します。一般的な ASfP の機能とワークフローについて詳しくは、Android Studio for Platform をご覧ください。

ASfP は、x86-64 CPU を搭載した 64 ビット Linux でのみ動作します。ローカルの Linux ワークステーションまたはクラウドで使用できます。クラウドの設定の詳細については、クラウド開発をご覧ください。

ASfP をインストールする

ASfP のデフォルトの最大ヒープサイズは 30 GB です。プラットフォームのチェックアウトのインデックス登録では、特に同じマシンでマルチ VM Cuttlefish デバイスも実行している場合に、大量のメモリが使用されます。プロジェクトのスコープを、作業するディレクトリに限定し、必要に応じて ASfP のメモリ設定で最大ヒープサイズを調整します。

ASfP は、IDE 内での自動更新をサポートしています。詳しくは、プラットフォーム向け Android Studio を更新するをご覧ください。ASfP のダウンロードとインストール、システム要件の確認について詳しくは、Android Studio for Platform をインストールするをご覧ください。

SDV プロジェクトを作成する

始める前に、AAOS SDV チェックアウトを初期化、同期、ビルドします。チェックアウトの設定の詳細については、コードの場所とダウンロード、ビルド、実行をご覧ください。

SDV プロジェクトを作成する手順は次のとおりです。

  1. ASfP で新しいプロジェクトを作成し、リポジトリ チェックアウトとして AAOS SDV チェックアウトのルートを選択します。ウィザードの手順の詳細については、プロジェクトを作成またはインポートするをご覧ください。
  2. ASfP でプロジェクトを作成したら、[ASfP] > [Project] > [Open Config] を選択して .asfp-project ファイルを開きます。
  3. ファイルの内容を次の例に置き換え、repo をチェックアウトのパスに設定します。

    repo: /path/to/sdv_source
    lunch: sdv_core_cf-aosp_current-userdebug
    directories:
      include:
        -   system/software_defined_vehicle/samples
    other_languages:
      -   rust
    
  4. 作業するエリアの lunch と directories を更新します。インデックス登録と同期を高速に保つには、アクティブに変更するディレクトリのみを含めます。次の表に、一般的な SDV ターゲットとディレクトリを示します。

    SDV 開発の重点 lunch 個の目標 推奨 directories
    SDV サービス バンドル sdv_core_cf-aosp_current-userdebug サービス カタログとバンドル ディレクトリ(system/software_defined_vehicle/samples など)
    SDV コア プラットフォームの統合 sdv_core_cf-aosp_current-userdebug system/software_defined_vehicle/middleware、system/software_defined_vehicle/automotive_services、device/google/sdv
    SDV IVI 上の SDV ゲートウェイ sdv_ivi_cf-aosp_current-userdebug system/software_defined_vehicle/sdv_gateway、system/software_defined_vehicle/samples/sdv_gateway、packages/services/Car
    SDV メディアに安全性を表示 sdv_media_har_cf-aosp_current-userdebug packages/services/display_safety、device/google/sdv_display_safety
    SDV IVI に緊急情報を表示する sdv_ivi_cf_ds-aosp_current-userdebug packages/apps/Car/DriverUI、packages/services/display_safety/service

    チェックアウトで trunk_staging マニフェストを使用する場合は、-aosp_current-userdebug を -trunk_staging-userdebug に置き換えます。ネイティブ プラットフォーム コードも参照するには、cpp を other_languages に追加します。すべての構成オプションの詳細については、構成パラメータをご覧ください。

  5. 変更を適用するには、[ASfP] > [Sync] > [Sync Project] を選択します。同期モード(完全同期、部分同期、ビルドなし同期)と、チーム用の共有可能な .asfp-project テンプレートのエクスポートまたはインポートの詳細については、同期モードと Soong ツール ウィンドウと共有可能なプロジェクト テンプレート(エクスポートとインポート)をご覧ください。

SDV サービス バンドルをデプロイする

ASfP には、サービス バンドルを含む APEX を実行中の SDV デバイスに直接デプロイする SDV プラグインが含まれています。このプラグインはデフォルトで無効になっています。これを使用するには、[Settings] > [Plugins] で SDV プラグインを有効にします。APEX パッケージの詳細については、サービス バンドルをビルドしてデプロイするをご覧ください。

デプロイ方法は、APEX がすでにデバイスに存在するかどうかによって異なります。

  • APEX がすでにインストールされている場合は、ASfP から直接変更をデプロイできます。
  • APEX が新しい場合は、まずシステム イメージを再ビルドして再起動するか、APEX の署名に使用された鍵を含むシステム イメージを使用する必要があります。その後、ASfP からデプロイできます。

サービス バンドル APEX をデプロイする手順は次のとおりです。

  1. Cuttlefish プラグインを使用して SDV デバイスを起動します。詳細については、Cuttlefish で SDV デバイスを実行するをご覧ください。
  2. サービス バンドルの apex/Android.bp ファイルを開き、apex { ブロックの横にあるガターの [Run] アイコンをクリックします。
  3. 表示されたメニューで、[Run 'Deploy APEX_NAME'] を選択します。同じメニューから、デプロイせずに APEX をビルドしたり、実行構成を変更したりすることもできます。

Cuttlefish で SDV デバイスを実行する

ASfP には、ローカル Cuttlefish デバイスを作成して実行する Cuttlefish プラグインが含まれています。このプラグインには Cuttlefish ホスト オーケストレーターが必要です。ホスト オーケストレーターが使用できない場合、ASfP に設定手順が表示されます。

SDV デバイスを作成する手順は次のとおりです。

  1. [ツール] > [デバイス マネージャー] を選択し、[+] をクリックして、[Create Cuttlefish Device] を選択します。
  2. マルチ VM 設定を作成するには、[正規構成から] を選択し、SDV Core と SDV IVI、SDV Media と SDV IVI(ディスプレイの安全性)など、設定の構成を作成またはインポートします。単一の VM を作成するには、代わりに [From local Android source tree checkout] を選択します。

1 つの画面ですべての VM ディスプレイを表示し、追加のデバイス オプションにアクセスするには、[Cuttlefish] ツール ウィンドウを使用します。これを開くには、サイドパネルの ... アイコンを選択して [Cuttlefish] を選択するか、[Help] > [Find Action] で [Cuttlefish] を検索します。[Running Devices] で個々のディスプレイを表示することもできます。SDV Core はディスプレイなしで動作するため、Logcat とターミナルを使用して検査します。

デバッグとテスト

ASfP には、C++ コードと Rust コード用の LLDB デバッガが組み込まれています。ASfP でのデバッグとテストの詳細については、プラットフォーム コードをデバッグする、Rust コードをデバッグする、atest でプラットフォーム コードをテストする、LLDB で cc_test ターゲットと rust_test ターゲットをデバッグするをご覧ください。

デバッガをサービス バンドルにアタッチする場合は、それをホストするプロセスにアタッチします。プロセス名は <bundle_name>:<instance_name> 形式(OrchestratorSampleRustServiceBundle:sample-main-no-conditions など)を使用します。次のコマンドは、一致するプロセスとそのプロセス ID を一覧表示します。

adb shell ps -A | grep <bundle_name>

複数のデバイスへの接続やログの表示など、SDV デバッグ ワークフローの詳細については、SDV をデバッグするをご覧ください。

VSIDL ファイルを編集する

ASfP には、VSIDL 言語サーバー(vsidl-lsp)が含まれています。言語サーバーのカタログを設定する方法については、カタログの自動更新と LSP の統合をご覧ください。カタログに CATALOG_UPDATE ファイルが含まれている場合、エディタには .vsidl ファイルに対して次の機能が用意されています。

  • ライブ検証: エディタは VSIDL キーワードをハイライト表示し、構文エラー、未解決の型、VSIDLC 検証エラーを [Problems] ウィンドウに表示します。検証ルールとそのエラーコードの詳細については、VSIDL 言語仕様をご覧ください。
  • 予測入力とドキュメント: Ctrl+Space キーを押すと、キーワード、メッセージ、サービス、トピック、チャネルの候補が表示されます。Ctrl+Q キーを押すと、ドキュメントのコメントが表示されます。
  • ナビゲーションとフォーマット: Ctrl+B キーを押して .vsidl または .proto の定義に移動できます。Alt+Shift+F7 キーを押して参照を検索できます。Ctrl+F12 キーを押してファイル構造を表示できます。Ctrl+Alt+L キーを押してファイルをフォーマットできます。

AI アシスタントに SDV コンテキストを追加する

ASfP には、Android Studio の AI と、Soong ビルドツールおよび atest ツールを備えた組み込みエージェントが含まれています。AGENTS.md ファイルはバージョン管理でソースコードと一緒に保存されるため、ASfP の組み込みエージェントと、AGENTS.md を読み取るコマンドラインまたはコンテナベースのコーディング エージェントで同じ SDV ルールを共有できます。ASfP でファイルを開いた状態でプロンプトを送信すると、エージェントはそのファイルのディレクトリとその親ディレクトリから AGENTS.md ファイルを読み込みます(同じディレクトリ内の GEMINI.md ファイルが優先される場合を除く)。有効なファイルは、チャットパネルの [コンテキスト] ドロワーの [AGENTS.md ファイル] で確認できます。詳細については、プラットフォーム向け Android Studio の概要と AGENTS.md ファイルを使用してエージェントをカスタマイズするをご覧ください。

次のテンプレートは、SDV プロジェクトを作成するのワークフローの出発点となります。

SDV サービス バンドル

この AGENTS.md ファイルを、catalog/、services/、apex/ フォルダを囲む .asfp-project に含まれるバンドル ディレクトリに配置します。詳細については、ミドルウェアを生成する、サービス バンドルをビルドしてデプロイする、SOME/IP マッピング ファイルを作成する、SDV 通信認可の概要をご覧ください。

# AAOS SDV service bundle and VSIDL rules

## Build and test
- Initialize the build environment (`source build/envsetup.sh` and
  `lunch sdv_core_cf-aosp_current-userdebug`) when running outside ASfP, build
  modules with Soong (`m <module_name>`), and run tests with
  `atest <TestModuleName>` (`rust_test`, `rust_test_host`, `cc_test`, or
  `python_test_host`), without creating `Cargo.toml` files or running `cargo`
- In catalog `Android.bp` files, avoid `defaults` on `rust_protobuf` modules
  (`vsidlc` uses a regex parser), include each `.proto` file in at most one
  `rust_protobuf` target, and cover all catalog files in the first `filegroup`
  (`srcs: ["**/*"]`)

## Protobuf, VSIDL, and AUTOSAR SOME/IP mapping conventions
- Keep `.proto` files limited to `message`, `enum`, and RPC `service` schemas
  (using `sdv/vsidl/v1/annotations.proto` only for field size bounds), without
  topic names, channel names, or queue capacities
- Write `.vsidl` files in TextProto `VsidlEntry` syntax (`package: "..."`,
  `service_bundle { name: "..." }`, `publisher` or `subscriber` with `message`
  and `topic`, and `server` or `client` with `service` and `channel`, without
  `import` statements; RPCs support unary, client-streaming, and
  server-streaming methods, not bidirectional streaming), and isolate
  `some_ip_mapping` (`sdv_type_mapping` and `someip_service_mapping` for
  AUTOSAR electronic control unit (ECU) `ARXML` or `vsomeip` IDs) or
  `vhal_mapping` rules in dedicated `.vsidl` mapping files so core bundles stay
  transport-independent
- Use `PascalCase` for `service_bundle` names (avoiding Rust, C++, and Java
  keywords), `snake_case` for `build_cfg.target_name`, a globally unique
  lowercase `package` with at least four segments (`com.<org>.sdv.<domain>`;
  never reuse platform-reserved `com.android.sdv.*` or sample `com.sdv.*`
  names), and lowercase dash-case starting with a letter (no consecutive or
  trailing hyphens, underscores, or slashes) for `topic`, `channel`, and
  instance names
- Set `capacity` on every `publisher` to an even integer greater than or equal
  to 2, and pair every `subscriber` and RPC `client` with a matching
  `publisher` or `server` in the catalog or its `-d` dependency catalogs

## Code generation, authorization, and APEX packaging
- Export `ANDROID_BUILD_TOP`, check `CATALOG_UPDATE` for catalog-relative
  `output_path` (such as `".."`), `dependency_catalog_paths` (`-d`), and
  `vsidlc_gen_args`, and run `vsidlc -c <catalog_dir> -o <output_dir>`; omit
  `--services` from `vsidlc_gen_args` and avoid `-p` (`--purge`) or
  `regenerator` when `output_path` holds handwritten `services/` code
- Leave generated files in `generated_rs/`, `apex/`, and `configs/` unmodified,
  and implement Rust logic in `services/<ServiceBundleName>/src/main.rs` (even
  though the initial `vsidlc --services` skeleton header says not to edit; C++
  bundles do not use `vsidlc` C++ codegen and instead use
  `libsdv_lifecycle_client_cpp`, `libsdv_comms_cpp`, and
  `sdv_service_bundle_metadata` with `native_library_path: "lib64/lib<so>.so"`
  in `sdv_service_bundles_manifest.textproto`)
- Keep communications authorization `.textproto` policies in `configs/` aligned
  with every `publisher`, `subscriber`, `server`, and `client` unit (omitting
  `capacity` inside manual authorization `.textproto` `publisher` entries) so
  Service Discovery does not reject endpoints at runtime
- In Rust bundles, wait for publisher or RPC server availability before
  creating subscribers or clients, stop active tasks in `on_stop`, and run
  blocking work in `tokio::spawn_blocking`
- Generate Rust service bundle APEXes with `vsidlc --apex` (`updatable: true`,
  `min_sdk_version: "35"`, and `product_specific: true` in `apex/Android.bp`,
  never `vendor: true` or `soc_specific: true`, with matching unique `name` and
  `version` >= 1 in `apex_manifest.json`), and do not set
  `supportsRebootlessUpdate: true` or run `adb install --force-non-staged`
  because SDV APEX updates require a reboot

SDV IVI の SDV ゲートウェイ

この AGENTS.md ファイルを IVI クライアント モジュール ディレクトリまたは system/software_defined_vehicle/sdv_gateway/ に配置します。詳細については、IVI で SDV ゲートウェイを使用するをご覧ください。

# AAOS SDV Gateway on SDV IVI rules

- Initialize the build environment (`source build/envsetup.sh` and
  `lunch sdv_ivi_cf-aosp_current-userdebug`) when running outside ASfP, build
  IVI modules with Soong (`m <module_name>`), and run verification with
  `atest <TestModuleName>`
- For native C or C++ IVI clients (including vehicle hardware abstraction layer
  (VHAL) integrations), link `libsdvgatewayclient`
  (`#include "libsdvgatewayclient.h"`) or `ISdvGateway`; for in-tree system Java
  or Kotlin clients, use `libsdvgatewayclient-java`,
  `libsdvgatewayclient-java-sdk.stubs`, `libsdvgatewayclient-java-sdk`, and
  `com.android.sdv.gateway.client`
- Start the Binder thread pool before calling `ASDVGateway_Client_new`, and
  call `ASDVGateway_Client_initComms` (or `SdvGatewayClient.initComms`) before
  any service discovery, data tunnel, or RPC calls
- Check `ASDVGateway_Client_isRpcAvailable` or
  `ASDVGateway_Client_isProcessBoundToSdvRpcNetworkInterface` before opening
  RPC sockets on early boot, treat `ASDVGateway_StatusCode_OK` with null
  `ASDVGateway_RpcCredentials_t` as insecure `UNLOCKED` boot mode, and free
  non-null credentials with `ASDVGateway_Client_deleteRpcCredentials`
- Grant `sdv_gateway_client_domain(<domain>)` in SELinux (do not add
  `binder_use` on `/vendor` daemons, which violates Treble `neverallow`; add
  `group inet` on native init services, and `INTERNET` plus
  `CONNECTIVITY_USE_RESTRICTED_NETWORKS` privapp permissions for system Java
  RPC clients)

ディスプレイの安全

この AGENTS.md ファイルを packages/services/display_safety/ またはインストルメント クラスタ アプリのディレクトリに配置します。詳細については、Display Safety を使ってみる、HAR プラットフォーム抽象化レイヤ、安全設計ツールチェーン、DriverUI をご覧ください。

# AAOS Display Safety partner integration rules

- Display Safety spans two guest VMs with separate `lunch` targets: keep
  safety-critical telltales, gauges, camera views, chimes, and early-boot or
  fallback placeholders in the Rust high availability renderer (HAR) and safety
  monitor on SDV Media (`sdv_media_har_cf`), and build non-safety cluster UI on
  SDV IVI (`sdv_ivi_cf_ds`) using `ClusterHomeManager` (`Cluster2` rather than
  legacy `Cluster1`)
- Implement target OS and hardware subsystems (display, graphics, exterior view
  system (EVS) cameras, audio, user input, and vehicle signals) in a dedicated
  `har-platform-<target>` platform abstraction layer (PAL) crate implementing
  `har-platform-api` traits rather than modifying core `harry` framework crates,
  and verify PAL crates against the HAR platform test suite with `atest`
- Generate safety monitor configurations and telltale inspection artifacts from
  the serialized Automotive Design for Compose document and safety JSON mapping
  (`{"documents": [{"rootnode": "#...", "display_id": 1, "document_id": "...",`
  `"states": {"<signal>": "#<node_id>"}}]}`) using the safety design compiler
  rather than hardcoding telltale pixel coordinates
- Because the HAR display plane composites above Android IVI, ensure HAR clears
  the cluster viewport region to `alpha = 0.0` while valid `HeartbeatRequest`
  gRPC messages arrive from IVI, and set opaque pixels in custom HAR OpenGL ES
  surfaces to `alpha = 1.0` (`0xFF`)
- Initialize the build environment (`source build/envsetup.sh` and `lunch`) when
  running outside ASfP, integrate prebuilt cluster APKs into `sdv_ivi_cf_ds`
  through `DriverUIPrebuilt` (`overrides: ["DriverUIStubApp"]`), launch dual-VM
  Cuttlefish setups from ASfP or with `ds_toolkit launch`, pass `--user 0` to
  `adb shell am` cluster commands, and note that
  `adb shell dumpsys SurfaceFlinger` on SDV IVI inspects only Android layers
  rather than the overlying HAR plane