コピペです。
settings.gradle.kts
pluginManagement {
repositories {
google {
content {
includeGroupByRegex("com\\.android.*")
includeGroupByRegex("com\\.google.*")
includeGroupByRegex("androidx.*")
}
}
mavenCentral()
gradlePluginPortal()
}
// 追加
resolutionStrategy {
eachPlugin {
if (requested.id.id == "com.google.android.gms.oss-licenses-plugin") {
useModule("com.google.android.gms:oss-licenses-plugin:${requested.version}")
}
}
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "AppName"
include(":app")
libs.versions.toml
[versions]
ossLicensesPlugin = "0.10.5"
ossLicense = "17.0.1"
[libraries]
oss-licenses = { group = "com.google.android.gms", name = "play-services-oss-licenses", version.ref = "ossLicense" }
[plugins]
oss-licenses-plugin = { id = "com.google.android.gms.oss-licenses-plugin", version.ref = "ossLicensesPlugin" }
build.gradle.kts(Root)
plugins {
alias(libs.plugins.oss.licenses.plugin) apply false
}
build.gradle.kts(:app)
plugins {
alias(libs.plugins.oss.licenses.plugin)
}
dependencies {
implementation(libs.oss.licenses)
}
styleを設定しないとライセンス表示時にクラッシュする。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application>
<!-- 追加 -->
<activity android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
</application>
</manifest>
Jetpack Composeでの使い方
val context = LocalContext.current
Button(onClick = {
context.startActivity(Intent(context, OssLicensesMenuActivity::class.java))
}) {
Text("Click")
}