1

I am trying to add a JAR to libs for another project and then use resources from the JAR inside of that project but I am getting

java.lang.NoClassDefFoundError: com.xxxxx.dylib.R$drawable.

The JAR contents are:

com.xxxxx.dylib
res
res.layout
res.menu
res.values

When the library project is added as a dependency it works but when the JAR is used there is no R.java generated. I believe this is the problem. Is it possible to use resources from a jar within a project?

Reyno
  • 583
  • 13
  • 28
  • resources cannot be packaged into jars. If its a library project you to refer the same in your android project. – Raghunandan Jun 25 '13 at 06:50
  • I am using the command line so that it can all be done through a script. For distribution I cannot use any dependencies and I would like to not send any of the java files so they cannot be edited – user2518868 Jun 25 '13 at 08:15
  • why don't you copy the resource files into your project in that case.? check the links in the answer posted. – Raghunandan Jun 25 '13 at 08:18
  • Thank you for the help. I am still get a noclassdefinitionfound error from one of my resources but that resource in the R.java file. I think the classes from the library are looking for resources in the package of the library. – user2518868 Jun 25 '13 at 08:44
  • updatedadt to rev 22? try this if helps http://stackoverflow.com/questions/16636039/java-lang-classnotfoundexception-after-changing-nothing-in-the-project-but-upgra/16636127#16636127 – Raghunandan Jun 25 '13 at 08:48
  • Yea I have 22 installed. I am trying to do this all from within the command line. – user2518868 Jun 25 '13 at 11:26

2 Answers2

1

JAR files package only the Java code you have, and not the resources.

If you want to use the resources in your project, you will have to take the entire library project, mark it as a library and then add it to your main project as a whole.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
1

Resources cannot be packaged into jar. Pure java class that do not refer to resources can be packaged into jars.

You need to make the project that you need to refer to as a library project and then refer the same in your android project.

http://developer.android.com/tools/projects/index.html

If you want to use command line

http://developer.android.com/tools/projects/projects-cmdline.html

If your using eclipse follow the below link.

http://developer.android.com/tools/projects/projects-eclipse.html

You can right click on the project that you want to refer, goto properties. Choose Android and check Is Library.

Now to refer the library project in your android project.

Right click on your android project, goto properties, choose android, click add browse the library project and the same.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256