1

What I've done

I've created a library project that contains several custom views complete with custom attributes. The library also contains a test layout to test the views.

I also read: https://code.google.com/p/android/issues/detail?id=9656#c81

So, within the test layout of the library I do make use of the http://schemas.android.com/apk/res-auto namespace.

What I'm trying to do

I then started a new project to consume the library, and including the library to this project was very easy when sharing source code; within the test-app's main activity I could easily inflate the test layout using setContentView(R.layout.libactivity)

However, after closing the library project and attempting to use a jar of the library is proving difficult !

I found the library jar in the /bin folder of the library - but that only contained classes and no resources.

I then exported a jar of the library - and that contained resources files as well as .class files. BUT how is this used?

Specific problem

How is it possible to inflate the libactivity test activity that I included in the library ?

I know there's similar questions like this on stackoverflow - but they seem to be outdated and conflicting because Google made it possible to include resource files in library's.

Someone Somewhere
  • 23,475
  • 11
  • 118
  • 166

2 Answers2

2

Here's how I've been able to create a library project without sharing the source code. It requires two projects: the base library and release library.

Base Library - this is where you put all of your source code, i.e. all your Activities, custom Views, etc. You can put resource files in this library if you want, but it is not needed.

Release Library - contains the jar from the base library's bin/ folder and any resource files you want to include. If you have included any resource files in the base library project, you need to copy them to this project.

When you want to use your code, you add the release library the same as including any other shared library. Your source code will be available, yet hidden, because it is in the jar file. The only other thing to note is that your resource files will be visible since they are in the shared library project. Unfortunately, I was not able to find a way to keep those non-visible.

Therefore, to be specific about your case, you will place your custom views in the base library project. The test layout will need to go in the release library project.

Your third project (one to test the library) will just need a reference to the release library and you should be good to go.

codebaum
  • 103
  • 6
  • As I understand it source code in a jar file is not hidden. Change the 'jar' to 'zip' and unzip it. All source code is readily available for copying. – Brian Reinhold Jul 29 '13 at 13:36
0

Ha... that is a nice question, if you were to export you library project with the xmls, doesn't matter which...

Then add that exported library Jar to the libs folder of your launching project, you would find these XMLs in your R file.

Let me know if it worked...

TacB0sS
  • 10,106
  • 12
  • 75
  • 118