agamemnus / cordova-plugin-xapkreader

Easily access Google Play APK expansion file data.
32 stars 55 forks source link

Error Gradle "Could not resolve project" on compile #116

Open NiSHoW opened 6 years ago

NiSHoW commented 6 years ago

There is a new system to add dependencies build-extra.gradle file of project download-library must be change like this

dependencies {
    implementation project(':com.flyingsoftgames.xapkreader:library')
}

android {
    useLibrary 'org.apache.http.legacy'
}

see this reference: https://stackoverflow.com/questions/33718663/gradle-error-configuration-declares-dependency-which-is-not-declared

renzoolguin commented 6 years ago

Resolving this issue actually takes two parts. @NiSHoW mentioned the first step. I confirmed it by testing that change in this fork.

The second step is fixing the plugin-build.gradle template in cordova-android. My current hacky solution is to run the following script as a cordova hook:

config.xml

<hook
  comment="Update Cordova Plugin Gradle Template for Gradle 3.0+"
  src="hooks/cordova-plugin-gradle-update.js"
  type="after_platform_add"
/>

hooks/cordova-plugin-gradle-update.js

module.exports = function(context) {
  var fs = require('fs');
  var pattern = /debugCompile (project\(.*)\,.*(\))\n\s*releaseCompile.*/g;
  var replacement = 'implementation $1)';
  var target = 'platforms/android/cordova/lib/plugin-build.gradle';

  console.log('Updating Cordova Plugin Gradle Template to work with gradle 3.0+');

  fs.readFile(target, 'utf8', function (err,data) {
    if (err) return console.log(err);

    data = data.replace(pattern, replacement);

    fs.writeFile(target, data, 'utf8', function (err) {
      if (err) return console.log(err);

      console.log('Updated: ' + target);
    });
  });
};

I'm not sure if and when cordova-android plans on fixing that. Ideally they will fix that in both versions 6.4.0 and 7.0.0. I say that because v7.0.0 introduced structural changes that I don't think most developers want to make right now.

If anyone has a better solution or knows of something that I'm missing, then please share.

Environment: Cordova-CLI: 7.0.1 Cordova-Android: 6.4.0 Gradle: 4.4.1

agamemnus commented 6 years ago

Sounds so complex. Thank you for sharing.

eAi commented 6 years ago

I've hit this issue and fixed it in a similar way to @renzoolguin above (many thanks!) I'm pretty new to Cordova, but I'm a bit baffled as to why this hasn't been fixed in cordova-android itself and in this project - is this an unusual bug? I'm not demanding for it to be fixed, I'm just confused as to why it hasn't been an issue for lots of other people.

One thing I found was that 'after_platform_add' seems to be called too late - when I use 'cordova prepare' this doesn't get called until after the whole project has been generated - at which point the plugin has already had the gradle file generated. I tried changing this to 'before_plugin_install' - which initially seemed to work, but I believe there's a race condition of sorts - this appears to run in parallel with the generation of the gradle configs. The ultimate fix I ended up with was to modify the generated gradle files - rather than the template, using the same code as above.

It all feels a bit dirty!

Environment Cordova: 7.0.1 Cordova-Android: 6.4.0 Gradle: 4.1

Saturnyn commented 5 years ago

Had the same problem, fixed it thanks to the info on this thread:

However, I had to modify the hook code to avoid timing issues: by making the hook return a promise we can ensure the build won't continue until the hook is finished.

let fse = require('fs-extra');

module.exports = function(context) {
    let pattern = /debugCompile (project\(.*)\,.*(\))\n\s*releaseCompile.*/g;
    let replacement = 'implementation $1)';
    let target = 'platforms/android/cordova/lib/plugin-build.gradle';

    const deferral = context.requireCordovaModule('q').defer();

    console.log('srcipts/cordovaPluginGradleUpdate: fixing gradle');
    fse.readFile(target, 'utf8')
    .then((data)=>{
        data = data.replace(pattern, replacement);

        return fse.writeFile(target, data, 'utf8')
        .then(()=>{
            console.log('srcipts/cordovaPluginGradleUpdate: done !');
            deferral.resolve();
        });
    })
    .catch((e)=>{
        deferral.reject('srcipts/cordovaPluginGradleUpdate: error '+e);
    });
    return deferral.promise;
};
erobertson42 commented 4 years ago

Thanks to everyone in the thread contributing to the install hook helping me get past some of the build issues I was having. I wanted to mention though, that using Cordova 9 causes this to break with the error:

Using "requireCordovaModule" to load non-cordova module "q" is not supported

The fix was easy enough however. Just add let q = require('q'); to the top, and then replace

const deferral = context.requireCordovaModule('q').defer();

with

const deferral = q.defer();

(or you could make it a one-liner, dealer's choice)

That said, I created a new fork in order to add several other fixes I needed for my application (including a couple others added to this hook script), and some changes to make it simpler to install/configure for others in my organization that will also need to maintain our app. Maybe it'll be of use to others as well: https://github.com/erobertson42/cordova-plugin-xapkreader/tree/cordova-9

And here is a summary of the changes: https://github.com/erobertson42/cordova-plugin-xapkreader/blob/cordova-9/README.md#changes

agamemnus commented 4 years ago

Thank you. I will review those some time soon. It is really annoying that everything keeps breaking, but I try to keep up now and then.

Johnafriedman commented 4 years ago

https://github.com/erobertson42/cordova-plugin-xapkreader/tree/cordova-9

And here is a summary of the changes: https://github.com/erobertson42/cordova-plugin-xapkreader/blob/cordova-9/README.md#changes

@erobertson42 thanks for sharing this! When I try to build my project I get platforms/android/app/src/main/java/com/flyingsoftgames/xapkreader/XAPKDownloaderActivity.java:17: error: package android.support.v4.content does not exist I've tried adding a android.support.v4 plugin but then I get duplicate definitions. I'm sure it's a problem in my setup, I just wondered if a simple answer is available. My output is attached below.

`Checking Java JDK and Android SDK versions ANDROID_SDK_ROOT=/Users/johnfriedman/Library/Android/sdk (recommended setting) ANDROID_HOME=/Users/johnfriedman/Library/Android/sdk (DEPRECATED) Subproject Path: CordovaLib Subproject Path: app Subproject Path: com.flyingsoftgames.xapkreader/FamilyPortal-downloader_library Subproject Path: com.flyingsoftgames.xapkreader/FamilyPortal-library

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 :com.flyingsoftgames.xapkreader:downloader_library:preBuild UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:preDebugBuild UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:checkDebugManifest UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:processDebugManifest UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:preBuild UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:preDebugBuild UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:checkDebugManifest UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:processDebugManifest UP-TO-DATE Task :app:preDebugBuild UP-TO-DATE Task :CordovaLib:compileDebugAidl NO-SOURCE Task :com.flyingsoftgames.xapkreader:library:compileDebugAidl NO-SOURCE Task :com.flyingsoftgames.xapkreader:downloader_library:compileDebugAidl NO-SOURCE Task :app:compileDebugAidl NO-SOURCE Task :CordovaLib:packageDebugRenderscript NO-SOURCE Task :com.flyingsoftgames.xapkreader:downloader_library:packageDebugRenderscript NO-SOURCE Task :com.flyingsoftgames.xapkreader:library: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 :com.flyingsoftgames.xapkreader:downloader_library:compileDebugRenderscript UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:generateDebugBuildConfig UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:generateDebugResValues UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:generateDebugResources UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:packageDebugResources UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:compileDebugRenderscript UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:generateDebugResValues UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:generateDebugResources UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:packageDebugResources UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:generateDebugRFile UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:generateDebugRFile UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:prepareLintJar UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:generateDebugSources UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:generateDebugBuildConfig UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:prepareLintJar UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:generateDebugSources UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:javaPreCompileDebug UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:compileDebugJavaWithJavac UP-TO-DATE Task :com.flyingsoftgames.xapkreader:library:processDebugJavaRes NO-SOURCE Task :com.flyingsoftgames.xapkreader:library:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:javaPreCompileDebug UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:compileDebugJavaWithJavac UP-TO-DATE Task :com.flyingsoftgames.xapkreader:downloader_library:processDebugJavaRes NO-SOURCE Task :com.flyingsoftgames.xapkreader:downloader_library: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 /Users/johnfriedman/dev/family-portal-native/platforms/android/app/src/main/java/com/flyingsoftgames/xapkreader/XAPKDownloaderActivity.java:17: error: package android.support.v4.content does not exist import android.support.v4.content.LocalBroadcastManager; ^ /Users/johnfriedman/dev/family-portal-native/platforms/android/app/src/main/java/com/flyingsoftgames/xapkreader/XAPKDownloaderActivity.java:139: error: cannot find symbol LocalBroadcastManager.getInstance(this).sendBroadcastSync(intent); ^ symbol: variable LocalBroadcastManager location: class XAPKDownloaderActivity /Users/johnfriedman/dev/family-portal-native/platforms/android/app/src/main/java/com/flyingsoftgames/xapkreader/XAPKDownloaderActivity.java:273: error: cannot find symbol LocalBroadcastManager.getInstance(this).sendBroadcastSync(intent); ^ symbol: variable LocalBroadcastManager location: class XAPKDownloaderActivity Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/johnfriedman/dev/family-portal-native/platforms/android/app/src/main/java/org/apache/cordova/file/AssetFilesystem.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 3 errors

FAILURE: Build failed with an exception.

BUILD FAILED in 1s 46 actionable tasks: 1 executed, 45 up-to-date /Users/johnfriedman/dev/family-portal-native/platforms/android/gradlew: Command failed with exit code 1 Error output: /Users/johnfriedman/dev/family-portal-native/platforms/android/app/src/main/java/com/flyingsoftgames/xapkreader/XAPKDownloaderActivity.java:17: error: package android.support.v4.content does not exist import android.support.v4.content.LocalBroadcastManager; ^ /Users/johnfriedman/dev/family-portal-native/platforms/android/app/src/main/java/com/flyingsoftgames/xapkreader/XAPKDownloaderActivity.java:139: error: cannot find symbol LocalBroadcastManager.getInstance(this).sendBroadcastSync(intent); ^ symbol: variable LocalBroadcastManager location: class XAPKDownloaderActivity /Users/johnfriedman/dev/family-portal-native/platforms/android/app/src/main/java/com/flyingsoftgames/xapkreader/XAPKDownloaderActivity.java:273: error: cannot find symbol LocalBroadcastManager.getInstance(this).sendBroadcastSync(intent); ^ symbol: variable LocalBroadcastManager location: class XAPKDownloaderActivity Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/johnfriedman/dev/family-portal-native/platforms/android/app/src/main/java/org/apache/cordova/file/AssetFilesystem.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 3 errors

FAILURE: Build failed with an exception.

BUILD FAILED in 1s `

agamemnus commented 4 years ago

They keep deprecating everything... But shouldn't this be in a new thread?

erobertson42 commented 4 years ago

@Johnafriedman, I'm sorry, but I don't know how much help I can be without knowing more about your setup. However I can say that I never had to explicitly install the android.support plugin, or manually add any support dependencies to any config file(s).

Although I do have the "Android Support Repository" package installed in Android Studio, you could check to see if you have that as well. I'm not sure if it will help, but it's worth a try. I'll admit I'm fairly new to Cordova and Android development in general.

SDK Manager -> SDK Tools tab -> Support Repository

android_support

Johnafriedman commented 4 years ago

Thanks for your response and suggestion. I am new to this and wasn't sure if I should open an issue in the forked repo.

I was able to build successfully by replacing {Project}/plugins/com.flyingsoftgames.xapkreader/src/android/XAPKDownloaderActivity.java:17 import androidx.localbroadcastmanager.content.LocalBroadcastManager; with import android.support.v4.content.LocalBroadcastManager;

agamemnus commented 4 years ago

Very good. Teamwork makes the dream work!

renzoolguin commented 4 years ago

@Johnafriedman I'll take a look at it and update as necessary. I currently have an Android Support issue with Crosswalk, so I'm trying to work out anything related to that. Which minimum Android Support version are you targeting?

Johnafriedman commented 4 years ago

@renzoolguin I'm afraid I don't know enough to be sure I understand the question.

I am using

    "cordova": "^9.0.0",
    "cordova-android": "^8.0.0",

My Android Studio > Preferences > System Settings > Android SDK | SDK Tools |

Android Support Library shows rev. 23.2.1 Support Repository | Android Support Repository shows version 47.0.0

My cordova project config.xml has these preferences:

    <preference name="android-minSdkVersion" value="19" />
    <preference name="android-targetSdkVersion" value="29" />