The .jar library for Android in the .jar library. Nested dependencies.

I recently asked a very similar question, but did not know how to express it. Having received some feedback and examined some of the possible solutions, I now again ask what I consider to be the best explanation for the problem.

My library (parentLib) is used in my Android application, link methods from another library (childLib) are created in this library. Therefore, the application itself uses parentLib (A.jar library), which in turn uses childLib (another .jar library).

The problem is that when an application tries to use something related to a nested library (childLib), it receives a NoClassDefFoundError, which causes the application to crash. I believe this problem is due to the fact that the application cannot resolve the nested dependency.

I canโ€™t use Android library projects since I need source code that is confusing and as clear as possible. I also tried to create these libraries using Android Studio, only to sadly not get the best result.

My options (I think):

Merge libraries

I can potentially combine childLib and parentLib in one .jar library, splitting them into different packages. It will be difficult, although in practice there are about 6 nested libraries for my intended application.

Insist that the client use multiple libraries

Instead of saying to the client: โ€œHere is one simple library (parentLib) for you to use,โ€ I could say: โ€œThere are 7 different libraries to import (parentLib, childLib, etc.), otherwise nothing will work " Not quite professional!

Other options

I would welcome any other suggestions anyone has!

Thanks in advance.

+6
source share
2 answers

Solved by switching to Android Studio (where there are no such problems).

0
source

NoClassDefFoundError means that the class was present at compile time but was not available in the classpath when trying to execute it.

So you need to tell gradle to compile these libraries and pack them inside apk.

Copy all the libraries you need into the libs folder in the root of your project. Then edit the gradle.build file and add the following:

dependencies { compile fileTree(dir: 'libs', include: '*.jar') } 

This will add all the required libraries to your apk. Thus, the classes you need will be present in the class path when executing the code that they need.

0
source

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


All Articles