از 27 مارس 2025، توصیه می کنیم از android-latest-release به جای aosp-main برای ساختن و کمک به AOSP استفاده کنید. برای اطلاعات بیشتر، به تغییرات AOSP مراجعه کنید.
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
به طور پیشفرض، همه پرچمهای راهاندازی ویژگی READ_WRITE هستند و روی DISABLED تنظیم شدهاند. قبل از اینکه بتوانید یک ویژگی را آزمایش کنید، باید با ایجاد یک فایل مقادیر پرچم برای پرچم، مقدار پیش فرض استفاده شده در ساخت را لغو کنید. در فایل مقادیر پرچم، وضعیت یک پرچم ( ENABLED یا DISABLED ) و مجوز ( READ_WRITE یا READ_ONLY ) را تنظیم میکنید.
پیکربندی انتشار ، دایرکتوری است که حاوی تمام فایلهای مقادیر پرچم برای یک بیلد خاص اندروید (با ویژگیهای خاص فعال و غیرفعال) است.
AOSP با چند پیکربندی انتشار، مانند trunk_staging عرضه میشود. دایرکتوری های پیکربندی انتشار در زیر WORKING_DIRECTORY /build/release/aconfig/ یافت می شود.
هنگامی که از دستور lunch برای انتخاب یک هدف استفاده می کنید، پیکربندی انتشار را نیز برای هدف تنظیم می کنید. به عنوان مثال، موارد زیر یک هدف trunk_staging است:
Trunk staging یک پیکربندی نسخه توسعه است زیرا Google از آن برای آزمایش ویژگیها قبل از انتشار عمومی استفاده میکند. این پیکربندی عمدتاً از پرچمهای READ_WRITE استفاده میکند که به شما امکان میدهد کد خود را با ویژگیهای فعال یا غیرفعال در زمان اجرا آزمایش کنید.
در نسخه عمومی، از پیکربندی انتشار استفاده کنید. پیکربندی انتشار نسخه عمدتاً از پرچمهای READ_ONLY استفاده میکند و همه کدهای فعال شده برای آن نسخه را منعکس میکند.
یک پرچم به پیکربندی انتشار trunk_staging اضافه کنید
برای آزمایش یک پرچم جدید، آن را به صورت زیر به پیکربندی انتشار trunk_staging اضافه کنید:
به WORKING_DIRECTORY /build/release/aconfig/trunk_staging/ بروید
یک دایرکتوری با نام بسته مشابه پرچم خود ایجاد کنید، مانند com.example.android.aconfig.demo.flags نشان داده شده در Declare an aconfig flag for Java .
به دایرکتوری جدید بروید.
در دایرکتوری، یک فایل مقادیر پرچم ایجاد کنید که نام مورد استفاده در فایل اعلام پرچم ( .aconfig ) را ترکیب کند، مانند my_static_flag نشان داده شده در Declare an aconfig flag برای جاوا با _flag_values.textproto . نام فایل حاصل my_static_flag_flag_values.textproto است.
فایل را ویرایش کنید و یک flag_value مشابه موارد زیر اضافه کنید:
package حاوی همان نام بسته مورد استفاده در اعلامیه است.
name شامل همان نام مورد استفاده در اعلامیه است.
state یا ENABLED یا DISABLED است.
permissionREAD_WRITE یا READ_ONLY است. به طور کلی، permission برای READ_ONLY برای فایل هایی با مقادیر پرچم که بخشی از پیکربندی انتشار هستند تنظیم می شود.
فایل را ذخیره کنید و از ویرایشگر خود خارج شوید.
در همان فهرست فایل مقادیر پرچم، یک فایل ساخت به نام Android.bp ایجاد کنید. این فایل برای گنجاندن فایل مقادیر پرچم در بیلد استفاده می شود.
در فایل Android.bp ، یک بخش aconfig_values شبیه به زیر ایجاد کنید:
name نام منحصر به فرد ماژول ساخت Soong است. Google از قرارداد aconfig-values-platform_ PATH_TO_RELEASE_CONFIG_DIR - CONFIG-NAME - package.name -all استفاده میکند. توجه داشته باشید که PATH_TO_RELEASE_CONFIG_DIRbuild/release است.
package حاوی همان نام بسته مورد استفاده در اعلامیه است.
srcs لیستی از تمام فایل های مقادیر پرچم شما است.
فایل را ذخیره کنید و از ویرایشگر خود خارج شوید.
به دایرکتوری بالای فهرست فعلی بروید ( cd .. )
فایل Android.bp را ویرایش کنید. این فایل ساخت شامل لیستی از نام ها ( name ) مرتبط با هر فایل مقادیر پرچم است. نامی را که در فایل ساخت قبلی (مرحله 8) استفاده کرده اید به این لیست اضافه کنید.
اندروید را بسازید و کد جدید خود را اجرا کنید تا مطمئن شوید که طبق تنظیمات فایل مقادیر پرچم فعال است.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Set feature launch flag values\n\nBy default, all feature launch flags are `READ_WRITE` and set to `DISABLED`.\nBefore you can test a feature, you must override the default value used in the\nbuild by creating a *flag values file* for the flag. In a flag values file,\nyou set a individual flag's state (`ENABLED` or `DISABLED`) and permission\n(`READ_WRITE` or `READ_ONLY`).\n\nA *release configuration* is a directory that contains all of the flag values\nfiles for a specific build of Android (with certain features enabled and\ndisabled).\n\nAOSP ships with a few release configurations, such as `trunk_staging`.\nRelease configuration directories are found under\n\u003cvar translate=\"no\"\u003eWORKING_DIRECTORY\u003c/var\u003e`/build/release/aconfig/`.\n| **Note:** This page shows you how to add a flag to an existing release configuration as a means of teaching how release configurations work. The release configurations included in AOSP are defined by Google. Google doesn't accept contributions to update or change a configuration's feature release flags. Instead, you can define your own custom release configurations including default flag values in your forks of AOSP. For more information on release configurations, see [Set feature launch flag values](/docs/setup/build/feature-flagging/set-values).\n\nWhen you use the `lunch` command to\n[choose a target](/docs/setup/build/building#choose-a-target), you're\nalso setting the release configuration for the target.\nFor example, the\nfollowing is a `trunk_staging` target: \n\n lunch aosp_cf_x86_64_only_phone-trunk_staging-userdebug\n\nTrunk staging is a *development release configuration* because\nGoogle uses it to test features before general release. This configuration\nuses\nmostly `READ_WRITE` flags that let you test your code with features enabled or\ndisabled at runtime.\n\nAt general release, use a *release release configuration* . A release\nrelease configuration mostly uses `READ_ONLY` flags and reflects all of the code\nenabled for that release.\n\nAdd a flag to the trunk_staging release configuration\n-----------------------------------------------------\n\nTo test a new flag, add it to the `trunk_staging` release configuration as\nfollows:\n\n1. Navigate to \u003cvar translate=\"no\"\u003eWORKING_DIRECTORY\u003c/var\u003e`/build/release/aconfig/trunk_staging/`\n2. Create a directory with the same package name as your flag, such as `com.example.android.aconfig.demo.flags` shown in [Declare an aconfig flag for Java](/docs/setup/build/feature-flagging/declare-flag).\n3. Navigate to the new directory.\n4. In the directory, create a flag values file that combines the name used in the flag declaration (`.aconfig`) file, such as `my_static_flag` shown in [Declare an aconfig flag for Java](/docs/setup/build/feature-flagging/declare-flag) with `_flag_values.textproto`. The resulting filename is `my_static_flag_flag_values.textproto`.\n5. Edit the file and add a `flag_value` similar to the following:\n\n flag_value {\n package: \"com.example.android.aconfig.demo.flags\"\n name: \"my_static_flag\"\n state: DISABLED\n Permission: READ_WRITE\n }\n\n Where:\n - `package` contains the same package name used in the declaration.\n - `name` contains the same name used in the declaration.\n - `state` is either `ENABLED` or `DISABLED`.\n - `permission` is either `READ_WRITE` or `READ_ONLY`. Generally, the `permission` is set to `READ_ONLY` for flag values files that are part of a release configuration.\n6. Save the file and exit your editor.\n\n7. In the same directory as the flag values file, create a build file called\n `Android.bp`. This file is used to include the flag values file in the build.\n\n8. In the `Android.bp` file, create a `aconfig_values` section similar to:\n\n aconfig_values {\n name: \"aconfig-values-platform_build_release-trunk-staging-com.android.aconfig.test-all\",\n package: \"com.android.aconfig.test\",\n srcs: [\n \"*_flag_values.textproto\",\n ]\n }\n\n Where:\n - `name` is the unique name for the Soong build module. Google uses the convention of `aconfig-values-platform_`\u003cvar translate=\"no\"\u003ePATH_TO_RELEASE_CONFIG_DIR\u003c/var\u003e`-`\u003cvar translate=\"no\"\u003eCONFIG-NAME\u003c/var\u003e`-`\u003cvar translate=\"no\"\u003epackage.name\u003c/var\u003e`-all`. Note that \u003cvar translate=\"no\"\u003ePATH_TO_RELEASE_CONFIG_DIR\u003c/var\u003e is `build/release`.\n - `package` contains the same package name used in the declaration.\n - `srcs` is a list of all of your flag values files.\n9. Save the file and exit your editor.\n\n10. Navigate to the directory above the current directory (`cd ..`)\n\n11. Edit the `Android.bp` file. This build file contains a list of the names\n (`name`) associated with each flag values file. Add the name you used in the\n previous build file (step 8) to this list.\n\n12. Build Android, and run your new code to ensure that it's enabled per the\n setting in the flag values file."]]