New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Android data binding support #2694

Open
gregestren opened this Issue Mar 16, 2017 · 13 comments

Comments

Projects
None yet
6 participants
@gregestren
Copy link
Contributor

gregestren commented Mar 16, 2017

Bazel already has internal support for Android data binding (e.g. here). But hooks haven't been exposed to link this to the SDK support libraries or toggle the feature on for android_binary / android_library rules.

This bug tracks the effort to make data binding end-user usable.

@gregestren

This comment has been minimized.

@gregestren

This comment has been minimized.

Copy link
Contributor

gregestren commented Apr 4, 2017

Update: we're making internal progress on this change and can start exposing further hooks in Bazel likely over the next week. This still won't be functional though without having the data binding libraries checked into appropriate places in your repo.

Anyone interested in experimenting with this earlier, and willing to play around with checking in the data binding libraries themselves, report here and we're glad to work through the process with you.

bazel-io pushed a commit that referenced this issue Apr 13, 2017

Make Android data binding rules explicitly depend on the runtime libr…
…ary.

Before this change Bazel was adding this implicitly. But that wasn't
working properly with --incremental_dexing. And that implementation is a
lot messier and bug-prone vs. just including it as a standard dependency.

Issue: #2694
PiperOrigin-RevId: 152956638

bazel-io pushed a commit that referenced this issue Apr 18, 2017

Expose Bazel's Android data binding support to users.
The logic is already in Bazel but wasn't available to build rules.
This change makes it available, but still requires data binding's
{build|run}time libraries to be checked into appropriate depot
spots for everything to work.

Followup changes will make those libraries easily available.

Issue: #2694
PiperOrigin-RevId: 153359861
@aj-michael

This comment has been minimized.

Copy link
Contributor

aj-michael commented Apr 20, 2017

Update: After a discussion with @gregestren we've determined that we need to update the aar_import rule to handle the databinding metadata files that are included in the com.android.databinding:adapters:1.3.*:aar libraries.

bazel-io pushed a commit that referenced this issue Apr 24, 2017

Update databinding exec.jar to 2.3.1.
#2694

Change-Id: I33e1c1a6c1f1c4b31227eb26b0deed09525a7ec7

bazel-io pushed a commit that referenced this issue Nov 16, 2017

Build databinding annotation processor in host configuration.
Also, add a fake databinding processor target.

Bazel users will need to do something like this:

# WORKSPACE
local_repository(
    name = "databinding",
    path = "./databinding",
)
bind(
    name = "databinding_annotation_processor",
    actual = "@databinding//:annotation_processor",
)

# databinding/BUILD
java_plugin(
    name = "annotation_processor",
    ...
)
...

#2694

RELNOTES: None
PiperOrigin-RevId: 175975110

duggelz pushed a commit to duggelz/bazel that referenced this issue Dec 15, 2017

Build databinding annotation processor in host configuration.
Also, add a fake databinding processor target.

Bazel users will need to do something like this:

# WORKSPACE
local_repository(
    name = "databinding",
    path = "./databinding",
)
bind(
    name = "databinding_annotation_processor",
    actual = "@databinding//:annotation_processor",
)

# databinding/BUILD
java_plugin(
    name = "annotation_processor",
    ...
)
...

bazelbuild#2694

RELNOTES: None
PiperOrigin-RevId: 175975110

@jin jin added the P2 label Jun 15, 2018

@Pmcneice

This comment has been minimized.

Copy link

Pmcneice commented Jul 22, 2018

It looks like there has been various commits in relation to this issue since the last comment - just wondering how close we are to having databinding support up and running?

@jin

This comment has been minimized.

Copy link
Member

jin commented Jul 22, 2018

@gregestren gregestren assigned ahumesky and unassigned gregestren Jul 23, 2018

@gregestren

This comment has been minimized.

Copy link
Contributor

gregestren commented Jul 23, 2018

Paul,

As Jin referenced above, @ahumesky is the current point of contact for data binding support. He's working through a number of technical issues about it at the moment and can give you the clearest expectations.

@ahumesky

This comment has been minimized.

Copy link
Contributor

ahumesky commented Jul 23, 2018

We're working to upgrade databinding in bazel to the latest version to support androidx / jetpack, as well as make depending on databinding easier. We've also found some bugs with databinding + android_instrumentation_test. We hope to have these issues sorted out in the next couple of weeks.

@Pmcneice

This comment has been minimized.

Copy link

Pmcneice commented Sep 17, 2018

Hey @ahumesky, any update on the status of this?

@ahumesky

This comment has been minimized.

Copy link
Contributor

ahumesky commented Sep 17, 2018

This was interrupted by a few little urgent issues, but those are done and we're back to work on this. I hope to have v2 working this week, then I plan to make getting the databinding dependencies working with the android rules easier (today you have to manually wire up the databinding dependencies).

@codesuki

This comment has been minimized.

Copy link

codesuki commented Nov 8, 2018

Hey, I am trying to convert a project to Bazel using databindings. Is there any progress on this? Even a hacky workaround would help me a lot until it's officially working.
When enabling databinding on android_binary Bazel crashes with NPE.

@ahumesky

This comment has been minimized.

Copy link
Contributor

ahumesky commented Nov 8, 2018

There has been significant progress, I have databinding v2 working, and I'm in the process of getting all the code reviewed and submitted. Should be in in the next couple of days.

You're seeing an NPE probably because the databinding dependencies need to be added to the rules with databinding enabled (it shouldn't give an NPE for that though, that's a bug in itself). I'm also working to make getting the databinding dependencies easier. The main problem right now is that our gmaven repo for android dependencies is incomplete (databinding depends on things that are hosted outside gmaven). It would be better to use something like bazel-deps to generate the rules for these dependencies, but bazel-deps does not support AARs.

@codesuki

This comment has been minimized.

Copy link

codesuki commented Nov 8, 2018

Thanks for the update. That sounds good!

I tried adding

aar_import(
    name = “library-1.3.1”,
    aar = “@androidsdk//:extras/android/m2repository/com/android/databinding/library/1.3.1/library-1.3.1.aar”,
)

As a dependency but it had no effect. Probably it's wrong anyway.

Do you have a sample on how to add the dependency correctly? I could adapt that to my local installation. Right now I don't even know which library is the correct one. And the only one I found is the one in the SDK.
😅

@codesuki

This comment has been minimized.

Copy link

codesuki commented Nov 8, 2018

This is the NPE when setting enable_data_binding = True .
Bazel versions 0.15.2 and 0.18.1.

Internal error thrown during build. Printing stack trace: java.lang.RuntimeException: Unrecoverable error while evaluating node '//:app BuildConfigurationValue.Key[c46469ce7e7c9c01ec016ebdb5b40fd0] false' (requested by nodes )
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:495)
	at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:368)
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.execLocalTasks(ForkJoinPool.java:1040)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1058)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.NullPointerException
	at com.google.devtools.build.lib.rules.java.JavaCompilationHelper.usesAnnotationProcessing(JavaCompilationHelper.java:465)
	at com.google.devtools.build.lib.rules.android.AndroidCommon.initJava(AndroidCommon.java:606)
	at com.google.devtools.build.lib.rules.android.AndroidCommon.init(AndroidCommon.java:540)
	at com.google.devtools.build.lib.rules.android.AndroidBinary.init(AndroidBinary.java:251)
	at com.google.devtools.build.lib.rules.android.AndroidBinary.create(AndroidBinary.java:119)
	at com.google.devtools.build.lib.rules.android.AndroidBinary.create(AndroidBinary.java:95)
	at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createRule(ConfiguredTargetFactory.java:319)
	at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createConfiguredTarget(ConfiguredTargetFactory.java:205)
	at com.google.devtools.build.lib.skyframe.SkyframeBuildView.createConfiguredTarget(SkyframeBuildView.java:635)
	at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.createConfiguredTarget(ConfiguredTargetFunction.java:777)
	at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.compute(ConfiguredTargetFunction.java:323)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:418)
	... 7 more

https://github.com/bazelbuild/bazel/blob/0.18.1/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java#L463

I tried setting javacopts to include -processor just to see if the NPE goes away but nothing changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment