2017-09-15 15 views
1

所以我想创建一个签署配置任何释放口味,我在android中。但我希望能够通过点击运行按钮而不是构建--->生成签名的Apk来从IDE运行它。Android gradle signConfigs从本地文件不允许从IDE运行配置

我想要从应用程序分离密钥库的凭据和路径。所以我在我的项目应用文件夹中创建了一个属性。

让我们来看看什么我迄今所做的:

gradle.properties文件看起来像这样:

myapp.properties=.signing/myapp_signing.properties 

属性文件的内容是这样的:

keystore=/Users/Fred/Documents/mykey_ks.jks 
keystore.alias_pw=abcd1234 

然后我有以下实际从证书文件中获取信息到签名配置关闭:

apply plugin: 'com.android.application' 

apply plugin: 'io.fabric' 
repositories { 
    maven { url 'https://maven.fabric.io/public' } 
} 


if (project.hasProperty("myapp.properties") 
     && new File(project.property("myapp.properties")).exists()) { 

    Properties props = new Properties() 
    props.load(new FileInputStream(file(project.property("myapp.properties")))) 
    android { 
     signingConfigs { 
      release { 
       storeFile file(props['keystore']) 
       storePassword props['keystore.password'] 
      } 
     } 
    } 
} 

android { 
    compileSdkVersion 26 
    buildToolsVersion "25.0.3" 
    defaultConfig { 
     minSdkVersion 26 
//....... more android stuff below, should be ok to have two android closures right ? 


} 

现在,当我在选择ProdRelease后按下android工作室上的运行按钮,我得到一个警告,我的apk没有签名,也没有签名配置可用?为什么?

enter image description here

UPDATE:我想在的build.gradle应用级文件如下:

buildTypes { 
     release { 

      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt') 
      releaseBuild() 
     } 
    } 
//.... 
def releaseBuild(){ 
    if (project.hasProperty("pomelo.properties") 
      && new File(project.property("pomelo.properties")).exists()) { 

     println 'file does exist' 
     Properties props = new Properties() 
     props.load(new FileInputStream(file(project.property("myapp.properties")))) 
     storeFile file(props['keystore']) 
     storePassword props['keystore.password'] 
     keyAlias props['keystore.alias'] 
     keyPassword props['keystore.alias_password'] 
    } 
} 

回答

0

也许它应该是这样的

signingConfigs { 
    release { 
     releaseBuild() 
     ..... 
    } 
} 


def releaseBuild(){ 
if (project.hasProperty("myapp.properties") 
     && new File(project.property("myapp.properties")).exists()) { 

    Properties props = new Properties() 
    props.load(new FileInputStream(file(project.property("myapp.properties")))) 
    storeFile file(props['keystore']) 
    storePassword props['keystore.password'] 
    } 
} 
+0

我试过,但相同的定义结果。当我在Android工作室中运行按钮时,它告诉我该变体未被签名。与我在我的问题中显示的图像截图相同。你试过了吗? – j2emanue

+0

println语句“文件不存在”永远不会被调用。在我更新的答案 – j2emanue