Reputation: 829
I have a project "CustomViews" that I'd like to use as a library in another project "Library Dependent". One of my views, ToolbarITI has a few custom attributes defined in a file which I handle in my ToolbarITI class:
attrs.xml
<resources>
<declare-styleable name="ToolbarITI">
<attr name="rightIconSrc" format="integer"/>
<attr name="leftIconSrc" format="integer"/>
<attr name="titleText" format="string"/>
<attr name="iconPadding" format="dimension"/>
<attr name="fontName" format="string"/>
</declare-styleable>
</resources>
When I add the custom view to a layout in my Library Dependent project, I am able to add these custom attributes in the xml file, and the attributes are applied. However, Android Studio does not recognize the custom: attributes pertaining to ToolbarITI when auto-filling which makes the process annoying. I have declared xmlns:custom at the top of my layout file.
I simply do not understand how these attributes are bundled with the library project and referenced by Android studio. If anyone can explain how this is done, please do provide an explanation!
Upvotes: 2
Views: 1743
Reputation: 829
I'll need someone to confirm that this was the root of the problem, but this is what I found.
I was uploading my .aar to com.tommcfarlin.lib, which with the "lib" results in resources being ignored (according to Android Studio). Though I'm not sure if this results in anything "breaking" when packaging it certainly decreases the functionality of Android Studio by not adding resource ids for autofill. Better be safe and not do this.
These are the steps I took that resulted in Android Studio recognizing the custom attributes.
1) I altered my build.gradle in my CustomViews project to: note the com.tommcfarlin.customviews
def aarFile = file("build/${archivesBaseName}-${project.version}.aar")
artifacts {
archives aarFile
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file:///C:/Users/tmcfarlin/AndroidProjects/myrepo")
pom.groupId = 'com.tommcfarlin.customviews'
pom.artifactId = 'CustomViews'
pom.version = '0.1.0'
}
}
}
2) I ran "gradle uploadArchives" from the terminal
3) In my Library Dependent project I had the following lines in my build.gradle:
repositories {
maven { url 'file:///C:/Users/tmcfarlin/AndroidProjects/myrepo' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.tommcfarlin.customviews:CustomViews:0.1.0@aar'
}
4) I synced the project with gradle files. After this, I still couldn't see the attributes. I closed the Library Dependent project and reopened it voila!!! I could now have the following block where my custom view's attributes were filled in for me when I typed "custom:" and pressed Ctrl+Space
<com.tommcfarlin.customviews.ToolbarITI
android:layout_width="wrap_content"
android:layout_height="wrap_content"
custom:fontName="helvetica.ttf">
</com.tommcfarlin.customviews.ToolbarITI>
This webpage has been immensely useful to me while learning how to set up a local repository. Just be sure not to use the "lib" directory!!! http://blog.glassdiary.com/post/67134169807/how-to-share-android-archive-library-aar-across
Upvotes: 1