Android studio编译Java程序时报错:编码 GBK 的不可映射字符

背景:我的情况是在Android studio下编写java程序(不是Android代码)时,使用了中文。

解决办法:UTF-8支持中文注释或以及其他中文字符

在相应java代码测试对应的Gradle下添加

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

结果像这样:

apply plugin: 'java-library'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}

sourceCompatibility = "1.7"
targetCompatibility = "1.7"

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

猜你喜欢

转载自blog.csdn.net/qq_31371757/article/details/84836020