Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error installing plugin #11

Closed
rolinger opened this issue Jul 16, 2016 · 10 comments
Closed

Error installing plugin #11

rolinger opened this issue Jul 16, 2016 · 10 comments

Comments

@rolinger
Copy link

rolinger commented Jul 16, 2016

I have Google Repository 31 and Google Play Services 31 installed.

C:\Users\RPO\dev\myApp\platforms\android\src\cordova\plugin\RequestLocationAccuracy.java:310: error: cannot find symbol
LocationServices.SettingsApi.checkLocationSettings(
^
symbol: variable SettingsApi
location: class LocationServices
C:\Users\RPO\dev\myApp\platforms\android\src\cordova\plugin\RequestLocationAccuracy.java:450: error: cannot find symbol
case ConnectionResult.SERVICE_MISSING_PERMISSION:
^
symbol: variable SERVICE_MISSING_PERMISSION
location: class ConnectionResult
C:\Users\RPO\dev\myApp\platforms\android\src\cordova\plugin\RequestLocationAccuracy.java:453: error: cannot find symbol
case ConnectionResult.SERVICE_UPDATING:
^
symbol: variable SERVICE_UPDATING
location: class ConnectionResult
C:\Users\RPO\dev\myApp\platforms\android\src\cordova\plugin\RequestLocationAccuracy.java:459: error: cannot find symbol
case ConnectionResult.SIGN_IN_FAILED:
^
symbol: variable SIGN_IN_FAILED
location: class ConnectionResult
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\RPO\dev\myApp\platforms\android\src\org\apache\cordova\file\AssetFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors
FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':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.

BUILD FAILED

Total time: 51.527 secs
ERROR building one of the platforms: Error code 1 for command: cmd with args: /s,/c,"C:\Users\RPO\dev\myApp\platforms\android\gradlew cdv
BuildDebug -b C:\Users\RPO\dev\myApp\platforms\android\build.gradle -Dorg.gradle.daemon=true -Pandroid.useDeprecatedNdk=true"
You may not have the required environment or OS to build this project
Error: Error code 1 for command: cmd with args: /s,/c,"C:\Users\RPO\dev\myApp\platforms\android\gradlew cdvBuildDebug -b C:\Users\RPO\dev
\myApp\platforms\android\build.gradle -Dorg.gradle.daemon=true -Pandroid.useDeprecatedNdk=true"

C:\Users\RPO\dev\myApp>cordova plugin add https://github.com/wf9a5m75/google-play-services#v23
Fetching plugin "https://github.com/wf9a5m75/google-play-services" via git clone
Repository "https://github.com/wf9a5m75/google-play-services" checked out to git ref "v23".
Notice: com.google.playservices has been automatically converted to cordova-plugin-googleplayservices and fetched from npm. This is due to o
ur old plugins registry shutting down.
Plugin "cordova-plugin-googleplayservices" already installed on android.

C:\Users\RPO\dev\myApp>cordova plugin
br.com.dtmtec.plugins.carrier 1.0.0 "Carrier"
cl.rmd.cordova.dialoggps 0.0.2 "DialogGPS"
com.google.playservices 23.0.0 "Google Play Services for Android"
com.ionic.keyboard 1.0.4 "Keyboard"
com.lampa.startapp 0.1.4 "startApp"
com.ludei.webview.plus 2.4.3 "Webview+"
com.phonegap.plugins.nativesettingsopener 1.0 "Native settings"
com.vliesaputra.deviceinformation 1.0.1 "DeviceInformation"
cordova-plugin-appavailability 0.4.2 "AppAvailability"
cordova-plugin-apprate 1.1.7 "AppRate"
cordova-plugin-console 1.0.2 "Console"
cordova-plugin-device 1.1.2 "Device"
cordova-plugin-device-motion 1.2.0 "Device Motion"
cordova-plugin-device-orientation 1.0.2 "Device Orientation"
cordova-plugin-dialogs 1.2.0 "Notification"
cordova-plugin-email 1.1.1 "EmailComposer"
cordova-plugin-fastrde-checkgps 1.0.0 "checkGPS"
cordova-plugin-file 4.1.1 "File"
cordova-plugin-geolocation 2.1.0 "Geolocation"
cordova-plugin-globalization 1.0.2 "Globalization"
cordova-plugin-googleplayservices 19.0.3 "Google Play Services for Android"
cordova-plugin-inappbrowser 1.2.1 "InAppBrowser"
cordova-plugin-request-location-accuracy 1.0.3 "Request Location Accuracy"
cordova-plugin-splashscreen 3.1.0 "Splashscreen"
cordova-plugin-statusbar 2.1.1 "StatusBar"
cordova-plugin-vibration 2.1.0 "Vibration"
cordova-plugin-whitelist 1.2.1 "Whitelist"
cordova-sqlite-storage 0.8.2 "Cordova sqlite storage plugin (core version)"
cordova-universal-links-plugin 1.1.2 "Universal Links Plugin"
cordova.plugins.diagnostic.api-22 2.3.10-api-22 "Diagnostic"
phonegap-facebook-plugin 0.12.0 "Facebook Connect"

@dpa99c
Copy link
Owner

dpa99c commented Jul 17, 2016

I can see two potential issues:

Firstly (this is the most likely cause), you are including cordova-plugin-googleplayservices (as com.google.playservices) which contains the Google Play Services library as a JAR file. This is an outdated method of including libraries, dating from when Android builds were driven by Ant.

Android and Cordova now use Gradle for the build process. Gradle is able to dynamically merge dependencies, leading to less problems with dependency clashes.

This plugin uses the Gradle method to include the Google Play Services Location library.

Unless you have a good reason to include cordova-plugin-googleplayservices, then remove it as it is likely causing a collision with the Gradle version of Google Play Services, resulting in your observed error. Any plugins which depend on Google Play Services should now be using the Gradle method to resolve the dependency.

Secondly, you are including the API 22 version of cordova.plugins.diagnostic - cordova.plugins.diagnostic.api-22. Is this because you are building against API 22? You can check what version of the cordova-android platform is installed using cordova platform ls. If the version is less than 5.0.0, then the cordova-android version you have installed is for API 22 or below. But since you are building using a recent version of Google Play Services (v31), this may cause an issue. So if your version of cordova-android is less than 5.0.0, I recommend installing the latest version:

cordova platform rm android && cordova platform add android@latest

I recommend building and running the example project to confirm that your build environment is setup correctly to make use of this plugin.

@rolinger
Copy link
Author

Interesting. Yes, I did add cordova-plugin-googleplayservices - the link you provided shows they are now on r26. I have not used the gradle method as thus far all plugins required for my app have been successful via the standard cordova plugin add method. I will try the gradle method above and see if I can get this working.

Installed platforms are: android 5.1.1.

Question, concerning iOS, the above plugin is for Android only, but how will the plugins react on iOS...will it default back to the cordova.plugins.diagnostic.switchToLocationSettings(); and direct the user to their setting screen?

@dpa99c
Copy link
Owner

dpa99c commented Jul 17, 2016

Cordova/Phonegap has been using Gradle by default since v4.0.0 (see here). It is up to the plugin author to make use of this feature - you as a plugin user just add the plugin in the standard way and Cordova will take care of the Gradle dependency resolution.

As far as iOS is concerned, there is no equivalent functionality that this plugin can make use of, so you'll need some conditional platform-specific behaviour to handle this. Either you can use cordova-plugin-device to perform the conditional inline, for example:

function handleLocationOff(){
    if(device.platform == "iOS"){
        cordova.plugins.diagnostic.switchToLocationSettings(); 
    }else if(device.platform == "Android"){
        cordova.plugins.locationAccuracy.request(successCallback, errorCallback, accuracy)
    }
}

Or make use of merges:

/merges/ios/platform.js:

function handleLocationOff(){
    cordova.plugins.diagnostic.switchToLocationSettings(); 
}

/merges/android/platform.js:

function handleLocationOff(){
    cordova.plugins.locationAccuracy.request(successCallback, errorCallback, accuracy)
}

www/index.html:

...
<script type="text/javascript" src="platform.js"></script>
...

@rolinger
Copy link
Author

thanks. I will look into this. However, I copied my whole project into a new directory and then updated the platform and all the SDKs (via Android Studio), I also added support for Adroid v4 and now I am getting build errors (mostly related to v4). The original build directory is still working fine. I won't mess with the original until I know the copied app is building cleanly.

/myOrigApp - works fine after all SDKs updated.
/myCopiedApp - getting the below errors.

I 'think' I fixed the first build error: Error 1:
Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$Acces
sibilityServiceInfoVersionImpl;

by adding to the platform\adroid\build.gradle file:

defaultConfig {
        multiDexEnabled true
}

but am now getting Error 2.
Execution failed for task ':transformClassesWithJarMergingForDebug'.

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/util/TimeUtils.class

Still researching this one, but thinking it has to do with extra v4 build files or need to delete the v4 folders because gradle is installing them even though not defined in the gralde (that I can see).

@dpa99c
Copy link
Owner

dpa99c commented Jul 18, 2016

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/util/TimeUtils.class

This is almost certainly being caused by multiple instances of the Android v4 support library being included.

Looking at the plugins you have installed, phonegap-facebook-plugin 0.12.0 "Facebook Connect" includes it as a JAR.

Although you have specified cordova.plugins.diagnostic.api-22 2.3.10-api-22 "Diagnostic" - the version for API 22, have you now switched to using the main version of this plugin (i.e. cordova.plugins.diagnostic 3.1.1 "Diagnostic")?
Because, while the API 22 branch does not include the Android v4 support library, the main version does include it via Gradle. If so, this would explain the collision.

Otherwise, it's likely another of your included plugins is either specifying the Android v4 support library as a Gradle dependency or including it directly as a JAR file (like the Facebook plugin).

The Facebook plugin really needs to be updated to use Gradle as the use of this JAR file will cause collisions with any other plugins making use of the Android v4 support library - it seems other people are experiencing similar issues see here.

Here are a few things you can try:

From here:

  • Try deleting the android-support-v4.jar from the platforms/android/FacebookLib/libs/ directory (and/or any other android-support-v4.jar you see in platforms/android).
  • Create the file platforms/android/build-extras.gradle with contents configurations { all*.exclude group: 'com.android.support', module: 'support-v4' }

From here:

Edit plugins/com.phonegap.plugins.facebookConnect and replace the line:

<framework src="platforms/android/FacebookLib" custom="true" />

with

<framework src="com.android.support:support-v4:+" />
<framework src="com.facebook.android:facebook-android-sdk:3.23.0" />

Remove and re-add the platform:

cordova platform rm android && cordova platform add android@latest

Personally, I would choose the last option, but I'd also consider forking the Facebook plugin Github repo and apply these changes to my fork, then installing my forked plugin to my local project to avoid losing these local changes if your /plugins folder is removed for some reason:

cordova plugin add https://github.com/your_account/phonegap-facebook-plugin.git --save

@rolinger
Copy link
Author

rolinger commented Jul 18, 2016

dpa99c - thank you. You are quite thorough and I can't tell you how much I appreciate that. I will apply everything you advised above and get back with the results. I will step through them until success and update with what the exact combo for success was.

The new copied build also has updated plugins, not using the diagnostic-api-22 anymore.

br.com.dtmtec.plugins.carrier 1.0.0 "Carrier"
cl.rmd.cordova.dialoggps 0.0.2 "DialogGPS"
com.lampa.startapp 0.1.4 "startApp"
com.ludei.webview.plus 2.4.3 "Webview+"
com.phonegap.plugins.nativesettingsopener 1.0 "Native settings"
com.vliesaputra.deviceinformation 1.0.1 "DeviceInformation"
cordova-plugin-appavailability 0.4.2 "AppAvailability"
cordova-plugin-apprate 1.1.7 "AppRate"
cordova-plugin-compat 1.0.0 "Compat"
cordova-plugin-console 1.0.3 "Console"
cordova-plugin-device 1.1.2 "Device"
cordova-plugin-device-motion 1.2.1 "Device Motion"
cordova-plugin-device-orientation 1.0.3 "Device Orientation"
cordova-plugin-dialogs 1.2.1 "Notification"
cordova-plugin-email 1.1.1 "EmailComposer"
cordova-plugin-fastrde-checkgps 1.0.0 "checkGPS"
cordova-plugin-file 4.1.1 "File"
cordova-plugin-geolocation 2.1.0 "Geolocation"
cordova-plugin-globalization 1.0.3 "Globalization"
cordova-plugin-inappbrowser 1.2.1 "InAppBrowser"
cordova-plugin-splashscreen 3.1.0 "Splashscreen"
cordova-plugin-statusbar 2.1.3 "StatusBar"
cordova-plugin-vibration 2.1.1 "Vibration"
cordova-plugin-whitelist 1.2.2 "Whitelist"
cordova-sqlite-storage 1.4.5 "Cordova sqlite storage plugin"
cordova-universal-links-plugin 1.1.2 "Universal Links Plugin"
cordova.plugins.diagnostic 3.1.1 "Diagnostic"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-facebook-plugin 0.12.0 "Facebook Connect"

The only remaining plugin is google-play-services. But there are like 3 or 4 versions out there and I am not certain which one I should be installing.

@rolinger
Copy link
Author

The first "from here" did not work. the facebook plugin def required the v4.jar.

However, the 2nd 'from here' DID work. After I removed and readd the platform android though the previous build-extras.gradle file was wiped out....thus the 2nd solution worked completely on its own:

Edit plugins/com.phonegap.plugins.facebookConnect and replace the line:

<framework src="platforms/android/FacebookLib" custom="true" />
with

<framework src="com.android.support:support-v4:+" />
<framework src="com.facebook.android:facebook-android-sdk:3.23.0" />

It compiled and thus far everything looks to be working cleanly. Which makes me very excited, because now my app is fully compatible from anything Android 4.0 and forward.

To this point I have not added cordova-plugin-request-location-accuracy. I needed to get everything working with v4 and all my previous plugins.

I just now added cordova-plugin-request-location-accuracy and the build worked. During the build I see:

:prepareComFacebookAndroidFacebookAndroidSdk3230Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesBase921Library
:prepareComGoogleAndroidGmsPlayServicesBasement921Library
:prepareComGoogleAndroidGmsPlayServicesLocation921Library
:prepareComGoogleAndroidGmsPlayServicesTasks921Library

So it looks like the new gradle process is taking everything much cleaner now....the actual build console messages are about 1/3 as long as the previous non-gradle builds too.

Going to try and implement the auto-gps now. Will post results.

TTHHAANNKK YYOOUU! Where do I send the 6 pack of beer too? :-)

@dpa99c
Copy link
Owner

dpa99c commented Jul 18, 2016

Glad you got it working :-)

I will post the relevant parts of this thread in answer to your stackoverflow question so any other poor souls suffering this misery can benefit from this discussion!

@rolinger
Copy link
Author

...and lastly. Added the gps enable and it works like a charm. Wish iOS had a method that could be incorporated into this plugin. It is a much cleaner behavior than defaulting to the user settings for them to manually turn it on.

@dpa99c
Copy link
Owner

dpa99c commented Jul 18, 2016

Regarding an equivalent iOS method, it is technically possible to display such a dialog in iOS, but only by actually requesting a position while location services is turned off. However, because cordova-plugin-geolocation checks location services is on before requesting any positions, you can't use the official geolocation plugin to do it.

It's something I've vaguely considered adding as an iOS implementation of this plugin (i.e. simply directly requesting a position if location services is OFF), but it does seem a bit of a hack to workaround the non-ideal behaviour of cordova-plugin-geolocation.

See the first part of this issue thread and this Cordova issue for more.

@dpa99c dpa99c closed this as completed Jul 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants