【问题标题】:Signing apk by gradle - invalid encoding for special chars通过 gradle 签名 apk - 特殊字符的无效编码
【发布时间】:2014-05-30 21:46:28
【问题描述】:

根据许多关于配置 gradle 来签署 apk 的主题,我使用了这个solution。 似乎它需要适当的值,但是我无法成功完成整个操作。可能这可能是字母“ł”的问题,它甚至在终端中显示错误。我需要帮助,因为我现在不知道该怎么办。我已经花了大约 4 个小时...

这是主项目app gradle 属性文件:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"    

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
    }

    signingConfigs {
        release {
            storeFile file(RELEASE_STORE_FILE)

            storePassword RELEASE_KEY_ALIAS

            keyAlias RELEASE_KEY_ALIAS

            keyPassword RELEASE_KEY_PASSWORD
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }

}

dependencies {
    //...
}

此文件从 Window 用户目录中的 ~/.gradle/gradle.properties 文件中获取数据。

org.gradle.parallel=true
org.gradle.daemon=false

    RELEASE_STORE_FILE=C:/users/xxx/f1/f1/android_market_key
    RELEASE_STORE_PASSWORD=lololo
    RELEASE_KEY_ALIAS=łłłł
    RELEASE_KEY_PASSWORD=lololo

我试过用:

compileOptions.encoding = "UTF-8"

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

甚至在gradlew.bat 中添加一些 -D* 选项来设置编码,但仍然失败。

请帮忙,我卡住了。

【问题讨论】:

    标签: android encoding gradle android-studio apk


    【解决方案1】:

    检查gradle.properties 文件的编码并确保它是UTF-8。

    某些编辑器(如记事本)默认为 ANSI 编码,如果文件包含非 ASCII 字符会导致问题。

    (例如:在记事本中:文件 -> 另存为 -> 编码)

    【讨论】:

      【解决方案2】:

      所以我找到了部分解决方案,在每个需要使用从控制台读取的特殊字符的地方,它终于奏效了:

      解决方案:

      apply plugin: 'android'
      
      android {
      
      
          compileSdkVersion 19
          buildToolsVersion '19.1.0'
      
          defaultConfig {
              minSdkVersion 10
              targetSdkVersion 19
          }
      
          signingConfigs {
              release {
                  storeFile file(RELEASE_STORE_FILE)
                  storePassword RELEASE_STORE_PASSWORD
      
                  def console = System.console()
                  if (console != null) {
                      keyAlias System.console().readLine("\n\$ Enter key alias: ")
                  }
      
                  keyPassword RELEASE_KEY_PASSWORD
              }
          }
      
          buildTypes {
              release {
                  signingConfig signingConfigs.release
              }
          }
      
          productFlavors {
          }
      }
      
      dependencies {
          //my dependencies
      }
      

      【讨论】:

        【解决方案3】:

        在遇到同样的问题并花费了几个小时后,我成功地构建了如下:

        1. 遵循here 中描述的说明。因此,我没有使用 gradle.properties 来存储值,而是将它们存储在自定义文件 signing.properties 中。

        2. 修改文件读取部分如下:

          props.load(new InputStreamReader(new FileInputStream(propFile), "UTF-8"))

        希望对你有帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多