bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
22.97k stars 4.03k forks source link

AarImport does not import databinding package from aars leading to runtime crash. #13640

Open arunkumar9t2 opened 3 years ago

arunkumar9t2 commented 3 years ago

Description of the problem / feature request:

When using aars via aar import, currently databinding package is not extracted and given to DatabindingV2Provider. This causes direct dependency pkgs to not have the package name and at runtime DatabindingMapper fails to find the Binding class.

Feature requests: what underlying problem are you trying to solve with this feature?

Runtime crash when consuming aar that contains databinding generated Binding classes.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

  1. Create an AAR that has a layout xml file with databinding enabled
  2. Import the AAR into project and launch any screen that using the AAR layout's Binding class.
  3. Observe runtime crash.
java.lang.IllegalStateException: DataBindingUtil.inflate(…layout, container, false) must not be null

What operating system are you running Bazel on?

MacOs Catalina 10.15.7

What's the output of bazel info release?

release 4.1.0

If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.

NA

What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

NA

Related info

According to this, the package name should be extracted from -br.bin file instead of the one from AndroidManifest.xml.

Related #2694

arunkumar9t2 commented 3 years ago

Repro project:

databindingstrictdeps.zip

bazelisk build //app
./gradlew app:assembleDebug

Gradle generated DatabindingMapperImpl has correct packages imported from dependency. For example

  @Override
  public List<DataBinderMapper> collectDependencies() {
    ArrayList<DataBinderMapper> result = new ArrayList<DataBinderMapper>(1);
    result.add(new androidx.databinding.library.baseAdapters.DataBinderMapperImpl());
    return result;
  }

Bazel generated

  @Override
  public List<DataBinderMapper> collectDependencies() {
    ArrayList<DataBinderMapper> result = new ArrayList<DataBinderMapper>(1);
    result.add(new DataBinderMapperImpl());
    return result;
  }

Notice androidx.databinding.library.baseAdapters.DataBinderMapperImpl() is missing on Bazel generated file. This causes java.lang.IllegalStateException: DataBindingUtil.inflate(…layout, container, false) must not be null at runtime.

arunkumar9t2 commented 2 years ago

hi @ahumesky I am willing to work on this but I am stuck. It seems the package needs to be passed to provider here, we could compute it by inspecting the aar in an action, however I am not sure how to pass result of an action to a provider.

According to databinding implementation the package name must be extracted by -br.bin file inside the aar.

Any thoughts appreciated.