mavlink / MAVSDK-Java

MAVSDK client for Java.
68 stars 40 forks source link

Solution: Dependency resolution problems (NoClassDefFoundError or duplicate class error) #79

Closed divyanshupundir closed 2 years ago

divyanshupundir commented 2 years ago

Dependency resolution is a known problem in protobuf javalite projects. There are two situations when a user will be using the mavsdk library in their applications:

  1. The users build the jar themselves and use something like implementation(files("libs/mavsdk-<version>.jar"))

In this case, since the metadata of the libraries used by mavsdk internally is not included in the form of the pom file (which Gradle uses to add the internal dependencies), the users will have to add all mavsdk dependencies themselves.

Declaring dependencies like this should work:

def grpcVersion = "1.36.2"
implementation "io.grpc:grpc-okhttp:${grpcVersion}"
implementation("io.grpc:grpc-protobuf-lite:${grpcVersion}")  {
    exclude group: "com.google.protobuf", module: "protobuf-javalite"
}
implementation "io.grpc:grpc-stub:${grpcVersion}"
implementation 'org.slf4j:slf4j-api:1.7.25'
// Other mavsdk dependencies
  1. The users use the published artefact:

Internal dependencies need not be included again. Simply doing this will work:

implementation("io.mavsdk:mavsdk:<versison>")  {
    exclude group: "com.google.protobuf", module: "protobuf-javalite"
}