build.gradleの外にビルド番号とバージョンを生成するメソッドが必要です。 defaultConfigに他のgradleスクリプトからメソッドを呼び出す
apply from: '../../signing.gradle'
と使用::
def getNewBuildCode = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', 'HEAD', '--count'
standardOutput = stdout
}
def version = stdout.toString().trim().toInteger()
println("versionCode: $version")
return version
}
def getVersionNameFromTag = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags'
standardOutput = stdout
}
return stdout.toString().trim()
}
は、その後、私はでbuild.gradleにそれを適用しています:
versionName getVersionNameFromTag()
私は」私はビルドversioning.gradleを作成しました受け取る:
Error:Could not find method getVersionNameFromTag() for arguments [] on ProductFlavor_Decorated{name=main, dimension=null, minSdkVersion=DefaultApiVersion{mApiLevel=17, mCodename='null'}, targetSdkVersion=DefaultApiVersion{mApiLevel=24, mCodename='null'}, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptSupportModeBlasEnabled=null, renderscriptNdkModeEnabled=null, versionCode=157, versionName=null, applicationId=ae.propertyfinder, testApplicationId=null, testInstrumentationRunner=android.support.test.runner.AndroidJUnitRunner, testInstrumentationRunnerArguments={}, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}} of type com.android.build.gradle.internal.dsl.ProductFlavor.
gと同じetNewBuildCode。 これを解決するには?
これです!ありがとう –