Compare commits

...

2 Commits

8 changed files with 54 additions and 7 deletions

View File

@@ -6,4 +6,10 @@
## 1.0.1 | 2023.10.13
- 修复在使用 Kotlin on Android 插件的项目上找不到源码路径的问题
- 修复在使用 Kotlin on Android 插件的项目上找不到源码路径的问题
## 1.0.2 | 2025.08.19
- 修复在新版 Android Gradle Plugin 及 Android Studio/IDEA 中部署源码路径时的错误
`removeContentEntry: removed content entry url 'build/generated/flexi-locale' still exists after removing`
- 新增 `sourceSetName` 方法,允许自定义要部署的源集名称

View File

@@ -6,4 +6,10 @@
## 1.0.1 | 2023.10.13
- Fixed a problem where the source code path could not be found on projects using the Kotlin on Android plugin
- Fixed a problem where the source code path could not be found on projects using the Kotlin on Android plugin
## 1.0.2 | 2025.08.19
- Fix errors when deploying source code paths in the new version of Android Gradle Plugin and Android Studio/IDEA
`removeContentEntry: removed content entry url 'build/generated/flexi-locale' still exists after removing`
- Added the `sourceSetName` method to allow customization of the source set name to be deployed

View File

@@ -74,6 +74,10 @@ android {
// 默认为 "build/generated/flexi-locale"
// 建议将生成的代码放置于 "build" 目录下,因为生成的代码不建议去修改它
generateDirPath = "build/generated/flexi-locale"
// 自定义部署的 `sourceSet` 名称
// 如果你的项目源码部署名称不是默认值,可以在这里自定义
// 默认为 "main"
sourceSetName = "main"
// 自定义生成的包名
// Android 项目默认使用 "android" 配置方法块中的 "namespace"
// 你可以不进行设置,包名在一般情况下会自动进行匹配

View File

@@ -80,6 +80,10 @@ android {
// Default is "build/generated/flexi-locale"
// It is recommended to place the generated code in the "build" directory, because the generated code is not recommended to be modified
generateDirPath = "build/generated/flexi-locale"
// Custom deployed `sourceSet` name
// If your project source code deployment name is not the default value, you can customize it here
// Defaults to "main"
sourceSetName = "main"
// Customize the generated package name
// Android projects use the "namespace" in the "android" configuration method block by default
// You don't need to set it, the package name will be automatically matched under normal circumstances
@@ -106,7 +110,9 @@ If you want to use it in Groovy DSL, please change the `=` of all variables to s
Assume this is the `strings.xml` of your current project, divided into two directories: `default` and `zh-rCN`.
> values/strings.xml
```xml
<resources>
<string name="app_name">My App</string>
<string name="say_hello">Hello %1$s</string>
@@ -116,6 +122,7 @@ Assume this is the `strings.xml` of your current project, divided into two direc
> values-zh-rCN/strings.xml
```xml
<resources>
<string name="app_name">我的应用</string>
<string name="say_hello">你好 %1$s</string>

View File

@@ -37,6 +37,11 @@ internal interface IFlexiLocaleConfigs {
* "build/generated/[FlexiLocaleProperties.PROJECT_MODULE_NAME]"
*/
internal const val DEFAULT_GENERATE_DIR_PATH = "build/generated/${FlexiLocaleProperties.PROJECT_MODULE_NAME}"
/**
* 默认的部署 `sourceSet` 名称
*/
internal const val DEFAULT_SOURCE_SET_NAME = "main"
}
/** 是否启用插件 */
@@ -45,6 +50,9 @@ internal interface IFlexiLocaleConfigs {
/** 自定义生成的目录路径 */
val generateDirPath: String
/** 自定义部署的 `sourceSet` 名称 */
val sourceSetName: String
/** 自定义生成的包名 */
val packageName: String
@@ -58,5 +66,5 @@ internal interface IFlexiLocaleConfigs {
* 获取内部 [hashCode]
* @return [Int]
*/
fun innerHashCode() = "$isEnable$generateDirPath$packageName$className$isEnableRestrictedAccess".hashCode()
fun innerHashCode() = "$isEnable$generateDirPath$sourceSetName$packageName$className$isEnableRestrictedAccess".hashCode()
}

View File

@@ -59,6 +59,16 @@ open class FlexiLocaleConfigureExtension internal constructor() {
var generateDirPath = IFlexiLocaleConfigs.DEFAULT_GENERATE_DIR_PATH
@JvmName("generateDirPath") set
/**
* 自定义部署的 `sourceSet` 名称
*
* 如果你的项目源码部署名称不是默认值 - 可以在这里自定义
*
* 默认为 [IFlexiLocaleConfigs.DEFAULT_SOURCE_SET_NAME]
*/
var sourceSetName = IFlexiLocaleConfigs.DEFAULT_SOURCE_SET_NAME
@JvmName("sourceSetName") set
/**
* 自定义生成的包名
*
@@ -104,12 +114,14 @@ open class FlexiLocaleConfigureExtension internal constructor() {
className.checkingValidClassName()
val currentEnable = isEnable
val currentGenerateDirPath = project.file(generateDirPath).absolutePath
val currentSourceSetName = sourceSetName
val currentPackageName = packageName
val currentClassName = "${className.ifBlank { project.fullName().uppercamelcase() }}Locale"
val currentEnableRestrictedAccess = isEnableRestrictedAccess
return object : IFlexiLocaleConfigs {
override val isEnable get() = currentEnable
override val generateDirPath get() = currentGenerateDirPath
override val sourceSetName get() = currentSourceSetName
override val packageName get() = currentPackageName
override val className get() = currentClassName
override val isEnableRestrictedAccess get() = currentEnableRestrictedAccess

View File

@@ -130,8 +130,12 @@ internal object LocaleAnalysisHelper {
*/
private fun initializePlugins(project: Project) {
runCatching {
fun BaseExtension.updateSourceDirs() = sourceSets.configureEach { kotlin.srcDir(configs.generateDirPath) }
fun KotlinProjectExtension.updateSourceDirs() = sourceSets.configureEach { kotlin.srcDir(configs.generateDirPath) }
fun BaseExtension.updateSourceDirs() = sourceSets.firstOrNull {
it.name == configs.sourceSetName
}?.kotlin?.srcDir(configs.generateDirPath) ?: FLog.warn("Could not found source set \"${configs.sourceSetName}\"")
fun KotlinProjectExtension.updateSourceDirs() = sourceSets.firstOrNull {
it.name == configs.sourceSetName
}?.kotlin?.srcDir(configs.generateDirPath) ?: FLog.warn("Could not found source set \"${configs.sourceSetName}\"")
fun BaseVariant.updateResDirectories() = sourceSets.forEach { provide -> provide.resDirectories?.also { resDirectories.addAll(it) } }
project.plugins.withId(APPLICATION_PLUGIN_NAME) {
project.get<AppExtension>().also { extension ->

View File

@@ -3,12 +3,12 @@ project.name=FlexiLocale
project.url=https://github.com/BetterAndroid/FlexiLocale
project.groupName=com.highcapable.flexilocale
project.moduleName=flexi-locale
project.version=1.0.1
project.version=1.0.2
# Gradle Plugin Configuration
gradle.plugin.moduleName=${project.groupName}.gradle.plugin
gradle.plugin.implementationClass=${project.groupName}.plugin.FlexiLocalePlugin
# Maven Publish Configuration
SONATYPE_HOST=S01
SONATYPE_HOST=CENTRAL_PORTAL
RELEASE_SIGNING_ENABLED=true
# Maven POM Configuration
POM_NAME=FlexiLocale