1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

build.gradleでcommit logを取得してたりする時にハマった話

Last updated at Posted at 2017-03-06

デバッグモードのアプリとかで最後のコミットの内容をアプリ内でも分かるようにするためとかに下記のようにbuild.gradleに書いてたりしますが、コミットコメントのダブルクォートのせいでbuildができない事案にぶち当たったので残しておきます。

昨今、aptやらkaptやらDataBindingやら使ってると謎エラーにやられることが多いのですが、今回これにやられましたorz

最新のコミットのログがRevert "Fix hoge"の場合

before

buildで死ぬ

build.gradle
def getCommitLog() {
    final String commitLog = 'git log -n 1 --oneline'.execute().text
    return commitLog
}

android {
  buildTypes {	
    debug {
      debuggable true
      buildConfigField "String", "COMMIT_LOG", "\"${getCommitLog()}\""
    }
  }
}

after

buildで死なない

build.gradle
def getCommitLog() {
    final String commitLog = 'git log -n 1 --oneline | sed "s/\"/'/g"'.execute().text
    return commitLog
}

android {
  buildTypes {	
    debug {
      debuggable true
      buildConfigField "String", "COMMIT_LOG", "\"${getCommitLog()}\""
    }
  }
}

以上です。

1
3
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?