8
7

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.

AndroidなbazelでNo resource identifier found for attributeで怒られたときの対処法

Posted at

bazel version

henteko@~ $ bazel version
Build label: 0.1.1
Build target: bazel-out/local_darwin-fastbuild/bin/src/main/java/bazel-main_deploy.jar
Build time: Thu Oct 15 20:51:11 2015 (1444942271)
Build timestamp: 1444942271
Build timestamp as int: 1444942271

本題

bazelでAndroidなプロジェクトをビルドしようとしたときに以下のようなエラーで怒られることがあります

No resource identifier found for attribute 'layout_behavior' in package

bazelの場合

この例の場合だと、Android Supportライブラリのdesignが不足しているのでbazelでこのライブラリを読み込んであげることで解消されます

java_import(
  name = "support_design_import",
  jars = ["android-sdk/extras/android/support/design/libs/android-support-design.jar"],
)

android_library(
  name = "support_design",
  custom_package = "android.support.design",
  manifest = "android-sdk/extras/android/support/design/AndroidManifest.xml",
  resource_files = glob(["android-sdk/extras/android/support/design/res/**"]),
  deps = [":support_design_import",  "//external:android/appcompat_v7"],
)

ちなみにここのandroid-sdkはローカルのAndroid SDKに対するsymlinkを、BUILDファイルと同フォルダに作成してます

あとはこの**"support_design"**をandroid_binaryのdepsで読み込んであげるだけです

android_binary(
  name = "android",
  custom_package = "com.henteko07.sample",
  srcs = glob(["android/app/src/main/java/**/*.java"]),
  manifest = "android/app/src/main/AndroidManifest.xml",
  resource_files = glob(["android/app/src/main/res/**"]),
  deps = ["//external:android/appcompat_v4", "//external:android/appcompat_v7", "support_design"]
)

まとめ

bazelでは

  • java_importでjarファイルを読み込み
  • android_libraryでソースコードなどの読み込み

を行うことでandroid_binaryのdepsで使用可能になります
他のライブラリが必要な場合も同じような手順で追加可能だと思います

gradleの場合

ちなみに、gradleだとbuild.gradleに以下を記述するとエラーが解消されます

dependencies {
  compile 'com.android.support:design:23.0.1'
}
8
7
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
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?