2017-06-13 14 views
0

私はsuccesfulyのGradleスクリプトを使用して、私のgradle.propretiesファイルを作成している、私は私のコードを共有することになり、設定Gradleのタスク問題

build.gradle: 
afterEvaluate { 
processDebugGoogleServices.dependsOn switchToDebug 
processReleaseGoogleServices.dependsOn switchToRelease 
} 
String base = "URL" 
def slurper = new JsonSlurper() 

def app_data = slurper.parseText(base.toURL().text) 

def FileWriter mFile = new FileWriter(".........../gradle.properties") 

今私は一つの問題は、キーと値のペアに直面しています私のgradle.propertyファイルを書いている間、アンドロイドによるデフォルト設定は、私の タスクで実行されます。これは、どのシステムがapplicationIdを見つけることができないかによって、バージョンコード、バージョン名など

build.gradle: 
android { 
compileSdkVersion 25 
buildToolsVersion "25.0.2" 
defaultConfig { 
applicationId "${app_id}" 
minSdkVersion 15 
targetSdkVersion 23 
versionCode java.lang.Integer.parseInt("${version_code}") 
versionName "${version_name}" 

} 


Error:(51, 0) Could not get unknown property 'app_id' for ProductFlavor_Decorated{name=main, dimension=null, minSdkVersion=null, targetSdkVersion=null, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptNdkModeEnabled=null, versionCode=null, versionName=null, applicationId=null, testApplicationId=null, testInstrumentationRunner=null, testInstrumentationRunnerArguments={}, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}} of type com.android.build.gradle.internal.dsl.ProductFlavor. 
<a href="openFile:.........../app/build.gradle">Open File</a> 

答えて

1

この問題を解決するには、rootディレクトリにother.gradleというファイルを作成してください。

task abc { 
String base = "URL" 
def slurper = new JsonSlurper() 

def app_data = slurper.parseText(base.toURL().text) 

def FileWriter mFile = new FileWriter(".........../gradle.properties") 
} 

-bオプションを指定してgradleコマンドを実行することができます。たとえば

gradle -b other.gradle abc 

これで正常にプロジェクトを実行しました。