OK, so I have a module called "Gridbox" which is a layout widget I wrote a very long time ago.
Within Gridbox is the file res/values/gridboxAttrs.xml
which contains (abridged):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Gridbox_Layout">
<attr name="layout_weightx" format="float" />
<attr name="layout_weighty" format="float" />
</declare-styleable>
</resources>
In my application module I have res/values/styles.xml
which references resources defined above:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Style for a normal button -->
<style name="baseButton">
<item name="android:gravity">center</item>
<item name="layout_weightx">1</item>
<item name="layout_weighty">1</item>
<item name="android:layout_margin">1dip</item>
</style>
</resources>
This built just fine under Eclipse, but Android Studio gives me
ERROR: /Users/falk/MyProject/MyApp/build/intermediates/packaged_res/debug/packageDebugResources/values/values.xml:372:5-384:11: AAPT: error: style attribute 'attr/layout_weightx (aka org.efalk.myapp.test:attr/layout_weightx)' not found.
I’m guessing I need to do something to get Android Studio to know that the module "MyApp" depends on module "Gridbox". My MyApp/build.gradle
file does end with
dependencies {
implementation project(':Gridbox')
}
For completeness, here is settings.gradle
:
pluginManagement {
repositories {
google {
content {
includeGroupByRegex("com\.android.*")
includeGroupByRegex("com\.google.*")
includeGroupByRegex("androidx.*")
}
}
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "MyProject"
include ':Gridbox'
include ':MyApp'
I have no idea what else I should be doing.
3
Answers
Not sure about your SDK version, but probably adding a
module-info.java
file inMyApp
help? i.e. to specify the dependency onGridbox
:something like this:
You are probably using AGP 7+ which requires "namespace" defined in build.gradle of Gridbox. In older versions of AGP namespace would be taken from the package defined in AndroidManifest.xml of the sdk.
Solution 1
Add above line in build.gradle
Solution2
Lower AGP version in main project.
The error message you’re encountering in Android Studio indicates that it can’t find the
layout_weightx
attribute defined in yourGridbox
module. There are a couple of things to check:The error message shows
aka org.efalk.myapp.test:attr/layout_weightx
. This suggests a namespace issue. Double-check the following:gridboxAttrs.xml
, ensure thedeclare-styleable
element has the attributexmlns:android="http://schemas.android.com/apk/res/android"
declared at the top level. This ensures the attributes are defined within the standard Android namespace.styles.xml
, remove the prefixorg.efalk.myapp.test:
fromlayout_weightx
. You shouldn’t need to specify the application or test package when referencing attributes defined within your own modules.While your
build.gradle
seems correct, ensure Gradle has properly synced the dependencies. Sometimes, a clean build can help resolve issues:Make sure there aren’t any circular dependencies between
Gridbox
andMyApp
. If both modules depend on each other in a circular fashion, it can cause build issues. Review your dependencies in bothbuild.gradle
files.Additional Tips:
layout_weightx
) betweengridboxAttrs.xml
andstyles.xml
.If the issue persists after trying these suggestions, consider providing the complete
gridboxAttrs.xml
andstyles.xml
files for further analysis.