为什么Buck AntennaPod示例中没有添加android-support-v4.jar?

Why Is android-support-v4.jar Not Added In Buck AntennaPod Example?

我正在研究 AntennaPod 并查看它如何构建 submodules 文件夹。

有一个 jar 文件 android-support-v4.jar 是该项目的一部分。

我在代码中没有看到实际添加此 .jar 的任何地方。我也没有在 buck-out/bin 文件夹中看到它。

这是 android_library 步骤:

android_library(
  name = 'dslv-lib',
  srcs = glob(['submodules/dslv/library/src/**/*.java']),
  deps = [
    ':all-jars',
    ':dslv-res',
  ],
)

我看到它正在获取 java 文件,这取决于 all-jars 和 dslv-res 规则。但是 all-jars 只抓取 libs 文件夹中的 jars(不支持-v4.jar)。

我的问题是: 为什么这个 android-support-v4.jar 没有被添加(或者我遗漏了什么),添加它的构建规则是什么?

来自 Buck 示例的完整 AntennaPod 代码如下:

import re

jar_deps = []
for jarfile in glob(['libs/*.jar']):
  name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'', jarfile)
  jar_deps.append(':' + name)
  prebuilt_jar(
    name = name,
    binary_jar = jarfile,
  )

android_library(
  name = 'all-jars',
  exported_deps = jar_deps,
)

presto_gen_aidls = []
for aidlfile in glob(['src/com/aocate/presto/service/*.aidl']):
  name = 'presto_aidls__' + re.sub(r'^.*/([^/]+)\.aidl$', r'', aidlfile)
  presto_gen_aidls.append(':' + name)
  gen_aidl(
    name = name,
    aidl = aidlfile,
    import_path = 'src',
  )

android_library(
  name = 'presto-aidls',
  srcs = presto_gen_aidls,
)


android_build_config(
  name = 'build-config',
  package = 'de.danoeh.antennapod',
)

APP_CLASS_SOURCE = 'src/de/danoeh/antennapod/AppShell.java'

android_library(
  name = 'main-lib',
  srcs = glob(['src/de/danoeh/antennapod/**/*.java'], excludes = [APP_CLASS_SOURCE]),
  deps = [
    ':all-jars',
    ':dslv-lib',
    ':presto-lib',
    ':appcompat',
    ':build-config',
    ':res',
  ],
)

android_library(
  name = 'application-lib',
  srcs = [APP_CLASS_SOURCE],
  deps = [
    ':build-config',
    ':jars__buck-android-support',
  ],
)

android_resource(
  name = 'res',
  package = 'de.danoeh.antennapod',
  res = 'res',
  assets = 'assets',
  deps = [
    ':appcompat',
    ':dslv-res',
  ]
)

android_library(
  name = 'dslv-lib',
  srcs = glob(['submodules/dslv/library/src/**/*.java']),
  deps = [
    ':all-jars',
    ':dslv-res',
  ],
)

android_resource(
  name = 'dslv-res',
  package = 'com.mobeta.android.dslv',
  res = 'submodules/dslv/library/res',
  deps = [
  ]
)

android_library(
  name = 'presto-lib',
  srcs = glob(['src/com/aocate/**/*.java']),
  deps = [
    ':presto-aidls',
    ':all-jars',
  ],
)

android_manifest(
  name = 'manifest',
  skeleton = 'AndroidManifest.xml',
  deps = [
    ':main-lib',
  ],
)

keystore(
  name = 'debug_keystore',
  store = 'keystore/debug.keystore',
  properties = 'keystore/debug.keystore.properties',
)

android_binary(
  name = 'antennapod',
  manifest = ':manifest',
  keystore = ':debug_keystore',
  use_split_dex = True,
  exopackage = True,
  primary_dex_patterns = [
    '^de/danoeh/antennapod/AppShell^',
    '^de/danoeh/antennapod/BuildConfig^',
    '^com/facebook/buck/android/support/exopackage/'
  ],
  deps = [
    ':main-lib',
    ':application-lib',
  ],
)


android_prebuilt_aar(
  name = 'appcompat',
  aar = 'libs/appcompat-v7-19.1.0.aar',
)

更新

这是我要实现的库项目。

这里是库项目中的Buck文件

prebuilt_jar(
  name = 'android-support-v4',
  binary_jar = 'android-support-v4.jar',
  visibility = [
    'PUBLIC',
  ],
)

prebuilt_jar(
  name = 'bolts',
  binary_jar = 'bolts.jar',
  visibility = [
    'PUBLIC',
  ],
)

这是我尝试过的最佳构建规则。

### com.phonegap.plugins.facebook

android_library(
  name = 'facebook-plugin-java',
  srcs = glob(['com.phonegap.plugins.facebookconnect/app-FacebookLib/src/**/*.java']),
)

android_resource(
  name = 'facebook-plugin-res',
  package = 'com.facebook',
  res = 'com.phonegap.plugins.facebookconnect/app-FacebookLib/res',
)

facebook_plugin_jar_deps = []
for jarfile in glob(['com.phonegap.plugins.facebookconnect/app-FacebookLib/libs/*.jar']):
  name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'', jarfile)
  facebook_plugin_jar_deps.append(':' + name)
  prebuilt_jar(
    name = name,
    binary_jar = jarfile,
  )

android_library(
  name = 'facebook-plugin-jars',
  exported_deps = facebook_plugin_jar_deps,
)

在那个 BUCK 文件中,一个 prebuilt_jar rule is created for each .jar file Buck finds under lib/. We add support-v4-19.1.0.jar under that folder in this commit。这在 //:all-jars 构建目标中被引用为 exported_dep//:dslv-lib 构建目标依赖于 //:all-jars,因此它最终成为 IntelliJ 中显示的依赖项。