You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何借助开源许可证插件添加无.jar/.pom格式字体的许可证文本?

Adding License Text for Non-Jar/Pom Fonts with Google's Open Source License Plugin

Hey there! I’ve run into this exact issue before when working with custom fonts alongside Google’s open source license plugin—here’s how I got it sorted out:

Step 1: Prepare Your Font License Files

First, make sure you have a proper license file (like LICENSE.txt) for each font. Place either a single shared license (if all fonts use the same terms) or individual license files in a directory alongside your fonts (or a dedicated licenses folder). Double-check that the license text matches the font’s actual open source terms (e.g., SIL Open Font License for most free fonts).

Step 2: Configure the Plugin in Your Build.gradle

You’ll need to tweak the plugin’s configuration to recognize your local font files and map them to their licenses. Open your module-level build.gradle file and add this inside the android block:

android {
    // ... your existing android config

    licensing {
        // Match your font file extensions (adjust if you use .otf or others)
        include '**/*.ttf'
        include '**/*.otf'

        // Option 1: Single license for all fonts
        licenseFile rootProject.file('src/main/assets/fonts/LICENSE.txt')

        // Option 2: Individual licenses per font (use this if fonts have different terms)
        mapping {
            'src/main/assets/fonts/CustomFont1.ttf': rootProject.file('licenses/CustomFont1-LICENSE.txt')
            'src/main/assets/fonts/CustomFont2.otf': rootProject.file('licenses/CustomFont2-LICENSE.txt')
        }
    }
}

Step 3: Ensure Fonts Are Scanned by the Plugin

If the plugin isn’t picking up your local assets automatically, add your font directory to the source sets to ensure it’s included in the plugin’s scan:

sourceSets {
    main {
        resources {
            srcDirs += 'src/main/assets/fonts'
            include '**/*.ttf', '**/*.otf', '**/LICENSE.txt'
        }
    }
}

Step 4: Generate and Verify the Licenses

Run the plugin’s license generation task for your build variant (e.g., generateReleaseLicenses for release builds). Once it completes, build your APK and check the "Open Source Licenses" section in your app’s settings—your font licenses should now appear alongside other dependencies’ licenses.

Quick Notes

  • Always make sure the license text is complete and accurate—don’t skip any clauses required by the font’s license.
  • If you’re using Android App Bundle (AAB), the plugin should still handle this correctly as long as the fonts and licenses are included in the bundle.

内容的提问来源于stack exchange,提问作者ezaspi

火山引擎 最新活动