Reputation: 149
I have MyAppProject as android application project and MyLibProject as android library project. I have strings.xml(2 strings) and one xyz.java class in MyLibProject. xyz.java class has 2 get methods to access the strings.xml values.
I have added reference library project "MyLibProject" in "MyAppProject" application project.
For some usecase, I will check whether Library project xyz.java class is in classpath then get the values from xyz.class.
How to access the strings.xml texts in xyz.java class get method?
Upvotes: 2
Views: 1402
Reputation: 492
This question has been very old, but creating Android libraries will never get old. I have been working on creating Android libraries for a few days now, and myself encountered this issue of not been able to use res
directory resources in library's java files due to some reason. After 2 days of searching, I found that I was missing package declaration in my library's manifest file.
So, to make it working, check if you have declared package in manifest.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yourpackage">
</manifest>
It worked for me after this change, now I can use resources in library's java files. I hope it works for you too.
Upvotes: 0
Reputation: 5246
As far as I'm aware, you should be able to access any references via a fully qualified name for the R file you're attempting to access, via the Context
. Something like (untested):
Context.getString(com.YOUR.LIB.R.string.YOURSTRING));
Failing that, you could possibly import the com.YOUR.LIB.R
file directly into your activity.
Hope this helps! And I hope that I understand what you're trying to achieve. If not, please provide more information and possibly some code you've already tried, may help explain your problem :)
Upvotes: 1