Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError in nested jar (Android)

I have created simple app to test the scenario which is failing with NoClassDefFoundError.

Lets take for example i have Test1 android project with Class TestClass with some methods. This Test1 project i exported as a test1.jar and exported only source folder with Class TestClass and classpath and .project files.

In another android project Test2 i added this test1.jar in my libs folder. And in this Test2 project i have a class Test2Class which calls methods of test1.jar class.

After this i exported this Test2 project as test2.jar file following above steps.

So when i use this test2.jar in another project i get this above error NoClassDefFoundError. It is the scenario of jar inside a jar.

Is anywhere should i do something so i am able to access a jar inside a jar.

Thanks in advance.

like image 563
Naveen Kumar Avatar asked Nov 27 '14 11:11

Naveen Kumar


1 Answers

Try this Step by step:
1. Remove all library projects then Clean.
2. Go to first Project Test1 Right click Properties -> Android. Check Is Library(make it library).
3. Go to second Project Test2 Right click Properties -> Android in the Library section select Add -> Add first project as library.
4. Go to second Project Test2 Right click Properties -> Android. Also, Check Is Library.
5. Go to third project C Right click Properties -> Android. In the Library section select Add -> Add First and Second as library. (Do not make Proj C as library)
6. Now Clean everything and run Proj C.
Edit: You can also see this bug Bug 405212 - Do not pack jars bundled inside a packed jar and Bug 361628 - Nested jars cannot be unpacked with Java 1.7. Try the above way it should work.

like image 59
Mohammed Ali Avatar answered Oct 12 '22 23:10

Mohammed Ali