m コマンドは、ツリーの最上部からビルドします。したがって、m コマンドはサブディレクトリ内から実行できます。m コマンドは、TOP 環境変数が設定されていればそれを使用します。TOP が設定されていない場合、m コマンドは現在のディレクトリからツリーを検索し、ツリーの最上部の特定を試みます。
m コマンドは、-jN 引数を使用して並列タスクを処理できます。-j 引数を指定しない場合、ビルドシステムはシステムに最適と思われる並列タスク数を自動的に選択します。
デバイス イメージ全体ではなく特定のモジュールをビルドするには、m コマンドラインにモジュール名を指定します。また、m コマンドは「ゴール」と呼ばれる疑似ターゲットも提供します。たとえば、m nothing とすると何もビルドされず、ビルド構造の解析と検証のみが行われます。有効なゴールのリストを表示するには m help と入力してください。
ビルドエラーのトラブルシューティング(8.0 以前)
AOSP 8 以前のビルドでは、Java のバージョンの問題により m コマンドが中断されることがあります。たとえば次のようなメッセージが表示されます。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-03-26 UTC。"],[],[],null,["# Build Android\n\nFollow the instructions on this page to build Android.\n\nSet up your build environment\n-----------------------------\n\nFrom within your working directory, source the `envsetup.sh` script to set\nup your build environment: \n\n source build/envsetup.sh\n\nThis script imports several commands that let you work with the Android\nsource code, including the commands used on this page. To view the source of the\nscript, refer to\n[`platform/build/envsetup.sh`](https://android.googlesource.com/platform/build/+/refs/heads/android16-release/envsetup.sh).\nTo view the built-in help, type `hmm`.\n\nChoose a target\n---------------\n\nBefore building Android, you must identify a *target* to build. A target\nreflects the target platform you're building for. To identify your\ntarget to build, use the `lunch` command followed by a string representing\nthe target. For example: \n\n lunch aosp_cf_x86_64_only_phone-aosp_current-userdebug\n\nYou should see is a synopsis of your target and build environment: \n\n ============================================\n PLATFORM_VERSION_CODENAME=Baklava\n PLATFORM_VERSION=Baklava\n TARGET_PRODUCT=aosp_cf_x86_64_only_phone\n TARGET_BUILD_VARIANT=userdebug\n TARGET_ARCH=x86_64\n TARGET_ARCH_VARIANT=silvermont\n HOST_OS=linux\n HOST_OS_EXTRA=Linux-6.10.11-1rodete2-amd64-x86_64-Debian-GNU/Linux-rodete\n HOST_CROSS_OS=windows\n BUILD_ID=BP1A.250305.020\n OUT_DIR=out\n ============================================\n\n| **Note:** You must run `source envsetup.sh` once per shell and before the `lunch` command because `lunch` is defined by `envsetup.sh`.\n\nThe string representing the target has the following format: \n\n lunch \u003cvar translate=\"no\"\u003eproduct_name\u003c/var\u003e-\u003cvar translate=\"no\"\u003erelease_config\u003c/var\u003e-\u003cvar translate=\"no\"\u003ebuild_variant\u003c/var\u003e\n\nThe components of this string are:\n\n- The \u003cvar translate=\"no\"\u003eproduct_name\u003c/var\u003e is the name of the product you want to\n build, such as `aosp_cf_x86_64_only_phone` or `aosp_husky`. Your specific\n \u003cvar translate=\"no\"\u003eproduct_name\u003c/var\u003e can follow your own format for your device,\n but the format that Google uses for its devices has these components:\n\n - `aosp` refers to the Android Open Source Platform.\n - (optional) `cf` is included when the target is intended to be run within the Cuttlefish emulator.\n - Architecture and hardware (codename), such as `x86_64_only_phone` or `husky`, which is the codename for Pixel 8 Pro. For list of codenames for Google devices, see [Device codenames](/docs/setup/reference/build-numbers#build-targets).\n- \u003cvar translate=\"no\"\u003erelease_config\u003c/var\u003e is set to a *release\n configuration* , such as the development release configuration called\n `aosp_current`. A release configuration identifies certain features and\n code that are behind feature launch flags and are either enabled or disabled for\n a build. For more on release configurations, see\n [Set feature flag launch values](/docs/setup/build/feature-flagging/set-values).\n\n- The \u003cvar translate=\"no\"\u003ebuild_variant\u003c/var\u003e portion of the string can be one of\n the three values in the following table:\n\n | \u003cvar translate=\"no\"\u003ebuild_variant\u003c/var\u003e | Description |\n |-----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | `user` | This build variant provides limited security access and is suited for production. |\n | `userdebug` | This build variant helps the device developers understand the performance and power of in-development releases. When developing with a `userdebug` build, follow the [Guidelines for userdebug](/docs/setup/create/new-device#userdebug-guidelines). |\n | `eng` | This build variant has faster build time and is best suited for day-to-day development if you don't care about performance and power. |\n\nIf you run `lunch` without any arguments, a list of common targets is provided.\nYou can also create your own target strings by piecing together the elements of\nthe target string using the information on this page and the codenames\nthat represent specific Google hardware at\n[Device codenames](/docs/setup/reference/build-numbers#build-targets).\n\n### View the current target\n\nTo see the current lunch settings, run: \n\n $ echo \"$TARGET_PRODUCT-$TARGET_BUILD_VARIANT\"\n\nBuild the code\n--------------\n\nRun the following command to build your target. Depending on the specification\nof your workstation, the first build could take less than an hour and up to a\nfew hours. Subsequent builds take significantly less time. \n\n m\n\nThe output of your build appears in \u003cvar translate=\"no\"\u003e$OUT_DIR\u003c/var\u003e. If you\nbuild different targets, each target build appears in\n\u003cvar translate=\"no\"\u003e$OUT_DIR\u003c/var\u003e.\n\nThe `m` command builds from the top of the tree, so you can run `m` from within\nsubdirectories. If you have the `TOP` environment variable set, the `m` command\nuses it. If `TOP` isn't set, the `m` command looks up the tree from the\ncurrent directory, trying to find the top of the tree.\n\nThe `m` command can handle parallel tasks with a `-jN` argument. If you don't\nprovide a `-j` argument, the build system automatically selects a parallel task\ncount that it thinks is optimal for your system.\n\nYou can build specific modules instead of the full device image by listing\nmodule names in your `m` command line. In addition, the `m` command provides\nsome pseudo targets, called *goals* . For example, `m nothing` doesn't build\nanything, but parses and validates the build structure. For a list of valid\ngoals, type `m help`.\n\nTroubleshoot build errors (8.0 or earlier)\n------------------------------------------\n\nIf you're building AOSP 8 or earlier, `m` might abort when it encounters an\nissue with your version of Java. For example, you might get this message: \n\n ************************************************************\n You are attempting to build with the incorrect version\n of java.\n\n Your version is: \u003cvar translate=\"no\"\u003eWRONG_VERSION\u003c/var\u003e.\n The correct version is: \u003cvar translate=\"no\"\u003eRIGHT_VERSION\u003c/var\u003e.\n\n Please follow the machine setup instructions at\n https://source.android.com/source/initializing.html\n ************************************************************\n\nHere are the likely causes and solutions:\n\n- You failed to install the correct JDK as specified in the JDK sections of [Set Up for AOSP development (2.3 - 8.0)](/docs/setup/start/older-versions).\n- There's another previously installed JDK appearing in your path. Prepend the correct JDK to the beginning of your path or remove the problematic JDK."]]