Skip to content

Commit

Permalink
chore: Change oss license plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
emusute1212 committed Jul 20, 2024
1 parent 35e74d9 commit 67516e6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 107 deletions.
91 changes: 9 additions & 82 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import java.io.File
import java.io.FileWriter

plugins {
Expand All @@ -7,13 +6,13 @@ plugins {
alias(libs.plugins.google.devtools.ksp)
alias(libs.plugins.firebase.crashlytics)
alias(libs.plugins.google.services)
alias(libs.plugins.google.oss.licenses.plugin)
alias(libs.plugins.hilt)
alias(libs.plugins.aboutlibraries)
}

android {
val shouldMakeApk = rootProject.file("upload-keystore.jks").exists()
val version = Version(1, 0, 3, 0)
val version = Version(1, 1, 0, 0)
namespace = libs.versions.namespace.get()
compileSdk = libs.versions.compileSdk.get().toInt()

Expand All @@ -34,6 +33,7 @@ android {
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("debug")
if (shouldMakeApk) {
signingConfig = signingConfigs.create("release")
}
Expand Down Expand Up @@ -93,8 +93,8 @@ dependencies {
// Ktx
implementation(libs.androidx.core.ktx)

// Google
implementation(libs.google.oss.licenses)
// Licenses
implementation(libs.aboutlibraries.compose)

// Crashlytics
implementation(platform(libs.firebase.bom))
Expand Down Expand Up @@ -131,84 +131,11 @@ dependencies {
androidTestImplementation(libs.androidx.ui.test.junit4)
}

// 自動登録されないOSSライセンスを追加するタスク
tasks.register("addOssLicenseTask") {
mustRunAfter(tasks.findByName("generateLicenses"))
doLast {
project.addOssLicense(
"Noto Sans JP",
"https://fonts.google.com/specimen/Noto+Sans+JP#license"
)
project.addOssLicense(
"Font Awesome",
"""
Font Awesome Free License
-------------------------
Font Awesome Free is free, open source, and GPL friendly. You can use it for
commercial projects, open source projects, or really almost whatever you want.
Full Font Awesome Free license: https://fontawesome.com/license/free.
# Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/)
In the Font Awesome Free download, the CC BY 4.0 license applies to all icons
packaged as SVG and JS file types.
# Fonts: SIL OFL 1.1 License (https://scripts.sil.org/OFL)
In the Font Awesome Free download, the SIL OFL license applies to all icons
packaged as web and desktop font files.
# Code: MIT License (https://opensource.org/licenses/MIT)
In the Font Awesome Free download, the MIT license applies to all non-font and
non-icon files.
# Attribution
Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font
Awesome Free files already contain embedded comments with sufficient
attribution, so you shouldn't need to do anything additional when using these
files normally.
We've kept attribution comments terse, so we ask that you do not actively work
to remove them from files, especially code. They're a great way for folks to
learn about Font Awesome.
# Brand Icons
All brand icons are trademarks of their respective owners. The use of these
trademarks does not indicate endorsement of the trademark holder by Font
Awesome, nor vice versa. **Please do not use brand logos for any purpose except
to represent the company, product, or service to which they refer.**
""".trimIndent()
)
}
// 自動登録されないOSSライセンスを追加する
aboutLibraries {
configPath = "OtherLicenses"
}

fun Project.addOssLicense(libName: String, licenseContent: String) {
// layout.buildDirectory.dir("")
val outputDir = File(buildDir, "generated/third_party_licenses")
.child("res")
.child("raw")
println("outputFile: ${outputDir.absolutePath}")
// ライセンスファイル
val licensesFile = File(outputDir, "third_party_licenses")
// ライセンスファイルへの書き込み前に現在の位置を保持
val start = licensesFile.length()

// ライセンスファイルへ書き込み
licensesFile.fileWriter(true).use {
it.write(licenseContent)
it.newLine()
}

// ライセンスメタデータファイルに書き込み
File(outputDir, "third_party_license_metadata").fileWriter(true).use {
it.write("${start}:${licenseContent.length} $libName")
it.newLine()
}
}

// preBuild前にライセンス情報を追加する
//checkNotNull(tasks.findByPath(":app:preBuild"))
// .dependsOn("addOssLicenseTask")

data class Version(
val major: Int,
val minor: Int,
Expand All @@ -228,5 +155,5 @@ fun File.fileWriter(overwrite: Boolean): FileWriter {
}

fun FileWriter.newLine() {
write(System.getProperty("line.separator"))
write(System.lineSeparator())
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package io.github.emusute1212.makasetechoice.ui.settings

import android.content.Intent
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.tween
import androidx.compose.animation.slideIn
import androidx.compose.animation.slideOut
Expand All @@ -17,21 +14,20 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat.startActivity
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
import io.github.emusute1212.makasetechoice.ui.MakaseteChoiceTheme
import io.github.emusute1212.makasetechoice.ui.settings.menus.ABOUT_APP_SCREEN_ROUTE
import io.github.emusute1212.makasetechoice.ui.settings.menus.OSS_LICENSE_SCREEN_ROUTE
import io.github.emusute1212.makasetechoice.ui.settings.menus.nestedAboutAppScreen
import io.github.emusute1212.makasetechoice.ui.settings.menus.nestedOssLicenseScreen

const val SETTING_SCREEN_ROUTE = "setting_screen"
fun NavGraphBuilder.settingScreen() {
Expand Down Expand Up @@ -80,6 +76,7 @@ fun SettingScreenHost() {
nestedNavController = nestedNavController
)
nestedAboutAppScreen()
nestedOssLicenseScreen()
}
}

Expand All @@ -98,7 +95,6 @@ private fun NavGraphBuilder.nestedSettingScreen(
private fun SettingScreen(
nestedNavController: NavController,
) {
val context = LocalContext.current
SettingMenus(
menus = SettingMenu.entries,
onItemClick = {
Expand All @@ -110,9 +106,9 @@ private fun SettingScreen(
}

SettingMenu.LICENSE -> {
Intent(context, OssLicensesMenuActivity::class.java).also { intent ->
startActivity(context, intent, null)
}
nestedNavController.navigate(
route = OSS_LICENSE_SCREEN_ROUTE
)
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.emusute1212.makasetechoice.ui.settings.menus

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer

const val OSS_LICENSE_SCREEN_ROUTE = "oss_license_screen"
fun NavGraphBuilder.nestedOssLicenseScreen() {
composable(OSS_LICENSE_SCREEN_ROUTE) {
OssLicenseScreen()
}
}

@Composable
private fun OssLicenseScreen() {
LibrariesContainer(
Modifier.fillMaxSize()
)
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
alias(libs.plugins.jetbrains.kotlin.android) apply false
alias(libs.plugins.firebase.crashlytics) apply false
alias(libs.plugins.google.services) apply false
alias(libs.plugins.google.oss.licenses.plugin) apply false
alias(libs.plugins.google.devtools.ksp) apply false
alias(libs.plugins.hilt) apply false
alias(libs.plugins.aboutlibraries) apply false
}
19 changes: 5 additions & 14 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,12 @@ composeBom = "2024.06.00"
room = "2.6.1"
hilt = "2.49"
googlePlayService = "4.4.2"
ossLicensePlugin = "0.10.6"
ossLicense = "17.1.0"
firebaseBom = "33.1.1"
firebaseBom = "33.1.2"
firebaseCrashlytics = "3.0.2"
navigationCompose = "2.7.7"
googleDevtoolsKsp = "1.9.10-1.0.13"
maverics = "3.0.9"
orgJetbrainsKotlinJvm = "1.9.0"
compileSdk = "34"
minSdk = "24"
targetSdk = "34"
applicationId = "io.github.emusute1212.makasetechoice"
namespace = "io.github.emusute1212.makasetechoice"
aboutlibraries = "11.2.2"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand All @@ -43,9 +36,6 @@ androidx-material3 = { group = "androidx.compose.material3", name = "material3"
androidx-room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
google-service = { group = "com.google.gms", name = "google-services", version.ref = "googlePlayService" }
google-oss-licenses-plugin = { group = "com.google.android.gms", name = "oss-licenses-plugin", version.ref = "ossLicensePlugin" }
google-oss-licenses = { group = "com.google.android.gms", name = "play-services-oss-licenses", version.ref = "ossLicense" }
firebase-bom = { group = "com.google.firebase", name = "firebase-bom", version.ref = "firebaseBom" }
firebase-crashlytics-ktx = { group = "com.google.firebase", name = "firebase-crashlytics-ktx" }
navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
Expand All @@ -55,12 +45,13 @@ mavericks-core = { group = "com.airbnb.android", name = "mavericks", version.ref
mavericks-hilt = { group = "com.airbnb.android", name = "mavericks-hilt", version.ref = "maverics" }
mavericks-compose = { group = "com.airbnb.android", name = "mavericks-compose", version.ref = "maverics" }
mavericks-navigation = { group = "com.airbnb.android", name = "mavericks-navigation", version.ref = "maverics" }
aboutlibraries-compose = { group = "com.mikepenz", name = "aboutlibraries-compose-m3", version.ref = "aboutlibraries" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
google-devtools-ksp = { id = "com.google.devtools.ksp", version.ref = "googleDevtoolsKsp"}
google-devtools-ksp = { id = "com.google.devtools.ksp", version.ref = "googleDevtoolsKsp" }
google-services = { id = "com.google.gms.google-services", version.ref = "googlePlayService" }
google-oss-licenses-plugin = { id = "com.google.android.gms.oss-licenses-plugin", version.ref = "ossLicensePlugin" }
firebase-crashlytics = { id = "com.google.firebase.crashlytics", version.ref = "firebaseCrashlytics" }
aboutlibraries = { id = "com.mikepenz.aboutlibraries.plugin", version.ref = "aboutlibraries" }

0 comments on commit 67516e6

Please sign in to comment.