Git Product home page Git Product logo

Comments (9)

jin avatar jin commented on September 23, 2024 1

#97 is in. With v2.0.1, you can mark the javapoet as neverlink, which should prevent the min-sdk issue. However, the issue with Epoxy's annotation processor not running still stands.

from rules_jvm_external.

jin avatar jin commented on September 23, 2024

Have you tried adding generates_api = 1 to the java_plugin target?

Nevermind, just tried it, it doesn't work.

from rules_jvm_external.

jin avatar jin commented on September 23, 2024

I got slightly further by adding com.airbnb:epoxy-processor:3.3.1 to maven_install and @maven//:com_airbnb_epoxy_processor to the deps of the java_plugin target. The BUILD file looks like this:

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

java_plugin(
    name = "epoxy_plugin",
    processor_class = "com.airbnb.epoxy.EpoxyProcessor",
    generates_api = 1,
    deps = [
        "@maven//:com_airbnb_android_epoxy_processor",
    ],
)

java_library(
    name = "epoxy_lib",
    exported_plugins = ["epoxy_plugin"],
    exports = [
        "@maven//:com_airbnb_android_epoxy",
        "@maven//:com_airbnb_android_epoxy_processor",
        "@maven//:com_airbnb_android_epoxy_annotations",
    ]
)

android_library(
    name = "resources",
    manifest = "AndroidManifest.xml",
    custom_package = "com.matthewcheok.bazeltest",
    resource_files = glob(
        ["res/**"], 
        exclude=["res/.DS_Store"]
    ),
    deps = [
        "@maven//:androidx_appcompat_appcompat",
        "@maven//:androidx_constraintlayout_constraintlayout",
    ],
)


kt_android_library(
    name = "lib",
    srcs = glob(["java/**/*.kt"]),
    custom_package = "com.matthewcheok.bazeltest",
    plugins = [":epoxy_plugin"],
    deps = [
        ":resources",
        ":epoxy_lib",
        "@maven//:androidx_constraintlayout_constraintlayout",
        "@maven//:androidx_annotation_annotation",
        "@maven//:androidx_appcompat_appcompat",
        "@maven//:androidx_core_core",
        "@maven//:androidx_core_core_ktx",
        "@maven//:androidx_drawerlayout_drawerlayout",
        "@maven//:androidx_lifecycle_lifecycle_common",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel",
        "@maven//:androidx_fragment_fragment",
        "@maven//:androidx_recyclerview_recyclerview", 
    ],
    visibility = ["//visibility:public"],
)

I'm now running into an SDK error with javapoet:

ERROR: /private/var/tmp/_bazel_jin/54321455f30132f9d0deb1ed5ef71a3e/external/maven/BUILD:798:1: Dexing external/maven/_dx/com_squareup_javapoet_1_11_1/javapoet-1.11.1.jar_desugared.jar with applicable dexopts [] failed (Exit 1)
java.util.concurrent.ExecutionException: com.android.dx.cf.code.SimException: ERROR in com.squareup.javapoet.CodeBlock.joining:(Ljava/lang/String;)Ljava/util/stream/Collector;: invoking a static interface method java.util.stream.Collector.of:(Ljava/util/function/Supplier;Ljava/util/function/BiConsumer;Ljava/util/function/BinaryOperator;Ljava/util/function/Function;[Ljava/util/stream/Collector$Characteristics;)Ljava/util/stream/Collector; strictly requires --min-sdk-version >= 24 (blocked at current API level 13)
	at java.base/java.util.concurrent.FutureTask.report(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.get(Unknown Source)
	at com.google.devtools.build.android.dexer.DexBuilder.produceDexArchive(DexBuilder.java:253)
	at com.google.devtools.build.android.dexer.DexBuilder.processRequest(DexBuilder.java:218)
	at com.google.devtools.build.android.dexer.DexBuilder.runPersistentWorker(DexBuilder.java:173)
	at com.google.devtools.build.android.dexer.DexBuilder.main(DexBuilder.java:121)
Caused by: com.android.dx.cf.code.SimException: ERROR in com.squareup.javapoet.CodeBlock.joining:(Ljava/lang/String;)Ljava/util/stream/Collector;: invoking a static interface method java.util.stream.Collector.of:(Ljava/util/function/Supplier;Ljava/util/function/BiConsumer;Ljava/util/function/BinaryOperator;Ljava/util/function/Function;[Ljava/util/stream/Collector$Characteristics;)Ljava/util/stream/Collector; strictly requires --min-sdk-version >= 24 (blocked at current API level 13)
	at com.android.dx.cf.code.Simulator.fail(Simulator.java:947)
	at com.android.dx.cf.code.Simulator.checkInvokeInterfaceSupported(Simulator.java:917)
	at com.android.dx.cf.code.Simulator.access$500(Simulator.java:43)
	at com.android.dx.cf.code.Simulator$SimVisitor.visitConstant(Simulator.java:687)
	at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:764)
	at com.android.dx.cf.code.Simulator.simulate(Simulator.java:117)
	at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:789)
	at com.android.dx.cf.code.Ropper.doit(Ropper.java:744)
	at com.android.dx.cf.code.Ropper.convert(Ropper.java:349)
	at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:309)
	at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:150)
	at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:102)
	at com.google.devtools.build.android.dexer.Dexing.addToDexFile(Dexing.java:198)
	at com.google.devtools.build.android.dexer.DexConverter.toDexFile(DexConverter.java:31)
	at com.google.devtools.build.android.dexer.DexConversionEnqueuer$ClassToDex.call(DexConversionEnqueuer.java:173)
	at com.google.devtools.build.android.dexer.DexConversionEnqueuer$ClassToDex.call(DexConversionEnqueuer.java:156)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Target //:bazel_test failed to build

from rules_jvm_external.

matthewcheok avatar matthewcheok commented on September 23, 2024

It looks like we need to specify a min SDK version. But I'm not sure where we might do that.

from rules_jvm_external.

jin avatar jin commented on September 23, 2024

Usually dex options go into android_binary's dexopts attribute. However, this seems like a bug because javapoet isn't supposed to go into the APK, let alone getting dexed and desugared. JakeWharton/butterknife#1234 (comment)

I think we'll need a way to specify neverlink on specific dependencies in the tree to avoid bringing artifacts like javapoet into the runtime classpath.

from rules_jvm_external.

jin avatar jin commented on September 23, 2024

Just an update: the dexopt issue will be fixed by #97 by marking the javapoet artifact as neverlink = True. I was able to reproduce the epoxy failures, but I believe this is due to an issue in the kt_android_library rule. I tried to use the Room annotation processor as well, and it worked on a regular android_library with Java sources, but not kt_android_library.

from rules_jvm_external.

jin avatar jin commented on September 23, 2024

I don't have bandwidth to work on this at the moment, may pick it up when the new Kotlin rules are released.

from rules_jvm_external.

fisheye-123 avatar fisheye-123 commented on September 23, 2024

Any update? I have same issue that bazel + Kotlin + epoxy not working

from rules_jvm_external.

clewis-turner avatar clewis-turner commented on September 23, 2024

We have been able to build our application with Bazel + Kotlin + epoxy using the following configuration:

WORKSPACE:
primary maven_install:

"com.airbnb.android:epoxy:3.9.0",
"com.airbnb.android:epoxy-processor:3.9.0",
"com.airbnb.android:epoxy-annotations:3.9.0",
"com.squareup.kotlinpoet.1.5.0",
"com.squareup.javapoet.1.13.0",

secondary maven_install:

maven_install(
    name = "jetify",
    artifacts = [
        "com.google.android.material:material:1.1.0",
        ...
    ],
    jetify = True,
    excluded_artifacts = [
        "com.android.support:*",
    ],
    repositories = [
        ...
    ],
)

BUILD:

java_library(
    name = "epoxy_compiler",
    exported_plugins = [
        ":epoxy_plugin",
    ],
    visibility = [
        "//visibility:public",
    ],
)

java_plugin(
    name = "epoxy_plugin",
    generates_api = 1,
    processor_class = "com.airbnb.epoxy.EpoxyProcessor",
    deps = [
        "@maven//:com_airbnb_android_epoxy",
        "@maven//:com_airbnb_android_epoxy_processor",
        "@maven//:com_airbnb_android_epoxy_annotations",
    ],
)

kt_android_library (
  ...
  deps = [
     ...
    ":epoxy_compiler",
    "@maven//:com_airbnb_android_epoxy",
    "@maven//:com_airbnb_android_epoxy_processor",
    "@maven//:com_squareup_javapoet",
    "@maven//:com_squareup_kotlinpoet",
    "@jetify//:com_google_android_material_material",

   ]
) 

We shouldn't need that visibility reference. As you can see, we also do not seem to need to include neverlink for javapoet and kotlinpoet. We also needed to exclude the Google material library from our primary install and utilize a jetified version.

Good luck, hope this helps!

from rules_jvm_external.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.