Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Đôi khi, SDK Dịch vụ Google Play có chứa hoặc phụ thuộc vào các thư viện nguồn mở. Để tuân thủ các yêu cầu về giấy phép của thư viện nguồn mở, bạn (nhà phát triển) có trách nhiệm hiển thị thông báo một cách thích hợp cho các thư viện nguồn mở mà ứng dụng của bạn sử dụng.
Dịch vụ Google Play bao gồm một bộ công cụ được thiết kế để giúp nhà phát triển dễ dàng thể hiện thông báo về phần mềm nguồn mở (OSS) của các thư viện được dùng trong ứng dụng của họ. oss-licenses-plugin và SDK oss-licenses của Dịch vụ Google Play thu thập các điều khoản cấp phép từ các thư viện đi kèm (như được khai báo trong tệp POM của các thư viện đó) và tạo một hoạt động có thể dùng để hiển thị các điều khoản này. Tìm hiểu thêm về cách công cụ này tìm và đóng gói thông tin về giấy phép.
Thêm trình bổ trợ Gradle
Trong pluginManagement của phần cài đặt dự án, hãy làm như sau:
Trong tệp bản dựng cấp ứng dụng, hãy áp dụng trình bổ trợ bằng cách thêm dòng sau vào phần khai báo hiện có của trình bổ trợ com.android.application ở đầu tệp:
Khi ứng dụng của bạn tạo, trình bổ trợ Gradle sẽ xử lý các giấy phép và thêm chúng vào tài nguyên của ứng dụng. Để dễ dàng hiển thị giấy phép, bạn có thể chạy một hoạt động do thư viện play-services-oss-licenses cung cấp tại một thời điểm thích hợp trong ứng dụng, như minh hoạ trong đoạn mã sau:
Kotlin
importcom.google.android.gms.oss.licenses.OssLicensesMenuActivity...// When the user selects an option to see the licenses:startActivity(Intent(this,OssLicensesMenuActivity::class.java))
Java
importcom.google.android.gms.oss.licenses.OssLicensesMenuActivity;...// When the user selects an option to see the licenses:startActivity(newIntent(this,OssLicensesMenuActivity.class));
Khi được khởi chạy, hoạt động này sẽ hiển thị danh sách các thư viện nguồn mở được biên dịch vào ứng dụng của bạn, bao gồm cả các thư viện mà ứng dụng sử dụng, như minh hoạ trong hình 1. Người dùng có thể nhấn vào tên của một thư viện để xem thông tin bổ sung về giấy phép của thư viện đó.
Hình 1. Hoạt động trình đơn giấy phép cho thấy một danh sách có thể chọn gồm các thư viện nguồn mở mà một ứng dụng sử dụng.
Đặt tiêu đề cho hoạt động
Theo mặc định, hoạt động được hiển thị có tiêu đề "Giấy phép nguồn mở". Bạn có thể tuỳ chỉnh tiêu đề của hoạt động bằng cách gọi setActivityTitle(), như minh hoạ trong đoạn mã sau:
Bạn có thể áp dụng một giao diện cho hoạt động để giao diện này khớp với giao diện được dùng trong các hoạt động khác của ứng dụng. Để làm như vậy, hãy thêm hoạt động cấp phép nguồn mở vào một phần tử <activity> trong tệp kê khai của ứng dụng, như minh hoạ trong đoạn mã sau:
Tại thời điểm biên dịch, trình bổ trợ Gradle sẽ quét các phần phụ thuộc POM của dự án ứng dụng. Khi một POM Maven tồn tại cho một phần phụ thuộc trực tiếp của ứng dụng, trình bổ trợ sẽ xử lý từng phần tử <licenses> và nhúng đường liên kết cũng như tiêu đề của từng giấy phép vào một tài sản Android có trong ứng dụng của bạn.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-05 UTC."],[[["\u003cp\u003eGoogle Play services uses open source libraries, requiring developers to display licenses.\u003c/p\u003e\n"],["\u003cp\u003eA Gradle plugin helps by gathering license information and creating an activity to display them.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers need to add the plugin, the library dependency, and launch the provided activity in their app.\u003c/p\u003e\n"],["\u003cp\u003eThe license activity's title and theme can be customized.\u003c/p\u003e\n"],["\u003cp\u003eThe plugin scans POM dependencies to compile the license list, including those used by Google Play services itself.\u003c/p\u003e\n"]]],["Developers must display notices for open-source libraries used in their apps. Google Play services provides a Gradle plugin to streamline this. To use it, include the Google Maven repository and add the `oss-licenses` plugin in the root-level build file. Apply the plugin in the app-level build file and add the `oss-licenses` library as a dependency. The plugin then processes licenses from POM files and creates an activity via `OssLicensesMenuActivity` to display them. Developers can customize the activity's title and theme. The plugin scans direct and transitive dependencies, including those of Google Play services.\n"],null,["\u003cbr /\u003e\n\nGoogle Play services SDKs sometimes include, or depend upon, open source\nlibraries. To comply with the license requirements of open source libraries, you\nas a developer are responsible for appropriately displaying the notices for the\nopen source libraries that your app uses.\n\nGoogle Play services includes a set of tools designed to give developers an\neasier way to express the open source software (OSS) notices of libraries used\nin their apps. The `oss-licenses-plugin` and the Google Play services\noss-licenses SDK collect license terms from included libraries, as declared in\ntheir POM files, and create an\n[activity](https://developer.android.com/guide/components/activities/intro-activities)\nthat can be used to display these terms. Learn more about\n[how the tool finds and packages license information](#how-licenses-are-determined).\n\nAdd the Gradle plugin\n\nIn your `pluginManagement` of your project settings, do the following:\n\n1. Include the [Google Maven repository](https://developer.android.com/studio/build/dependencies#google-maven).\n2. Resolve the `oss-licenses` plugin in the `PluginManagement`.\n\nThe following code snippet shows these steps: \n\nKotlin DSL\n\nsettings.gradle.kts \n\n```kotlin\npluginManagement {\n repositories {\n ...\n google()\n }\n resolutionStrategy {\n eachPlugin {\n if (requested.id.id == \"com.google.android.gms.oss-licenses-plugin\") {\n useModule(\"com.google.android.gms:oss-licenses-plugin:0.10.6\")\n }\n }\n }\n}\n```\n\nGroovy DSL\n\nbuild.gradle \n\n```groovy\npluginManagement {\n repositories {\n ...\n google()\n }\n resolutionStrategy {\n eachPlugin {\n if (requested.id.id == \"com.google.android.gms.oss-licenses-plugin\") {\n useModule(\"com.google.android.gms:oss-licenses-plugin:0.10.6\")\n }\n }\n }\n}\n```\n\nIn your app-level build file, apply the plugin by adding the following line\nunder the existing declaration of the `com.android.application` plugin at the\ntop of the file: \n\nKotlin DSL\n\napp/build.gradle.kts \n\n```kotlin\nplugins {\n id(\"com.android.application\")\n id(\"com.google.android.gms.oss-licenses-plugin\")\n}\n```\n\nGroovy DSL\n\napp/build.gradle \n\n```groovy\nplugins {\n id 'com.android.application'\n id 'com.google.android.gms.oss-licenses-plugin'\n}\n```\n\nYou can\n[view the code](https://github.com/google/play-services-plugins)\nfor this plugin on GitHub.\n\nAdd the `play-services-oss-licenses` library to your app\n\nIn the `dependencies` section of your app-level build file, add a dependency on\nthe `play-services-oss-licenses` library: \n\nKotlin DSL\n\nbuild.gradle.kts \n\n```kotlin\nimplementation(\"com.google.android.gms:play-services-oss-licenses:17.2.2\")\n```\n\nGroovy DSL\n\nbuild.gradle \n\n```groovy\nimplementation 'com.google.android.gms:play-services-oss-licenses:17.2.2'\n```\n\nDisplay license information\n\nWhen your app builds, the Gradle plugin processes the licenses and adds them to\nyour app's resources. To easily display the license, you can launch an activity\nthat's provided by the `play-services-oss-licenses` library at an appropriate\npoint in your app, as shown in the following code snippet: \n\nKotlin \n\n```kotlin\nimport com.google.android.gms.oss.licenses.OssLicensesMenuActivity\n...\n\n// When the user selects an option to see the licenses:\nstartActivity(Intent(this, OssLicensesMenuActivity::class.java))\n```\n\nJava \n\n```java\nimport com.google.android.gms.oss.licenses.OssLicensesMenuActivity;\n...\n\n// When the user selects an option to see the licenses:\nstartActivity(new Intent(this, OssLicensesMenuActivity.class));\n```\n\nWhen the activity is launched, it displays a list of open source libraries that\nare compiled into your app, including libraries used by the app, as shown in\nfigure 1. Users can tap on the name of a library to view additional license\ninformation for that library.\n\n**Figure 1.** The licenses menu activity shows a selectable list of open source\nlibraries that an app uses.\n\nSet the activity title\n\nBy default, the displayed activity has the title \"Open source licenses\". You can\ncustomize the title of the activity by calling\n[`setActivityTitle()`](/android/reference/com/google/android/gms/oss/licenses/OssLicensesMenuActivity#public-static-void-setactivitytitle-string-title),\nas shown in the following code snippet: \n\nKotlin \n\n```kotlin\nOssLicensesMenuActivity.setActivityTitle(getString(R.string.custom_license_title))\n```\n\nJava \n\n```java\nOssLicensesMenuActivity.setActivityTitle(getString(R.string.custom_license_title));\n```\n\nApply a theme to the activity\n\nYou can apply a theme to the activity to match the theme used in your app's\nother activities. To do so, include the open source license activity in an\n`\u003cactivity\u003e` element within your app's manifest file, as shown in the following\ncode snippet: \n\n```xml\n\u003capplication android:theme=\"@style/AppTheme\" ...\u003e\n \u003cactivity\n android:name=\"com.google.android.gms.oss.licenses.OssLicensesMenuActivity\"\n android:theme=\"@style/AppTheme\" /\u003e\n \u003cactivity\n android:name=\"com.google.android.gms.oss.licenses.OssLicensesActivity\"\n android:theme=\"@style/AppTheme\" /\u003e\n\u003c/application\u003e\n```\n\nHow the list of licenses is determined\n\nAt compile time, the Gradle plugin scans the POM dependencies of your app's\nproject. When a Maven POM exists for a direct dependency of the app, the plugin\nprocesses each [`\u003clicenses\u003e`](https://maven.apache.org/pom.html#Licenses)\nelement and embeds the link and title of each license in an Android asset that's\nincluded with your app.\n| **Note:** The list of licenses also includes the full license text of any library that is depended upon by the transitive closure of Google Play services libraries used by the app. This means that the list includes any open source libraries that are used to create the Google Play services libraries that are compiled into your app."]]