Package org.apache.http does not exist and the app dont compile

Hi!
Im learning ionic but I have a problem, I have been trying to solve this, but I dont know how.

When I launch:
sudo ionic cordova run android

in my app I recieve that error:

`


> Configure project :app
+-----------------------------------------------------------------
| cordova-android-support-gradle-release: 27.+
+-----------------------------------------------------------------

> Task :app:preBuild UP-TO-DATE
> Task :CordovaLib:preBuild UP-TO-DATE
> Task :CordovaLib:preDebugBuild UP-TO-DATE
> Task :CordovaLib:checkDebugManifest UP-TO-DATE
> Task :CordovaLib:processDebugManifest UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :CordovaLib:compileDebugAidl NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :CordovaLib:packageDebugRenderscript NO-SOURCE
> Task :app:compileDebugRenderscript UP-TO-DATE
> Task :app:checkDebugManifest UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateDebugSources UP-TO-DATE
> Task :CordovaLib:compileDebugRenderscript UP-TO-DATE
> Task :CordovaLib:generateDebugBuildConfig UP-TO-DATE
> Task :CordovaLib:generateDebugResValues UP-TO-DATE
> Task :CordovaLib:generateDebugResources UP-TO-DATE
> Task :CordovaLib:packageDebugResources UP-TO-DATE
> Task :CordovaLib:generateDebugRFile UP-TO-DATE
> Task :CordovaLib:prepareLintJar UP-TO-DATE
> Task :CordovaLib:generateDebugSources UP-TO-DATE
> Task :CordovaLib:javaPreCompileDebug UP-TO-DATE
> Task :CordovaLib:compileDebugJavaWithJavac UP-TO-DATE
> Task :CordovaLib:processDebugJavaRes NO-SOURCE
> Task :CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:mainApkListPersistenceDebug UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:mergeDebugResources UP-TO-DATE
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:processDebugResources UP-TO-DATE

> Task :app:compileDebugJavaWithJavac FAILED
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:6: error: package org.apache.http does not exist
import org.apache.http.HttpResponse;
                      ^
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:7: error: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.HttpPost;
                                     ^
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:8: error: package org.apache.http.entity does not exist
import org.apache.http.entity.StringEntity;
                             ^
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:9: error: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.DefaultHttpClient;
                                  ^
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:662: error: cannot find symbol
            DefaultHttpClient httpClient = new DefaultHttpClient();
            ^
  symbol:   class DefaultHttpClient
  location: class LocationUpdateService
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:662: error: cannot find symbol
            DefaultHttpClient httpClient = new DefaultHttpClient();
                                               ^
  symbol:   class DefaultHttpClient
  location: class LocationUpdateService
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:663: error: cannot find symbol
            HttpPost request = new HttpPost(url);
            ^
  symbol:   class HttpPost
  location: class LocationUpdateService
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:663: error: cannot find symbol
            HttpPost request = new HttpPost(url);
                                   ^
  symbol:   class HttpPost
  location: class LocationUpdateService
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:677: error: cannot find symbol
            StringEntity se = new StringEntity(params.toString());
            ^
  symbol:   class StringEntity
  location: class LocationUpdateService
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:677: error: cannot find symbol
            StringEntity se = new StringEntity(params.toString());
                                  ^
  symbol:   class StringEntity
  location: class LocationUpdateService
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:691: error: cannot find symbol
            HttpResponse response = httpClient.execute(request);
            ^
  symbol:   class HttpResponse
  location: class LocationUpdateService
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/org/apache/cordova/file/AssetFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
11 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
24 actionable tasks: 1 executed, 23 up-to-date
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/gradlew: Command failed with exit code 1 Error output:
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:6: error: package org.apache.http does not exist
import org.apache.http.HttpResponse;
                      ^
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:7: error: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.HttpPost;
                                     ^
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:8: error: package org.apache.http.entity does not exist
import org.apache.http.entity.StringEntity;
                             ^
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:9: error: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.DefaultHttpClient;
                                  ^
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:662: error: cannot find symbol
            DefaultHttpClient httpClient = new DefaultHttpClient();
            ^
  symbol:   class DefaultHttpClient
  location: class LocationUpdateService
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:662: error: cannot find symbol
            DefaultHttpClient httpClient = new DefaultHttpClient();
                                               ^
  symbol:   class DefaultHttpClient
  location: class LocationUpdateService
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:663: error: cannot find symbol
            HttpPost request = new HttpPost(url);
            ^
  symbol:   class HttpPost
  location: class LocationUpdateService
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:663: error: cannot find symbol
            HttpPost request = new HttpPost(url);
                                   ^
  symbol:   class HttpPost
  location: class LocationUpdateService
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:677: error: cannot find symbol
            StringEntity se = new StringEntity(params.toString());
            ^
  symbol:   class StringEntity
  location: class LocationUpdateService
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:677: error: cannot find symbol
            StringEntity se = new StringEntity(params.toString());
                                  ^
  symbol:   class StringEntity
  location: class LocationUpdateService
/home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:691: error: cannot find symbol
            HttpResponse response = httpClient.execute(request);
            ^
  symbol:   class HttpResponse
  location: class LocationUpdateService
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /home/abraham/Escritorio/vengavamoh/SafeJewellery/platforms/android/app/src/main/java/org/apache/cordova/file/AssetFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
11 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
[ERROR] An error occurred while running subprocess cordova.
        
        cordova build android --device exited with exit code 1.
        
        Re-running this command with the --verbose flag may provide more information.`

This is my ionic info :
``

`Ionic:

   Ionic CLI                     : 6.4.0 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.0.7
   @angular-devkit/build-angular : 0.901.0
   @angular-devkit/schematics    : 9.1.0
   @angular/cli                  : 9.1.0
   @ionic/angular-toolkit        : 2.2.0

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.1.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 12 other plugins)

Utility:

   cordova-res (update available: 0.11.0) : 0.9.0
   native-run (update available: 1.0.0)   : 0.3.0

System:

   Android SDK Tools : 26.1.1 (/root/Android/Sdk/)
   NodeJS            : v13.8.0 (/usr/local/bin/node)
   npm               : 6.13.6
   OS                : Linux 5.3```

How can I solve it? I was searching on internet but any solution works for me

Thanks!

I’m facing the same issue. Two days ago the app was building without issues, yesterday I started to get this issue and today is the second day I’m trying to fix this. The issue is within the dependencies for sure but I’ve no idea which one! I’ve tried several things without success.

Is there anyone out there with a suggestion?

> Task :app:compileDebugJavaWithJavac FAILED
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:6: error: package org.apache.http does not exist
import org.apache.http.HttpResponse;
                      ^
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:7: error: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.HttpPost;
                                     ^
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:8: error: package org.apache.http.entity does not exist
import org.apache.http.entity.StringEntity;
                             ^
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:9: error: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.DefaultHttpClient;
                                  ^
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:662: error: cannot find symbol
            DefaultHttpClient httpClient = new DefaultHttpClient();
            ^
  symbol:   class DefaultHttpClient
  location: class LocationUpdateService
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:662: error: cannot find symbol
            DefaultHttpClient httpClient = new DefaultHttpClient();
                                               ^
  symbol:   class DefaultHttpClient
  location: class LocationUpdateService
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:663: error: cannot find symbol
            HttpPost request = new HttpPost(url);
            ^
  symbol:   class HttpPost
  location: class LocationUpdateService
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:663: error: cannot find symbol
            HttpPost request = new HttpPost(url);
                                   ^
  symbol:   class HttpPost
  location: class LocationUpdateService
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:677: error: cannot find symbol
            StringEntity se = new StringEntity(params.toString());
            ^
  symbol:   class StringEntity
  location: class LocationUpdateService
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:677: error: cannot find symbol
            StringEntity se = new StringEntity(params.toString());
                                  ^
  symbol:   class StringEntity
  location: class LocationUpdateService
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:691: error: cannot find symbol
            HttpResponse response = httpClient.execute(request);
            ^
  symbol:   class HttpResponse
  location: class LocationUpdateService
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
11 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
24 actionable tasks: 1 executed, 23 up-to-date
/Users/pabloleone/Projects/coronapp/platforms/android/gradlew: Command failed with exit code 1 Error output:
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:6: error: package org.apache.http does not exist
import org.apache.http.HttpResponse;
                      ^
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:7: error: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.HttpPost;
                                     ^
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:8: error: package org.apache.http.entity does not exist
import org.apache.http.entity.StringEntity;
                             ^
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:9: error: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.DefaultHttpClient;
                                  ^
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:662: error: cannot find symbol
            DefaultHttpClient httpClient = new DefaultHttpClient();
            ^
  symbol:   class DefaultHttpClient
  location: class LocationUpdateService
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:662: error: cannot find symbol
            DefaultHttpClient httpClient = new DefaultHttpClient();
                                               ^
  symbol:   class DefaultHttpClient
  location: class LocationUpdateService
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:663: error: cannot find symbol
            HttpPost request = new HttpPost(url);
            ^
  symbol:   class HttpPost
  location: class LocationUpdateService
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:663: error: cannot find symbol
            HttpPost request = new HttpPost(url);
                                   ^
  symbol:   class HttpPost
  location: class LocationUpdateService
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:677: error: cannot find symbol
            StringEntity se = new StringEntity(params.toString());
            ^
  symbol:   class StringEntity
  location: class LocationUpdateService
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:677: error: cannot find symbol
            StringEntity se = new StringEntity(params.toString());
                                  ^
  symbol:   class StringEntity
  location: class LocationUpdateService
/Users/pabloleone/Projects/coronapp/platforms/android/app/src/main/java/com/zencity/cordova/bgloc/LocationUpdateService.java:691: error: cannot find symbol
            HttpResponse response = httpClient.execute(request);
            ^
  symbol:   class HttpResponse
  location: class LocationUpdateService
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
11 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
[ERROR] An error occurred while running subprocess cordova.

        cordova build android --emulator exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

The paths in your error messages suggest this one.

The problem is that the background geolocation plugin that is have is this one :slight_smile:
@mauron85/cordova-plugin-background-geolocation

Not zencity. I dont no why, but this plugin appears…

Hi, i solved this by removing plugin cordova-plugin-background-geolocation

ionic cordova plugin rm cordova-plugin-background-geolocation

2 Likes

Works for me!!! thanks

I suspect that this is the problematic plugin, but I need it.
Also I can’t find references in the source code to the code that doesn’t compile (legacy http client)…
It started when I updated to cordova 10 and cordova-android 9.
Were you able to solve this without removing the plugin?

Apparently I got a dependency I didn’t added: cordova-plugin-background-geolocation which is not @mauron/cordova-plugin-background-geolocation… :frowning: I don’t know how it got in…

The problems is:

When you habe @mauron85/cordova-plugin-background-geolocation pluging and exectute Add platform all plugins of package.json are installed… and… Surprise: One extra plugin that you dont needed install too !! “cordova-plugin-background-geolocation”: "^1.0.6"

Look at this, If you:

  1. Remove “@mauron85/cordova-plugin-background-geolocation” plugin from your package.json.
  2. Then add platform.
  3. Then add plugin: ionic cordova plugin add @mauron85/cordova-plugin-background-geolocation

All goes well.

but, if you use your package.json as if and add platform, the extra pluging is added… and you need to remove manually (like afiqsoftoya19 said) to build…

I dont know why… but i cant use Ionic AppFlow becouse that…

Ok, I found the solution:
On package.Json in DevDependences add:

“cordova-plugin-background-geolocation”: “@mauron85/cordova-plugin-background-geolocation@^3.1.0”,

This line prevent “Add platform” to adding cordova-plugin-background-geolocation”: “^1.0.6”

Jope this help someone else.

3 Likes