Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency issues in reference project

I have an issue that dependencies of a project that is referenced as a dependency module in my android app seem not to be included into the .apk file of my android application.

Project Setup

  • Android App (Android studio & gradle)
  • Java desktop application (IntelliJ/maven/gradle project)
  • Java model (classes & features used by both android & desktop app)

The "Java model" is added as a dependency to both Android App and Java Desktop application.

When I run the desktop application, the dependencies of the JavaModel are resolved via maven, incuded into the application and everything runs smoothly.

From an Android Studio point of view, I have imported the JavaModel as a module into the android project and gradle is used to resolve the dependencies. I have set up the following gradle files:

Android App "settings.gradle"

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

Android App "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 just fine without any errors and a .apk can be created and runs on my test device. However, as soon as I access features within the app that are provided by the "Java model" (in this example, I am using the HttpClient class from the org.apache.httpcomponents:httpclient:4.4.1 dependency), I get the following exception:

java.lang.ClassNotFoundException: Didn't find class "org.apache.http.impl.client.HttpClients"

Plese note that this is just an example case and the issue also occurs with all other dependencies that are only referenced in the "JavaModel", but not in the Android app itself.

It seems to me like the dependencies of the "JavaModel" work just fine at compile time, since everything executes just fine, but are then not included into the .apk file and therefore cause this exeption.

The question is how can I (correctly) make sure that even dependencies of a dependency project are included into the .apk file?

like image 582
Philipp Jahoda Avatar asked Sep 08 '26 20:09

Philipp Jahoda


1 Answers

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

Regarding "JavaModel". If dependencies of JavaModel are compile dependencies it all must work fine (assuming dependency does not have fancy code like classloaders)

like image 126
logcat Avatar answered Sep 10 '26 10:09

logcat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!