我正在尝试将保存在 json 中的用户、别名和密码数据加载到字符串女巫字符集 UTF-8 中,以便能够唱出我的应用程序。
这是我之前尝试过的列表:
releasePlay {
storeFile file("android_market_key")
storePassword = "xxx"
keyAlias = "yyy"
keyPassword = "zzz"
}
它正在工作,但没有像 łóżćź 这样的特殊字符......
所以我创建了一个文件,写了一个密码,然后我使用了那个配置::
releasePlay {
storeFile file("android_market_key")
storePassword = "xxx"
keyAlias = file('password.properties').getText('UTF-8')
keyPassword = "zzz"
}
它正在工作,但还不足以保证安全。另一种方法是使用这个:
releasePlay {
storeFile file("android_market_key")
def console = System.console()
if (console != null) {
storePassword = System.console().readLine("\n\$ Enter keystore password: ")
keyAlias System.console().readLine("\n\$ Enter key alias: ")
keyPassword = System.console().readLine("\n\$ Enter key password: ")
}
}
它正在工作,但每次手动写入所有数据也很慢。
我决定使用外部 json lib 从文件中读取所有数据,并通过解析值将它们用作签名参数。但是我坚持我不知道如何在 singnin clousure 中使用这个外部库。整个问题都在 releasePlay clousure 周围。这是我的代码:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
classpath 'org.codehaus.jackson:jackson-mapper-asl:1.9.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
android {
compileSdkVersion 'Google Inc.:Google APIs:14'
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "x.xxxxxxxxx.rorlistservers"
minSdkVersion 14
targetSdkVersion 20
versionCode 7
versionName "1.5"
}
signingConfigs {
releasePlay {
def versionPropsF = file('sign.properties').getText('UTF-8')
!Error! >>> def versionProps = new ObjectMapper().readValue(versionPropsF, HashMap.class);
storeFile file("android_market_key")
storePassword = versionProps['storePassword']
keyAlias = versionProps['keyAlias']
keyPassword = versionProps['keyPassword']
}
}
lintOptions {
checkReleaseBuilds true
abortOnError false
}
buildTypes {
debug {
//res
}
release {
//res
}
}
productFlavors {
play {
signingConfig signingConfigs.releasePlay
}
}
}
repositories {
maven { url "http://dl.bintray.com/populov/" }
maven { url "http://www.bugsense.com/gradle/" }
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.0'
compile 'com.google.code.gson:gson:1.7.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.loopj.android:android-async-http:1.+'
compile 'com.google.android.gms:play-services:5.0.77'
compile project(':libraries:ViewPagerIndicator-')
compile 'com.crashlytics.android:crashlytics:1.+'
}
这是堆栈跟踪:
Error:Could not find org.codehaus.jackson:jackson-mapper-asl:1.9.0.
Required by:
MyAppName:app:unspecified
tl;博士
哈希表并将其保存到 storeFile、storePassword 等值。
最佳答案
这是解决方案,我使用了 ConfigSlurper:
在 build.gradle 我写道:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
android {
compileSdkVersion 'Google Inc.:Google APIs:14'
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "x.xxxxxxxxx.rorlistservers"
minSdkVersion 14
targetSdkVersion 20
versionCode 7
versionName "1.5"
}
signingConfigs {
releasePlay {
def fileJsonConfig = file('sign.properties').getText('UTF-8')
def config = new ConfigSlurper('app').parse(fileJsonConfig)
storeFile file(config.storeFile)
storePassword = config.storePassword
keyAlias = config.keyAlias
keyPassword = config.keyPassword
println fileJsonConfig
println config
}
}
lintOptions {
checkReleaseBuilds true
abortOnError false
}
buildTypes {
debug {
//res
}
release {
//res
}
}
productFlavors {
play {
signingConfig signingConfigs.releasePlay
}
}
}
repositories {
maven { url "http://dl.bintray.com/populov/" }
maven { url "http://www.bugsense.com/gradle/" }
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile 'com.google.code.gson:gson:1.7.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.loopj.android:android-async-http:1.+'
compile 'com.google.android.gms:play-services:5.0.77'
compile project(':libraries:ViewPagerIndicator-')
compile 'com.crashlytics.android:crashlytics:1.+'
}
sign.properties 的结构是(UTF-8 字符集!):
environments {
app {
storeFile = "android_market_key"
storePassword ="xx"
keyAlias = "yy"
keyPassword = "zz"
}
}
关于android - gradle 从文件中加载文本并使用外部库进行签名配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25003120/