Dependency Issues in the Reference Project

The problem I have is that the dependencies of a project that is listed as a dependency module in my Android app doesn't seem to be included in the .apk file of my Android app.

Project setup

  • Android app (android studio and gradle)
  • Java Desktop Application (IntelliJ / maven / gradle project)
  • Java model (classes and functions used for both Android and desktop applications)

The "Java Model" is added as a dependency on the Android App and Java Desktop.

When I run my desktop application, the JavaModel dependencies are resolved through maven, injected into the application, and everything runs smoothly.

From Android Studio perspective, I have imported JavaModel as a module in android project and gradle is used to resolve dependencies. I have installed the following gradle files:

Android App "settings.gradle"

include ':app'
include ':JavaModel'
project(':JavaModel').projectDir=new File('../../JavaModel')

      

Android application "build.gradle"

dependencies {
    compile project(':JavaModel')
    // and more...
}

      

Java model "build.gradle"

dependencies {
    compile(
            'org.apache.httpcomponents:httpclient:4.4.1'
            // and more ...
    )
}

      

Everything compiles fine without any errors and the .apk can be built and run on my test device. However , as soon as I access the functions in the application that are provided by the "Java Model" (in this example, I am using a class HttpClient

from dependencies org.apache.httpcomponents:httpclient:4.4.1

), I get the following exception:

java.lang.ClassNotFoundException: class "org.apache.http.impl.client.HttpClients" was not found

Remember that this is just an example case , and the problem also occurs with all other dependencies that are only mentioned in "JavaModel" and not in the Android application itself.

It seems to me that the "JavaModel" dependencies work very well at compile time, since everything runs just fine, but then is not included in the .apk file and therefore throws this exception.

The question is, how can I (correctly) ensure that even project dependent dependencies are included in the .apk file?

+3


source to share


1 answer


Apache http client conflicts with android one, if you want to use recent you need to use android port https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html



Regarding "JavaModel". If JavaModel dependencies depend on compiled dependencies, they should all work fine (assuming the dependency does not have attractive code like classloaders)

+2


source







All Articles