Illegal char <:> at index

今天换台windows打包项目忽然报错,信息如下(项目路径及名字做脱敏处理为xxxx了):

Execution failed for task ':app:packageDebug'.
> Multiple task action failures occurred:
   > Illegal char <:> at index 94: F:\development\xxxxxxxxxx\app\debug\xxxxx_v1.0debug2021-08-16 14:51:14.apk
   > A failure occurred while executing com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable
      > Illegal char <:> at index 94: F:\development\xxxxxxxxxx\app\debug\xxxxx_v1.0debug2021-08-16 14:51:14.apk

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

到debug目录看没有生成这个apk包,很是奇怪,网上有说是路径编码啥的,反正测试后不是我这边的问题原因,最后才找到,是我用的编译期自动修改apk名代码又兼容性问题导致,之前是好的,现在换台电脑不行了,最后发现是我加的个时间方法generateBuildConfigTime的时间格式HH:mm有冒号导致的,但是我另一台linux电脑是ok的,根本原因是windows不允许文件名带有冒号等特殊字符,后来去掉冒号就好了

applicationVariants.all { variant ->
            variant.outputs.all { output ->
                def outputFile = output.outputFile
                if (outputFile != null && outputFile.name.endsWith('.apk')) outputFileName = "xxxxx_v${versionName}${variant.buildType.name}${generateBuildConfigTime()}.apk"
              }
        }
String generateBuildConfigTime() {
    return (new Date()).format("yyyyMMdd_HH:mm", TimeZone.getTimeZone("GMT+08:00"))
}

其实现在最新版的gradle修改打包后的文件名推荐方法是设置属性archivesBaseName,这样不仅可以改apk的名字,还可以控制aab包的名字

android {
    .........

    defaultConfig {
        .........

        setProperty("archivesBaseName", "xxxxx_v${versionName}_${generateBuildConfigTime()}")
    }
   
    .........
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容