dpa99c / phonegap-launch-navigator

Phonegap/Cordova plugin which launches native route navigation apps for Android, iOS and Windows
369 stars 131 forks source link

Conflict with cordova-hot-code-push-local-dev-addon #193

Closed alirezamirian closed 6 years ago

alirezamirian commented 6 years ago

I'm submitting a ... (check one with "x"):

Bug report

Current behavior: If both plugins are added, build fails. It seems it's a version clash of OkHttp

Expected behavior: Successful build

Steps to reproduce:

Environment information

cordova-hot-code-push-plugin 1.5.3 "Hot Code Push Plugin"

cordova-plugin-actionsheet 2.3.3 "ActionSheet"

cordova-plugin-camera 2.3.1 "Camera"

cordova-plugin-compat 1.2.0 "Compat"

cordova-plugin-customurlscheme 4.2.0 "Custom URL scheme"

cordova-plugin-device 2.0.2 "Device"

cordova-plugin-dialogs 2.0.1 "Notification"

cordova-plugin-file 4.3.3 "File"

cordova-plugin-geolocation 2.4.3 "Geolocation"

cordova-plugin-inappbrowser 1.6.1 "InAppBrowser"

cordova-plugin-splashscreen 4.0.3 "Splashscreen"

cordova-plugin-statusbar 2.2.3 "StatusBar"

cordova-plugin-whitelist 1.3.2 "Whitelist"

ionic-plugin-keyboard 2.2.1 "Keyboard"

nl.madebymark.share 0.1.1 "Share"

onesignal-cordova-plugin 2.1.2 "OneSignal Push Notifications"

uk.co.workingedge.phonegap.plugin.launchnavigator 4.2.0 "Launch Navigator"

console output FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: okhttp3/internal/ws/RealWebSocket$1.class * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 6.16 secs Error: Command failed with exit code 1 Error output: Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Recompile with -Xlint:unchecked for details. FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: okhttp3/internal/ws/RealWebSocket$1.class
dpa99c commented 6 years ago

Looking at the plugin.xml and gradle config file for cordova-hot-code-push-local-dev-addon, it doesn't directly depend on the OKHTTP library.

So it's possibly a downstream dependency of the socket.io-client library that plugin uses. You can try to manually edit platforms/android/build.gradle and manually align the version numbers.

In the next release, I will add a plugin variable to make to the OKHTTP library version requested by this plugin configurable, but you'd still need to know what version to set it to (i.e. what is being requested by the other plugin).

dpa99c commented 6 years ago

Fix published in v4.2.1

alirezamirian commented 6 years ago

Thanks for your quick response and fix. However it seems something is missing in the fix. After following your instruction, I'm getting the following error from cordova build android:

Could not get unknown property 'OKHTTP_VERSION' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

I created a project from scratch and added this plugin and the same error occurred.

It seems the variable OKHTTP_VERSION is missing in the gradle file. When I add it manually by adding the following line in gradle.build, it builds successfully:

ext.OKHTTP_VERSION = '1.2.3'
dpa99c commented 6 years ago

It seems to work fine when I tested it - see console output below.

console output ``` $ cordova -v 8.0.0 $ cordova create test && cd test Creating a new cordova project. $ cordova platform add android@latest Using cordova-fetch for cordova-android@latest Adding android project... Creating Cordova project for the Android platform: Path: platforms\android Package: io.cordova.hellocordova Name: HelloCordova Activity: MainActivity Android target: android-27 Subproject Path: CordovaLib Subproject Path: app Android project created with cordova-android@7.1.0 Android Studio project detected Android Studio project detected Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the project Installing "cordova-plugin-whitelist" for android This plugin is only applicable for versions of cordova-android greater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in. Adding cordova-plugin-whitelist to package.json Saved plugin info for "cordova-plugin-whitelist" to config.xml --save flag or autosave detected Saving android@latest into config.xml file ... $ cordova plugin add uk.co.workingedge.phonegap.plugin.launchnavigator --variable OKHTTP_VERSION=3.10.0 Installing "uk.co.workingedge.phonegap.plugin.launchnavigator" for android Installing "cordova-plugin-actionsheet" for android Android Studio project detected Installing "cordova-plugin-dialogs" for android Subproject Path: CordovaLib Subproject Path: app Adding uk.co.workingedge.phonegap.plugin.launchnavigator to package.json Saved plugin info for "uk.co.workingedge.phonegap.plugin.launchnavigator" to config.xml $ more platforms/android/app/build.gradle | grep okhttp compile "com.squareup.okhttp3:okhttp:3.10.0" $ cordova build android Android Studio project detected ANDROID_HOME=G:\Users\dpa99\AppData\Local\Android\sdk JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161 studio Picked up _JAVA_OPTIONS: -Xms256m -Xmx4096m BUILD SUCCESSFUL in 1s 1 actionable task: 1 executed Subproject Path: CordovaLib Subproject Path: app publishNonDefault is deprecated and has no effect anymore. All variants are now published. The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead. at build_3c73skfualp0fpq2g3nwd1gno.run(D:\Temp\test\platforms\android\app\build.gradle:143) (Run with --stacktrace to get the full stack trace of this deprecation warning.) Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead. :CordovaLib:preBuild UP-TO-DATE :CordovaLib:preDebugBuild UP-TO-DATE :CordovaLib:compileDebugAidl :CordovaLib:compileDebugRenderscript :CordovaLib:checkDebugManifest :CordovaLib:generateDebugBuildConfig :CordovaLib:prepareLintJar :CordovaLib:generateDebugResValues :CordovaLib:generateDebugResources :CordovaLib:packageDebugResources :CordovaLib:platformAttrExtractor :CordovaLib:processDebugManifest :CordovaLib:javaPreCompileDebug :CordovaLib:processDebugJavaRes NO-SOURCE :app:preBuild UP-TO-DATE :app:preDebugBuild :app:compileDebugAidl :CordovaLib:packageDebugRenderscript NO-SOURCE :app:compileDebugRenderscript :app:checkDebugManifest :app:generateDebugBuildConfig :app:prepareLintJar :app:generateDebugResValues :app:generateDebugResources :app:mergeDebugResources :app:createDebugCompatibleScreenManifests :app:processDebugManifest :app:splitsDiscoveryTaskDebug :app:compileDebugNdk NO-SOURCE :CordovaLib:mergeDebugShaders :CordovaLib:compileDebugShaders :CordovaLib:generateDebugAssets :CordovaLib:mergeDebugAssets :app:mergeDebugShaders :app:compileDebugShaders :app:generateDebugAssets :app:mergeDebugAssets :CordovaLib:compileDebugNdk NO-SOURCE :CordovaLib:mergeDebugJniLibFolders :CordovaLib:transformNativeLibsWithMergeJniLibsForDebug :CordovaLib:transformNativeLibsWithStripDebugSymbolForDebug :CordovaLib:transformNativeLibsWithIntermediateJniLibsForDebug :app:mergeDebugJniLibFolders :app:processDebugJavaRes NO-SOURCE :app:validateSigningDebug :CordovaLib:processDebugResources :CordovaLib:generateDebugSources :CordovaLib:compileDebugJavaWithJavacNote: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. :CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug :app:processDebugResources :app:generateDebugSources :app:javaPreCompileDebug :app:compileDebugJavaWithJavacNote: D:\Temp\test\platforms\android\app\src\main\java\org\apache\cordova\dialogs\Notification.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. :app:compileDebugSources :app:transformClassesWithStackFramesFixerForDebug :app:transformClassesWithDesugarForDebug :app:transformClassesWithDexBuilderForDebug :app:transformDexArchiveWithExternalLibsDexMergerForDebug :app:transformDexArchiveWithDexMergerForDebug :app:transformNativeLibsWithMergeJniLibsForDebug :app:transformNativeLibsWithStripDebugSymbolForDebug :app:transformResourcesWithMergeJavaResForDebug :app:packageDebug :app:assembleDebug :app:cdvBuildDebug BUILD SUCCESSFUL in 9s 48 actionable tasks: 48 executed Built the following apk(s): D:\Temp\test\platforms\android\app\build\outputs\apk\debug\app-debug.apk $ ```
alirezamirian commented 6 years ago

So, most probably this is related to cordova version. Because I'm using cordova 6.5.0 and it fails to build.

Build output ``` alireza@alireza-pc:/e$ cordova -v 6.5.0 alireza@alireza-pc:/e$ cordova create test && cd test Creating a new cordova project. alireza@alireza-pc:/e/test$ cordova platform add android@latest Adding android project... Creating Cordova project for the Android platform: Path: platforms/android Package: io.cordova.hellocordova Name: HelloCordova Activity: MainActivity Android target: android-27 Subproject Path: CordovaLib Subproject Path: app Android project created with cordova-android@7.1.0 Android Studio project detected Android Studio project detected Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the project Fetching plugin "cordova-plugin-whitelist@1" via npm Installing "cordova-plugin-whitelist" for android This plugin is only applicable for versions of cordova-android greater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in. alireza@alireza-pc:/e/test$ cordova plugin add uk.co.workingedge.phonegap.plugin.launchnavigator --variable OKHTTP_VERSION=3.10.0 Fetching plugin "uk.co.workingedge.phonegap.plugin.launchnavigator" via npm Installing "uk.co.workingedge.phonegap.plugin.launchnavigator" for android Fetching plugin "cordova-plugin-actionsheet" via npm Installing "cordova-plugin-actionsheet" for android Android Studio project detected Fetching plugin "cordova-plugin-dialogs" via npm Installing "cordova-plugin-dialogs" for android Subproject Path: CordovaLib Subproject Path: app alireza@alireza-pc:/e/test$ more platforms/android/app/build.gradle | grep okhttp compile "com.squareup.okhttp3:okhttp:$OKHTTP_VERSION" alireza@alireza-pc:/e/test$ cordova build android ``` . . . ``` Error: /e/test/platforms/android/gradlew: Command failed with exit code 1 Error output: 17:55:14.280 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 17:55:14.280 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception. 17:55:14.280 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 17:55:14.280 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Where: 17:55:14.280 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Build file '/e/test/platforms/android/app/build.gradle' line: 262 17:55:14.280 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 17:55:14.281 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong: 17:55:14.281 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] A problem occurred evaluating project ':app'. 17:55:14.281 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Could not get unknown property 'OKHTTP_VERSION' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. 17:55:14.281 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 17:55:14.281 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try: 17:55:14.281 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace. 17:55:14.281 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 17:55:14.281 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at https://help.gradle.org 17:55:14.281 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] 17:55:14.281 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 15s ```

With cordova@6.5.0, in the build.gradle, we have:

compile "com.squareup.okhttp3:okhttp:$OKHTTP_VERSION"

In cordova@8.0.0:

compile "com.squareup.okhttp3:okhttp:3.10.0"
juanmarinelli commented 6 years ago

hello, i use phonegap build and the plugin on IOS build correct, but on ANDROID not found. The error is "Could not get unknown property 'OKHTTP_VERSION' for object of type..." with cli-6.5.0 how can I solve it using phonegap build? Thanks @dpa99c @alirezamirian

dpa99c commented 6 years ago

@juanmarinelli use the latest PGB CLI version cli-6.5.0 is old

juanmarinelli commented 6 years ago

thanks @dpa99c , I solved it using version 8.0.0

alirezamirian commented 6 years ago

I created a before_build hook for solving this issue for cordova@6.x For anyone like me who is enforced to use older versions of cordova:

build-extras.gradle:

ext.OKHTTP_VERSION = '3.0.1'

copy-gradle-extra.js (before_build hook):

/**
 * This hook is ONLY required for cordova@<8.x (or even maybe cordova@<7.x)
 * We can safely remove it when migrated to latest versions of Cordova.
 * More info: https://github.com/dpa99c/phonegap-launch-navigator/issues/193
 * @param ctx
 * @returns {PromiseLike<void>}
 */
module.exports = function (ctx) {
    const fs = ctx.requireCordovaModule('fs');
    const path = ctx.requireCordovaModule('path');
    const deferral = ctx.requireCordovaModule('q').defer();
    const platformRoot = path.join(ctx.opts.projectRoot, 'platforms/android');
    const readStream = fs.createReadStream(__dirname + '/build-extras.gradle');
    const writeStream = fs.createWriteStream(path.join(platformRoot, 'build-extras.gradle'));
    readStream.on('error', deferral.reject);
    writeStream.on('error', deferral.reject);
    writeStream.on('finish', () => {
        console.log('build-extras.gradle copied to android platform')
        deferral.resolve();
    });
    try {
        readStream.pipe(writeStream);
    }
    catch (e) {
        readStream.destroy();
        writeStream.end();
        deferral.reject(e);
    }
    return deferral.promise;
};

copy-gradle-extra.js and build-extras.gradle are assumed to be in the same directory.

In config.xml:

<platform name="android">
    <hook type="before_build" src="path/to/the/hook/copy-gradle-extra.js"/>
</platform>
netvillage commented 6 years ago

I solved it using phonegap build 7.1.0 (rather than 8) from 6.5

cikcoh commented 6 years ago

hello, i use ionic cordova build The error is "Could not get unknown property 'OKHTTP_VERSION' for object of type..."

cordova --v 7.0.0 ionic --v 3.20.0 Thanks

dpa99c commented 6 years ago

@cikcoh try updating to cordova@8.0.0

cikcoh commented 6 years ago

with cordova 8 (node:25064) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CordovaError (node:25064) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

dpa99c commented 6 years ago

There's no indication in that cordova@8 error message that this plugin is the cause