Home Forum
Welcome, Guest
Username Password: Remember me

Making a JAR file that contains resources
(1 viewing) (1) Guest
Discussion related to creating Android software
  • Page:
  • 1

TOPIC: Making a JAR file that contains resources

Making a JAR file that contains resources 3 years, 4 months ago #108

Does anyone happen to know how to make a JAR file that I can use in a number of different projects? I've found loads of information on how to export the stuff I want to a JAR using Eclipse and it all seems to work.
The problem is that it needs to contain some images and txt files and they are referenced via R.Java. I even created a dummy app that contains only the stuff I wanted in the JAR and exported it all (including the R.Java). When I run the new app with the JAR included it seems to work fine but when it tries to reference anything (R.raw.settings for example) the debugger shows the correct value from the R.Java file but is just passing in rubbish.
I assume that the R.Java is populated with values from original app and they are useless once in the JAR.
How has Google managed to do it with Android.Jar?

Cheers,
Steve
  • StephenL
  • OFFLINE
  • Freshman
  • Posts: 9
  • Karma: 0

Re:Making a JAR file that contains resources 3 years, 4 months ago #109

Hmm. Well, since a jar is really just a zip file and you have the zip calls available in java to extract its contents, one approach could be to just include the jar with your project as if its a raw resource (like any binary data file), then use the File io stuff (FileReader etc) to get a handle to it and read it in. I did this with a html file early on in my Android work. It worked, but I since found out I'd done it the hard way as the browser can access html files much easier than treating them as raw binaries.

Give me a prod if you're still struggling and I'll dig out that general data file loader I mentioned.
  • ticktock
  • OFFLINE
  • Professor
  • Posts: 79
  • Karma: 6

Re:Making a JAR file that contains resources 3 years, 4 months ago #110

Thanks Ticktock, I think this website has the same idea
Bypassing Resources

I will have to look into this approach on Monday, hopefully it'll all fall into place first time

Thanks again,
Steve
  • StephenL
  • OFFLINE
  • Freshman
  • Posts: 9
  • Karma: 0

Re:Making a JAR file that contains resources 3 years, 3 months ago #112

All seems to work fine

InputStream is = Application.getInstance().getAssets().open("image.png"); 
 
BitmapFactory.decodeStream(is);


All resources (images etc. are in the Assests folder)

Application is just a singleton class wrapped around the activity (that will be built on top of our JAR).

Thanks again,
Steve
  • StephenL
  • OFFLINE
  • Freshman
  • Posts: 9
  • Karma: 0
Last Edit: 3 years, 3 months ago by StephenL.
  • Page:
  • 1
Time to create page: 0.26 seconds
Copyright © 2012 Android Academy. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.
 
Glossary
We have 32 guests online