4

** See edit below **

I built a multi-library project and published it to a private repository on jitpack.io successfully. Some of the libraries contain resources in the form of layout files, etc. I have another project that implements these libraries and builds fine, but when I try to run it, I keep getting an error regarding attributes in some of the layout and navigation files (from the libraries):

For instance, I'm loading a layout file called fragment_radio_main that is imported from com.github.username.libraryname:radio:version. In that layout, I have a RecyclerView which uses the attribute app:layoutManager. This is where the failure is happening

AAPT: error: attribute layoutManager (aka com.organization.appname:layoutManager) not found.
AAPT: error: attribute sc_border_width (aka com.organization.appname:sc_border_width) not found.
AAPT: error: attribute sc_corner_radius (aka com.organization.appname:sc_corner_radius) not found.
AAPT: error: attribute sc_tint_color (aka com.organization.appname:sc_tint_color) not found.
AAPT: error: attribute defaultNavHost (aka com.organization.appname:defaultNavHost) not found.

In the above logs, layoutManager was from RecyclerView, the attributes with the prefix sc_* are from a 3rd party library that one of my layouts uses, and defaultNavHost is from NavHostFragment from the Navigation library. There are many more attributes that are failing, but I believe this gets the point across.

In the aka line(aka com.organization.appname:sc_tint_color), the attribute sc_tint_color is not actually an attribute defined by com.organization.appname, but rather, defined by a 3rd party. Maybe there's some configuration that needs to happen to resolve these attributes? I'm just stuck on this.

If you need further info, I'd be glad to provide. Any help would be greatly appreciated.

** EDIT 11/27/2019 **

It turns out that, if I import my Radio library to my current project, I also have to add any 3rd party dependencies my Radio library used that contain resource (specifically, in this case, styleable) files in my current project to gain access to those attributes.

So I guess my question is, does anyone know how to avoid having to do this?

James B
  • 447
  • 3
  • 15

1 Answers1

0

Just add the dependency inside the library as api instead of implementation. Then you'll have it available in the module which references it, without the need to duplicate these dependencies.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • 1
    Your general answer does not fit this issue. We have done this, but the problem exists. So there will be other reasons behind it. – Emad Razavi Nov 02 '20 at 09:48
  • Just don't use `com.github.username.libraryname:radio:version` but a local version... and my answer well fits the issue, because it is all about the `build.gradle` of that library project - and when using a pre-built version, this means not being able to change it. – Martin Zeitler Nov 02 '20 at 13:46
  • As I realized from your answer, you say not to use the real dependency from the remote dependency repo and grab the whole project into our project. That is not the correct answer because we are not fixing the issue but changing the question. The issue is having XML related errors while working with third-party repositories and using api dependency. – Emad Razavi Nov 02 '20 at 16:32
  • Martin, can you clarify your answer? I tried using `api` and still had the same issue. I am also using a local .aar file that I imported. – Jeff Padgett Jan 12 '21 at 17:47
  • @JeffPadgett The Gradle docs explain the difference in visibility... another possible cause might be to have built JAR instead of AAR (which has Android resources). – Martin Zeitler Jan 12 '21 at 18:09
  • Yeah I'm definitely using .aar, and definitely had been using `api` instead of `implementation`. Let me know if you have any other thoughts. Thanks. – Jeff Padgett Jan 12 '21 at 20:19
  • Library resources can also become private, when only one another is declared as public: https://developer.android.com/studio/projects/android-library#PrivateResources ...I'd probably check if these even had been packaged and within which access scope. – Martin Zeitler Jan 12 '21 at 23:06