如何使用 Dagger & Butterknife 设置 Buck?
How do I set up Buck with Dagger & Butterknife?
各位开发者大家好,
我正在尝试从 Gradle 切换到 Buck,但在使用 Dagger 和 Butterknife 进行设置时遇到问题,因为它们需要注释处理。
我找到了一些链接和教程,但它们已经有几年(~4)年了,我认为可能会有一些更新的方法来做事。
这是我已经看过的:
https://github.com/ryan-endacott/android-buck-dagger-starter
提前致谢,
帕特里克
Buck 支持对基于 Java 的规则(包括 android_library
)进行注释处理。看一看在 buck 仓库中如何使用 Immutables (link to source code):
- 首先,您需要声明库 jar:
java_library(
name = "immutables",
exported_deps = [
":builder",
":value",
],
visibility = [
"PUBLIC",
],
)
prebuilt_jar(
name = "value",
binary_jar = "value-2.5.6.jar",
source_jar = "value-2.5.6-sources.jar",
licenses = [
"COPYING",
],
)
prebuilt_jar(
name = "builder",
binary_jar = "builder-2.5.6.jar",
source_jar = "builder-2.5.6-sources.jar",
licenses = [
"COPYING",
],
)
- 定义注释处理器:
java_annotation_processor(
name = "processor",
isolate_class_loader = True,
processor_class = "org.immutables.value.internal.$processor$.$Processor",
visibility = [
"PUBLIC",
],
deps = [
":immutables",
],
)
- 然后您可以将此注释处理器添加到目标的插件列表中:
java_library(
name = "target",
plugins = [
"//third-party/java/immutables:processor",
],
deps = [
...
],
...
)
Buck 存储库 contains 添加此注释处理器的自定义规则 (java_immutables_library
),以便开发人员无需在每个目标上指定插件。您或许可以使用类似的方法。
各位开发者大家好,
我正在尝试从 Gradle 切换到 Buck,但在使用 Dagger 和 Butterknife 进行设置时遇到问题,因为它们需要注释处理。
我找到了一些链接和教程,但它们已经有几年(~4)年了,我认为可能会有一些更新的方法来做事。
这是我已经看过的: https://github.com/ryan-endacott/android-buck-dagger-starter
提前致谢, 帕特里克
Buck 支持对基于 Java 的规则(包括 android_library
)进行注释处理。看一看在 buck 仓库中如何使用 Immutables (link to source code):
- 首先,您需要声明库 jar:
java_library( name = "immutables", exported_deps = [ ":builder", ":value", ], visibility = [ "PUBLIC", ], ) prebuilt_jar( name = "value", binary_jar = "value-2.5.6.jar", source_jar = "value-2.5.6-sources.jar", licenses = [ "COPYING", ], ) prebuilt_jar( name = "builder", binary_jar = "builder-2.5.6.jar", source_jar = "builder-2.5.6-sources.jar", licenses = [ "COPYING", ], )
- 定义注释处理器:
java_annotation_processor( name = "processor", isolate_class_loader = True, processor_class = "org.immutables.value.internal.$processor$.$Processor", visibility = [ "PUBLIC", ], deps = [ ":immutables", ], )
- 然后您可以将此注释处理器添加到目标的插件列表中:
java_library( name = "target", plugins = [ "//third-party/java/immutables:processor", ], deps = [ ... ], ... )
Buck 存储库 contains 添加此注释处理器的自定义规则 (java_immutables_library
),以便开发人员无需在每个目标上指定插件。您或许可以使用类似的方法。