silkimen / cordova-plugin-advanced-http

Cordova / Phonegap plugin for communicating with HTTP servers. Allows for SSL pinning!
MIT License
400 stars 321 forks source link

[Bug] [Android] Dependency issue with latest File plugin, App build is failing. #468

Open kalandher opened 2 years ago

kalandher commented 2 years ago

Describe the bug

App build failing after re-installing of latest 'cordova-plugin-file' plugin. I observe there is dependency for File plugin in 'CordovaHttpDownload.java', which says doesn't exist during app build.

System info

Are you using ionic-native-wrapper?

Minimum viable code to reproduce Below is error during app build

> Task :app:compileDebugJavaWithJavac FAILED \platforms\android\app\src\main\java\com\silkimen\cordovahttp\CordovaHttpDownload.java:12: error: package org.apache.cordova.file does not exist import org.apache.cordova.file.*; ^ \platforms\android\app\src\main\java\com\silkimen\cordovahttp\CordovaHttpDownload.java:34: error: cannot find symbol JSONObject fileEntry = FileUtils.getFilePlugin().getEntryForFile(file); ^ symbol: variable FileUtils location: class CordovaHttpDownload 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. 2 errors FAILURE: Build failed with an exception.

Below is the file where above error is mentioned

package com.silkimen.cordovahttp;

import java.io.File;
import java.net.URI;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;

import com.silkimen.http.HttpRequest;
import com.silkimen.http.TLSConfiguration;

import org.apache.cordova.file.FileUtils;
import org.json.JSONObject;

class CordovaHttpDownload extends CordovaHttpBase {
  private String filePath;

  public CordovaHttpDownload(String url, JSONObject headers, String filePath, int timeout, boolean followRedirects,
      TLSConfiguration tlsConfiguration, CordovaObservableCallbackContext callbackContext) {

    super("GET", url, headers, timeout, followRedirects, "text", tlsConfiguration, callbackContext);
    this.filePath = filePath;
  }

  @Override
  protected void processResponse(HttpRequest request, CordovaHttpResponse response) throws Exception {
    response.setStatus(request.code());
    response.setUrl(request.url().toString());
    response.setHeaders(request.headers());

    if (request.code() >= 200 && request.code() < 300) {
      File file = new File(new URI(this.filePath));
      JSONObject fileEntry = FileUtils.getFilePlugin().getEntryForFile(file);

      request.receive(file);
      response.setFileEntry(fileEntry);
    } else {
      response.setErrorMessage("There was an error downloading the file");
    }
  }
}

``

Screenshots If applicable, add screenshots to help explain your problem.

image

yksolanki9 commented 2 years ago

@kalandher I'm facing the same issue. Did you find any solution for this?

yksolanki9 commented 2 years ago

Update: I fixed this issue by installing cordova-plugin-file in my project

kalandher commented 2 years ago

@yksolanki9 Which version of cordova-plugin-file have you installed ? I tried with latest version that's when I encountered this issue

yksolanki9 commented 2 years ago

If you're on cordova-file-plugin v7 and getting this error Cannot find symbol CordovaPluginPathHandler, downgrade the plugin to v6

kalandher commented 2 years ago

There are issues in V6 with respect to Android x support. That's the reason we have to upgrade to v7. https://github.com/apache/cordova-plugin-file/issues/511

yksolanki9 commented 2 years ago

My bad, I did not test it on Android 11. As a workaround, you can try this stackoverflow solution

kalandher commented 2 years ago

My bad, I did not test it on Android 11. As a workaround, you can try this stackoverflow solution

Error I'm getting is different. This solution doesn't work. My issue is with the file plugin dependency which is upgraded to v7 and it needs Cordova android 10 to be installed.

colorthoro commented 2 years ago

@kalandher Did you find any solution for this?

graemian commented 1 year ago

I am using Meteor (https://guide.meteor.com/cordova). I found that if I do a fresh build (i.e. clean .meteor/local/cordova-build directory), I get this error.

To work around it, I remove this package (cordova-plugin-advanced-http), do a clean build, then re-add it and build again.

If I had to guess, I would say the problem is that cordova-plugin-advanced-http depends on cordova-plugin-file, but is built before cordova-plugin-file. Either the dependency isn't declared, or the build system ignores it.

graemian commented 1 year ago

Actually, if I just list cordova-plugin-advanced-http@3.3.1 AFTER cordova-plugin-file@7.0.0 in .meteor/cordova-plugins , everything works fine