** 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?
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.
Related
The issue occur when I upgrade to androidX.
I have removed all the custom font and style which are used in the project.
Also remove and change the .xml files used for different shapes.
look for the 'iconSize' attribute in your project in res/values/values.xml
it says there are duplicate values for this 'iconSize' attribute,
delete one of them
I am using actionbarsherlock library in my android app and I am using one of its style attribute with the name of popupPromptView but when I try to generate the apk for my app, it gives me this error:
C:\Users\My Username\.gradle\caches\transforms-2\files-2.1\fa481916e694bf5a6973eb98ad535c2d\jetified-actionbarsherlock-4.4.0\res\values\values.xml:268:5-296:25: AAPT: error: resource android:attr/popupPromptView is private.
I tried going to this values.xml file and comment out this style attribute but when I try to generate the apk again, that line which I commented comes back again. I don't know what's wrong. I have even tried deleting the cache folder of .gradle but still no luck.
I had the same problem
You can solve downloading Sherlock as a module itself to compile together with your project (I imported the Sherlock modules from a Eclipse project) instead of using a library reference
In this way you can remove that line in a definitive way
it made my day
https://developer.android.com/studio/command-line/aapt2
In previous versions of AAPT, the compiler would silently ignore foregroundInsidePadding attributes when you define it with the android namespace. When using AAPT2, the compiler catches this early and throws the following build error:
Error: (...) resource android:attr/foregroundInsidePadding is private
To resolve this issue, simply replace android:foregroundInsidePadding with foregroundInsidePadding.
I have a module in my app that acts as a dynamic feature.
This dynamic feature module uses a third party library where this third party library has in its AndroidManifest an Activity that uses a custom theme.
With the described configurations, the app compiles fine, but when I try to run it, it throws an error saying that the resource of that Activity's theme could not be found.
The error looks like this:
AGPBI: {"kind":"error","text":"Android resource linking failed","sources":[{"file":"/Users/my_user/Documents/MyProject/App/AppName/build/intermediates/metadata_feature_manifest/debug/processDebugManifest/metadata-feature/AndroidManifest.xml","position":{"startLine":40,"startColumn":8,"endLine":45,"endColumn":54}}],"original":"/Users/my_user/Documents/MyProject/App/AppName/build/intermediates/metadata_feature_manifest/debug/processDebugManifest/metadata-feature/AndroidManifest.xml:41:9-46:55: AAPT: error: resource style/CustomTheme (aka com.my.project.domain:style/CustomTheme) not found.\n ","tool":"AAPT"}
* What went wrong:
Execution failed for task ':app:processDebugResources'.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
Android resource linking failed
/Users/my_user/Documents/MyProject/App/AppName/build/intermediates/metadata_feature_manifest/debug/processDebugManifest/metadata-feature/AndroidManifest.xml:41:9-46:55: AAPT: error: resource style/CustomTheme (aka com.my.project.domain:style/CustomTheme) not found.
I think that that problem is related to the following issue described by Google:
In a dynamic feature module’s manifest, you should not reference resources that don’t exist in the base module. That’s because, when Google Play generates your app’s base APK, it merges manifests for all modules into that of the base APK. So, resource linking breaks if the base APK’s manifest references resources that don’t exist in the base APK.
Reference: https://developer.android.com/guide/app-bundle/
How can one make that project run, if the third party library is not open to be modified?
A work around to fix the mentioned problem is actually pretty simple (misleading and not good looking though).
For example, if the log complains about a style named CustomTheme and a string name custom_string that could not be found, all you have to do is create that style and string resource, empty, in your base module.
../app/src/main/res/values/styles.xml
<resources ...>
...
<style name="CustomTheme" />
</resources>
../app/src/main/res/values/strings.xml
<resources ...>
...
<string name="custom_string" />
<resources />
I'm using two 3rd party libs, both use the same attribute name in their attrs.xml. The build fails with:
Attribute "tabBackground" has already been defined
Is there a way to work around this collision without modifying the argument name in one of the libs?
Actually no.
I suppose you have a dependency from A project to B.
When you build your main project in Eclipse, the resources will fail to build and an error is printed out in the Android console: "... error: Attribute "icon" has already been defined".
Actually you have two ways :
remove dependency from A project to B
OR change attribute name of some project
Also if you build project with Gradle you can use this article which explains how to merge resources.
I want to use the QuiltView lib in my Android project.
When I try the demo, I've no problems, but when I want to use it in my project I've got this error :
error: No resource identifier found for attribute 'scrollOrientation' in package 'com.jake.quiltview'
I've just include libs (QuiltViewLib & GridLayoutV7) in my project...
So, have you got an idea ?
You have to fix the namespace. The XML he used references his own project. You have to change it to reference yours. I had this issue too.
Change
xmlns:app="http://schemas.android.com/apk/res/com.jake.quiltviewsample
To:
xmlns:app="http://schemas.android.com/apk/lib/com.package.class
Obviously changing it to match your project package. :)