LoginSignup
24
22

More than 5 years have passed since last update.

Android library projectでBuild.DEBUGを使うtips

Last updated at Posted at 2015-05-10

2016/1/17 追記: この記事はobsoleteです。ライブラリ付属のサンプルアプリならこの方法でいいですが、実際のライブラリでこれをするとdebug buildとrelease buildのアーティファクトが2つ出来てしまい、dependenciesで非常に扱いづらくなります。

Androidでライブラリモジュールからアプリケーションのdebuggableフラグを参照する をおすすめします。


元ネタ: android - BuildConfig.DEBUG always false when building library projects with gradle - Stack Overflow

Android library projectでは Build.DEBUG が常にfalseになります。リリース版アーティファクトはこれでいいのですが、同梱するサンプルアプリでも常にそうなってしまうので、 Build.DEBUG でログを有効にする手法が使えません。

上記stackoverflowエントリによると、Android Gradle Plugin 1.1から以下の設定をすることで、同梱するサンプルアプリから見える BuildConfig.DEBUG がtrueになるとのことで、実際にやってみたところ確かに有効だったのでメモっておきます。

// in the library project
android {
    // ...
    publishNonDefault true
}
// in example apps
dependencies {
    compile project(path: ':library', configuration: 'debug')
}
24
22
0

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
24
22