2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

classpathなどを使わずAndroidにOSS Licenses Gradle Pluginを組み込む方法

Last updated at Posted at 2024-05-21

コピペです。

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")
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?