How make Android self components and use it from a jar library?
Asked Answered
C

1

10

I'm trying to create an android component that can be easily added to android projects as a jar library.

For this, I had to create new xml attributes in "res/values/attr.xml" that I add to my graphic xml element using the path:

 xmlns:app="http://schemas.android.com/apk/res/com.component.mypackage"

Then I import this project as a jar library into another project. To create my graphic components in the new project, I must change the path below:

 xmlns:app="http://schemas.android.com/apk/res/com.mylibrary"

But the path is incorrect: the custom attributes are not found.

I managed to integrate the R file in the library jar and I could access it from my xml to declare a custom component like this:

<PreferenceScreen
  xmlns:android = "http://schemas.android.com/apk/res/android"
 xmlns:app = "http://schemas.android.com/apk/res/com.myLibraryPackage">

<com.myLibraryPackage.mySelfComponent
     android:title="Name"
     android:key="name"
     app:hintText="Input your name"
     android:dialogTitle="Your name "
     app:validator="com.myLibraryPackage.myValidatorClass" />

What is strange is that if I put my file attr.xml in resources of my project, it works, which means it find com.myLibraryPackage.mySelfComponent. In that case, why it can't find also com.myLibraryPackage ?

(I also tried replacing

xmlns:app="http://schemas.android.com/apk/res/com.myLibraryPackage"

by

xmlns:app="http://schemas.android.com/apk/res/com.myApplicationPackage"

but it still doesn't work)

I would have preferred to use a jar to facilitate its integration in a project !

Has anyone encountered a problem like this who could help me?

Thank you.

Conifer answered 5/5, 2011 at 13:47 Comment(3)
+1 I can't help, but have an upvote for the bilingual question!Decedent
Yeah, but if everybody starts doing that, it'll be a mess.Corallite
Moi aussi / Me too, Je Upvote / I ajoute un vote for the bilingual question.Aardvark
M
3

I'm trying to create an android component that can be easily added to android projects as a jar library.

If you want reuse code and resources, it won't be possible to do it with a jar file. You'll need to convert your library to a library project.

Then I import this project as a jar library into another project. To create my graphic components in the new project, I must change the path below:

If you're using a library project, you'd still reference the custom attribute as if it were contained in the application (since android will merge all the resources together when the application is compiled):

xmlns:app="http://schemas.android.com/apk/res/com.component.mypackage"
Mould answered 5/5, 2011 at 15:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.