gradle 如何从file.properties加载带有特殊字符的文本并使用它对应用程序进行签名

daupos2t  于 2023-08-06  发布在  其他
关注(0)|答案(2)|浏览(113)

我试图加载我的用户,别名和密码数据保存在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库来阅读文件中的所有数据,并通过解析值来使用它们作为签名参数。但是我不知道如何在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.+'
    
    }


下面是stacktrace:

Error:Could not find org.codehaus.jackson:jackson-mapper-asl:1.9.0.
Required by:
    MyAppName:app:unspecified

tl;dr

1.我想从文件中加载文本(以JSON格式保存),将其保存到哈希表中,并将其保存为storeFile,storePassword等值。
1.失败是因为我不知道怎么做。
1.我添加到依赖clousure json库,但我仍然得到错误。
1.我需要帮助

qyswt5oh

qyswt5oh1#

下面是解决方案,我使用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.+'

}

字符串
而www.example.com的结构sign.properties是(UTF-8 charset!):

environments {
  app {
    storeFile = "android_market_key"
    storePassword ="xx"
    keyAlias = "yy"
    keyPassword = "zz"
  }
}

7ajki6be

7ajki6be2#

存储库http://download.crashlytics.com/maven似乎不具有org.codehaus.jackson:jackson-mapper-asl:1.9.0相关性。一种解决的方法是添加mavenCentral()存储库。或者,您可以使用Groovy的ConfigSlurper类解析JSON。

相关问题