2016-08-09 8 views
0

私はプロジェクトへのフレーバーの追加に取り組んでおり、以下の問題に遭遇しました。 keystoreパス、エイリアスとパスワードを追加する代わりに、.propertiesファイルに追加して、build.gradleにアクセスしようとしました。署名のための外部ファイルをロードするグレイド

は、これは

プロジェクトがgitのであるので、私はgradle.propertiesに保管した場合、他のユーザーも.propertiesファイルパスへの私のローカルパスを取得し、私がやった方法です。その理由のために、私はlocal.properties.propertiesパスを追加しました。 build.gradle私はlocal.propertiesから変数を読み込み、プロパティファイルに書き込まれた各変数を取得しています。

local.properties

variable.prop=C\:\\Users\\user\\signing\\project\\pro.properties 

ここbuild.gradle

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

    dependencies { 
     classpath 'io.fabric.tools:gradle:1.+' 
    } 
} 

apply plugin: 'com.android.application' 
apply plugin: 'io.fabric' 
apply plugin: 'com.neenbedankt.android-apt' 

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

def versionMajor = 1 
def versionMinor = 0 
def versionPatch = 1 
def versionBuild = 1 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 

    Properties props = new Properties() 
    props.load(project.rootProject.file('local.properties').newDataInputStream()) 
    def localPropertiesPath = props.getProperty('variable.prop', null); 
    if (localPropertiesPath == null) 
     throw new GradleException("Unable to find properties file. Variable might not be added in local.properties or file may not exist in given path") 
    else { 
     def propFile = file(localPropertiesPath) 
     if (propFile.canRead()) { 
      Properties properties = new Properties() 
      properties.load(new FileInputStream(propFile)) 

      signingConfigs { 

       uat { 
        storeFile file(properties['uatKeystorePath']) 
        keyAlias properties['uatKeyAlias'] 
        keyPassword properties['uatKeyPassword'] 
        storePassword properties['uatStorePassword'] 
       } 

       release { 
        storeFile file(properties['releaseKeystorePath']) 
        keyAlias properties['releaseKeyAlias'] 
        keyPassword properties['releaseKeyPassword'] 
        storePassword properties['releaseStorePassword'] 
       } 
      } 

      defaultConfig { 
       applicationId "com.package.name" 
       minSdkVersion 15 
       targetSdkVersion 23 
       versionCode versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild 
       versionName "${versionMajor}.${versionMinor}.${versionPatch}" 
       setMultiDexEnabled true 
      } 

      dexOptions { 
       javaMaxHeapSize "2048M" 
      } 

      buildTypes { 
       release { 
        minifyEnabled false 
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
        signingConfig signingConfig.release 
       } 
      } 
     } 
    } 
} 

、ラインにproperties.load(new FileInputStream(propFile))それは常に

スロー私が試みた

  1. ハードpro.propertiesのパスコードの代わりに、またと試み以下link

  2. に所与として試みlocal.properties

  3. から取りますforward-slash,backslash、012を変更するの組み合わせ

しかしこれまで何も助けてくれませんでした。すべてのヘルプは、私は私が答える必要はありそうコメントすることはできませんpro.propertiesファイル

uatKeystorePath=C:\Users\user\.signing\project\uat_keystore.jks 
uatStorePassword=StorePassword 
uatKeyAlias=AliasName 
uatKeyPassword=KeyPassword 
releaseKeystorePath=C:\Users\user\.signing\project\release_keystore.jks 
releaseStorePassword=StorePassword 
releaseKeyAlias=AliasName 
releaseKeyPassword=KeyPassword 

答えて

0

を理解されるであろう、しかし、私はちょうどあなたがあなたの本当のファイル内の同じタイプミスなどがある場合はお聞きしたいですあなたはあなたの質問になったのですか?

variable.prop=C\:\\Users\\user\\signing\\project\\pro.properties

私は、バックスラッシュがC:

+0

間はい、それはエスケープ文字だということを意味します。他にもエラーが表示されていなければなりません –

+0

まだ見つからない場合、バグを見つける良い方法は出力を印刷することだと思います。 '' println localPropertiesPath'のような行を 'def propFile = file(localPropertiesPath)'の後に 'println propFile'のような行を含めるべきです(' 'local.properties'') –

関連する問題