gradlew assembleDebug需要我的发布密钥密码

gradlew assembleDebug需要我的发布密钥密码,gradle,build,android-gradle-plugin,release,Gradle,Build,Android Gradle Plugin,Release,我添加了签名设置,如图所示。现在,当我运行/gradlew assembleDebug时,它需要我的密钥库和密钥密码,最后有两个APK文件: ./Main/build/outputs/apk/Main-debug.apk ./Main/build/outputs/apk/Main-debug-unaligned.apk 因此Gradle构建了我的模块的调试版本,但需要发布密钥 构建模块的build.gradle文件如下所示 apply plugin: 'android' android {

我添加了签名设置,如图所示。现在,当我运行
/gradlew assembleDebug
时,它需要我的密钥库和密钥密码,最后有两个APK文件:

  • ./Main/build/outputs/apk/Main-debug.apk
  • ./Main/build/outputs/apk/Main-debug-unaligned.apk
  • 因此Gradle构建了我的模块的调试版本,但需要发布密钥

    构建模块的build.gradle文件如下所示

    apply plugin: 'android'
    
    android {
        compileSdkVersion 19
        buildToolsVersion '19.1.0'
    
        signingConfigs {
            release {
                storeFile file("my-release-key.keystore")
                storePassword System.console().readLine("\nKeystore password: ")
                keyPassword System.console().readLine("Key password: ")
                keyAlias "my_key"
            }
        }
    
        defaultConfig {
            minSdkVersion 9
            targetSdkVersion 19
            versionCode 1
            versionName "1.0"
        }
    
        buildTypes {
            release {
                runProguard true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
                signingConfig signingConfigs.release
            }
        }
    }
    
    dependencies {
        compile 'com.android.support:support-v4:19.0.1'
        compile 'com.android.support:appcompat-v7:19.0.1'
        compile project(':Log-Wrapper')
        compile 'com.google.android.gms:play-services:+'
    }
    
    更新#1.


    解决方案是可行的,我接受了答案。但我个人更喜欢使用上述方法。发布密钥存储在本地且安全,无需在每次编译发布版本时键入密码

    看来我可以把这里和那里收集到的一些建议合并起来。。我让它工作了

    问题似乎在于,在build.gradle中的任何地方都可以编写如下内容:

    storePassword System.console().readLine("\nKeystore password: ")
    
    它将随时执行

    我提出的解决方案是,在buildTypes块之前创建signingCongif块:

    signingConfigs {
        release {
            storeFile file("c://my.keystore")
            storePassword "" // REQUIRED otherwise cannot be overwritten
            keyAlias "myAlias"
            keyPassword "" // REQUIRED otherwise cannot be overwritten
        }
    }   
    
    buildTypes {
        [...]
    
    并使用以下内容调整渐变配置:

    gradle.taskGraph.whenReady { taskGraph ->
    if(taskGraph.hasTask(assembleRelease) || taskGraph.hasTask(installRelease)) {
        // Only execute when we are trying to assemble a release build
        def passKeystore = System.console().readLine("\nKeystore password: ")
        def passKey = System.console().readLine("\nKey password: ")
        android.signingConfigs.release.storePassword = passKeystore
        android.signingConfigs.release.keyPassword = passKey
    }
    
    }

    请注意:
    1.此块位于“安卓{}”块的外部和前面。

    2.这仅在命令行执行中进行了测试。似乎在没有可用控制台的情况下需要一些修复。

    似乎我可以将这里和那里收集到的一些建议合并起来。。我让它工作了

    问题似乎在于,在build.gradle中的任何地方都可以编写如下内容:

    storePassword System.console().readLine("\nKeystore password: ")
    
    它将随时执行

    我提出的解决方案是,在buildTypes块之前创建signingCongif块:

    signingConfigs {
        release {
            storeFile file("c://my.keystore")
            storePassword "" // REQUIRED otherwise cannot be overwritten
            keyAlias "myAlias"
            keyPassword "" // REQUIRED otherwise cannot be overwritten
        }
    }   
    
    buildTypes {
        [...]
    
    并使用以下内容调整渐变配置:

    gradle.taskGraph.whenReady { taskGraph ->
    if(taskGraph.hasTask(assembleRelease) || taskGraph.hasTask(installRelease)) {
        // Only execute when we are trying to assemble a release build
        def passKeystore = System.console().readLine("\nKeystore password: ")
        def passKey = System.console().readLine("\nKey password: ")
        android.signingConfigs.release.storePassword = passKeystore
        android.signingConfigs.release.keyPassword = passKey
    }
    
    }

    请注意:
    1.此块位于“安卓{}”块的外部和前面。

    2.这仅在命令行执行中进行了测试。似乎在没有可用控制台的情况下需要一些修复。

    似乎我可以将这里和那里收集到的一些建议合并起来。。我让它工作了

    问题似乎在于,在build.gradle中的任何地方都可以编写如下内容:

    storePassword System.console().readLine("\nKeystore password: ")
    
    它将随时执行

    我提出的解决方案是,在buildTypes块之前创建signingCongif块:

    signingConfigs {
        release {
            storeFile file("c://my.keystore")
            storePassword "" // REQUIRED otherwise cannot be overwritten
            keyAlias "myAlias"
            keyPassword "" // REQUIRED otherwise cannot be overwritten
        }
    }   
    
    buildTypes {
        [...]
    
    并使用以下内容调整渐变配置:

    gradle.taskGraph.whenReady { taskGraph ->
    if(taskGraph.hasTask(assembleRelease) || taskGraph.hasTask(installRelease)) {
        // Only execute when we are trying to assemble a release build
        def passKeystore = System.console().readLine("\nKeystore password: ")
        def passKey = System.console().readLine("\nKey password: ")
        android.signingConfigs.release.storePassword = passKeystore
        android.signingConfigs.release.keyPassword = passKey
    }
    
    }

    请注意:
    1.此块位于“安卓{}”块的外部和前面。

    2.这仅在命令行执行中进行了测试。似乎在没有可用控制台的情况下需要一些修复。

    似乎我可以将这里和那里收集到的一些建议合并起来。。我让它工作了

    问题似乎在于,在build.gradle中的任何地方都可以编写如下内容:

    storePassword System.console().readLine("\nKeystore password: ")
    
    它将随时执行

    我提出的解决方案是,在buildTypes块之前创建signingCongif块:

    signingConfigs {
        release {
            storeFile file("c://my.keystore")
            storePassword "" // REQUIRED otherwise cannot be overwritten
            keyAlias "myAlias"
            keyPassword "" // REQUIRED otherwise cannot be overwritten
        }
    }   
    
    buildTypes {
        [...]
    
    并使用以下内容调整渐变配置:

    gradle.taskGraph.whenReady { taskGraph ->
    if(taskGraph.hasTask(assembleRelease) || taskGraph.hasTask(installRelease)) {
        // Only execute when we are trying to assemble a release build
        def passKeystore = System.console().readLine("\nKeystore password: ")
        def passKey = System.console().readLine("\nKey password: ")
        android.signingConfigs.release.storePassword = passKeystore
        android.signingConfigs.release.keyPassword = passKey
    }
    
    }

    请注意:
    1.此块位于“安卓{}”块的外部和前面。

    2.这仅在命令行执行中进行了测试。似乎在没有可用控制台的情况下需要一些修复。

    似乎只有3个选项:

  • 将我的签名配置提取到单独的psedoo项目
  • 自动签名,但使用发布密钥对所有内容进行签名
  • 在命令行上手动输入密码
  • 这是我的变通方法,也是您实现完美平衡的第四个选择:

    apply plugin: 'com.android.application'
    
    gradle.taskGraph.whenReady { taskGraph ->
        if(taskGraph.hasTask(':app:assembleRelease')) {
            android.signingConfigs.release.storeFile = file(KEYSTORE)
            android.signingConfigs.release.storePassword = STOREPASS
            android.signingConfigs.release.keyAlias = KEY_ALIAS
            android.signingConfigs.release.keyPassword = KEYPASS
        }
    }
    
    android {
        ...
        defaultConfig {
            ...
        }
        signingConfigs {
            debug {
    
            }
            release {
    
            }
        }
        buildTypes {
        debug {
                ...
            }
            release {
                ...
                //signingConfig signingConfigs.release
            }
        }
    }
    

    这允许您仅在发布版本上使用存储的密钥和签名。看起来似乎只有3个选项:

  • 将我的签名配置提取到单独的psedoo项目
  • 自动签名,但使用发布密钥对所有内容进行签名
  • 在命令行上手动输入密码
  • 这是我的变通方法,也是您实现完美平衡的第四个选择:

    apply plugin: 'com.android.application'
    
    gradle.taskGraph.whenReady { taskGraph ->
        if(taskGraph.hasTask(':app:assembleRelease')) {
            android.signingConfigs.release.storeFile = file(KEYSTORE)
            android.signingConfigs.release.storePassword = STOREPASS
            android.signingConfigs.release.keyAlias = KEY_ALIAS
            android.signingConfigs.release.keyPassword = KEYPASS
        }
    }
    
    android {
        ...
        defaultConfig {
            ...
        }
        signingConfigs {
            debug {
    
            }
            release {
    
            }
        }
        buildTypes {
        debug {
                ...
            }
            release {
                ...
                //signingConfig signingConfigs.release
            }
        }
    }
    

    这允许您仅在发布版本上使用存储的密钥和签名。看起来似乎只有3个选项:

  • 将我的签名配置提取到单独的psedoo项目
  • 自动签名,但使用发布密钥对所有内容进行签名
  • 在命令行上手动输入密码
  • 这是我的变通方法,也是您实现完美平衡的第四个选择:

    apply plugin: 'com.android.application'
    
    gradle.taskGraph.whenReady { taskGraph ->
        if(taskGraph.hasTask(':app:assembleRelease')) {
            android.signingConfigs.release.storeFile = file(KEYSTORE)
            android.signingConfigs.release.storePassword = STOREPASS
            android.signingConfigs.release.keyAlias = KEY_ALIAS
            android.signingConfigs.release.keyPassword = KEYPASS
        }
    }
    
    android {
        ...
        defaultConfig {
            ...
        }
        signingConfigs {
            debug {
    
            }
            release {
    
            }
        }
        buildTypes {
        debug {
                ...
            }
            release {
                ...
                //signingConfig signingConfigs.release
            }
        }
    }
    

    这允许您仅在发布版本上使用存储的密钥和签名。看起来似乎只有3个选项:

  • 将我的签名配置提取到单独的psedoo项目
  • 自动签名,但使用发布密钥对所有内容进行签名
  • 在命令行上手动输入密码
  • 这是我的变通方法,也是您实现完美平衡的第四个选择:

    apply plugin: 'com.android.application'
    
    gradle.taskGraph.whenReady { taskGraph ->
        if(taskGraph.hasTask(':app:assembleRelease')) {
            android.signingConfigs.release.storeFile = file(KEYSTORE)
            android.signingConfigs.release.storePassword = STOREPASS
            android.signingConfigs.release.keyAlias = KEY_ALIAS
            android.signingConfigs.release.keyPassword = KEYPASS
        }
    }
    
    android {
        ...
        defaultConfig {
            ...
        }
        signingConfigs {
            debug {
    
            }
            release {
    
            }
        }
        buildTypes {
        debug {
                ...
            }
            release {
                ...
                //signingConfig signingConfigs.release
            }
        }
    }
    

    这允许您仅在发布版本上使用存储的密钥和签名

    尚未。既然这不是一个答案,你能把它移到我问题的评论中吗?我相信从Gradle 4.6开始这就不再有效了(或者在设置值时它似乎有效,但在尝试实际签名时,密钥库无法读取)。还没有。既然这不是一个答案,你能把它移到我问题的评论中吗?我相信从Gradle 4.6开始这就不再有效了(或者在设置值时它似乎有效,但在尝试实际签名时,密钥库无法读取)。还没有。既然这不是一个答案,你能把它移到我问题的评论中吗?我相信从Gradle 4.6开始这就不再有效了(或者在设置值时它似乎有效,但在尝试实际签名时,密钥库无法读取)。还没有。既然这不是一个答案,你能把它移到我问题的评论中吗?我相信从Gradle 4.6开始这就不再有效了(或者在设置值时它似乎有效,但当尝试实际签名时,密钥库无法读取)。