NoClassDefFoundError in a nested jar (Android)

I created a simple script testing application that fails with NoClassDefFoundError .

Let's take, for example, the Test1 android project with the TestClass class with some methods. I exported this Test1 project as test1.jar and exported only the source folder with Class TestClass and classpath and. project .

In another Android Test2 project, I added this test1.jar to my libs folder. And in this Test2 project, I have a Test2Class class that calls the methods of the test1.jar class.

After that, I exported this Test2 project as a test2.jar file, following the steps.

Therefore, when I use this test2.jar in another project, I get this error above NoClassDefFoundError . This is a scenario of a can in a bank.

Somewhere I have to do something so that I can access the bank inside the bank.

Thanks in advance.

+6
source share
4 answers

Try this step by step:
1. Remove all library projects, then Clean.
2. Go to the first Test1 project Test1 Right-click Properties โ†’ Android. Check out Is Library (make it a library).
3. Go to the second Test2 project Test2 Right-click Properties โ†’ Android in the "Library" section, select Add โ†’ Add the first project as a library.
4. Go to the second Test2 project Test2 Right-click Properties โ†’ Android. Also check out the Is Library .
5. Go to the third project C Right-click Properties โ†’ Android. In the "Library" section, select Add โ†’ Add First and Second as a Library. (Do not make Proj C as a library)
6. Now clear everything and run Proj C
Edit: You can also see this error. Error 405212 - Do not pack jars in a packed jar and Error 361628 - Nested jars cannot be unpacked using Java 1.7 . Try to do as it should work.

+3
source

Remove jars from java build path. Add a new folder name as "libs" and place all banks in this folder. The application will work fine

0
source

Try the following:

Go to Project / Properties / Java Build Path / Order and Export - make sure that you use it before Android Dependencies and the support library.

Check all the checkboxes and click "Apply" and clear the project.

0
source

This is impossible to do. You will need to unzip the JARs and add them to the classpath to open the nested JAR. See the Java error link for help.

There are several alternatives for proper handling; see this question that recommends One-jar , Uber jar or Shade

Note. This is true for Java, Andoid may behave differently, but it seems to have the same problem.

0
source

Source: https://habr.com/ru/post/978781/


All Articles