我正在研究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(没有 support-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'\1', 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'\1', 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'\1', 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,
)