-1

I need to create an android library that will also contains layout that uses data binding.
I've managed to get the library and the containing app works, but as soon as I try to enable obfuscation (minifyEnabled true) I'm getting:

Cannot resolve type for {variable name}

This is reasonable because my variable type was changed during proguard processing.
I tried to make my resources private by declaring some of them public on the public.xml, but this doesn't help.

Can it be done in anyway?

Sergei Bubenshchikov
  • 5,275
  • 3
  • 33
  • 60
Raven
  • 39
  • 2
  • 7

1 Answers1

1

but as soon as I try to enable obfuscation

You must exclude your model classes members from being obfuscated by ProGuard by adjusting its config file (usually proguard-rules.pro, if not, check your build.gradle file for reference) in your project/module.

EDIT

but I'm trying to keep my data model hidden so the one using my library won't be able to use them

Then you must not use data binding as it needs to get the data from your model object so it simply must be public.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • Thanks, but I'm trying to keep my data model hidden so the one using my library won't be able to use them, so the preferred way for me is to make my layout private. – Raven Mar 07 '17 at 06:01
  • The solution I'm looking for, if possible, is to make the layouts only accessible from my library. in this way, my library knows the data module, and others can't. The problem is that the resources are bundle on the AAR as is, and can be access from all containing projects. this is why I mentioned the _public.xml_ in a way of making your resources private. – Raven Mar 07 '17 at 09:06
  • You cannot have this unless you write all these libs incl. inflater and databinding yourself. Using Android provider components comes with some requirements and that means model must expose members you want to data-bind to. Also layout files are also reachable from other's code using your library. Still I see no problem - if someone uses things that are not in public api of your library then it his problem. why bother? – Marcin Orlowski Mar 07 '17 at 10:08