Search code examples
cordovanpmphonegap-pluginscordova-plugins

Phonegap diagnostic plugin not working


I am trying to use Phonegap plugin diagnostic but it does not work. Here is how I add it in my cnfig.xml

<widget 
xmlns="http://www.w3.org/ns/widgets" 
xmlns:gap="http://phonegap.com/ns/1.0" 
id="com.crondale.tippnett" 
version="1.1.10">
<name>TippNett</name>
<description>TippNett er et system for å som bidrar til bedre massebalanse.   Systemet finner anlegg i nærheten med motsatt massebehov. Det bidrar til kortere kjørelengde og raskere anleggsutførsel. Du sparer penger, i tillegg til at miljøet blir spart for CO2 utslipp.</description>
<author href="http://www.crondale.com" email="[email protected]">Crondale</author>
<content src="index.html" />
<access origin="*" />
<preference name="SplashScreen" value="screen" />
<preference name="windows-target-version" value="8.0" />
<preference name="windows-phone-target-version" value="8.1" />
<preference name="target-device" value="universal" />

<platform name="android">
    <preference name="orientation" value="portrait" />
    <preference name="android-build-tool" value="gradle" />
</platform>

<platform name="ios">
    <preference name="orientation" value="portrait" />
</platform>

<gap:plugin name="cordova-plugin-whitelist" source="npm" version="1.0.0" />
<gap:plugin name="cordova-plugin-device" source="npm" version="1.0.1" />
<gap:plugin name="cordova-plugin-inappbrowser" source="npm" version="1.0.1" />
<gap:plugin name="cordova-plugin-network-information" source="npm" version="1.2.1" />
<gap:plugin name="cordova-plugin-geolocation" source="npm"/>


// here I add it
<gap:plugin name="cordova.plugins.diagnostic" source="npm" />


  ....
</widget>

Here is my code in index.js

function onDeviceReady() {
         // Handle the Cordova pause and resume events

         alert(cordova.plugins); // I get un-define here
        cordova.plugins.diagnostic.isLocationEnabledSetting(function(enabled){
            alert(11);
        if(enabled)
        {
            alert("Location Setting is enabled");
        }
        else
        {
            alert("Location Setting is disabled");
        }
    }, function(error){
        alert("The following error occurred: "+error);
    });

I have tried it both on android and on ios as well. But I get the same result in both of them.

This is in my build log

Build Date: 2016-06-06 07:18:09 +0000
  Build option --'' not recognized (ignoring).
  Running: /project/gradlew cdvBuildRelease -b /project/build.gradle -Dorg.gradle.daemon=true -PcdvBuildMultipleApks=false
  :preBuild
  :compileReleaseNdk
  :preReleaseBuild
  :checkReleaseManifest
  :preDebugBuild
  :CordovaLib:compileLint
  :CordovaLib:copyDebugLint UP-TO-DATE
  :CordovaLib:mergeDebugProguardFiles
  :CordovaLib:preBuild
  :CordovaLib:preDebugBuild
  :CordovaLib:checkDebugManifest
  :CordovaLib:prepareDebugDependencies
  :CordovaLib:compileDebugAidl
  :CordovaLib:compileDebugRenderscript
  :CordovaLib:generateDebugBuildConfig
  :CordovaLib:generateDebugAssets UP-TO-DATE
  :CordovaLib:mergeDebugAssets
  :CordovaLib:generateDebugResValues
  :CordovaLib:generateDebugResources
  :CordovaLib:packageDebugResources
  :CordovaLib:processDebugManifest
  :CordovaLib:processDebugResources
  :CordovaLib:generateDebugSources
  :CordovaLib:compileDebugJavaNote: Some input files use or override a deprecated API.
  Note: Recompile with -Xlint:deprecation for details.

  :CordovaLib:processDebugJavaRes UP-TO-DATE
  :CordovaLib:packageDebugJar
  :CordovaLib:compileDebugNdk
  :CordovaLib:packageDebugJniLibs UP-TO-DATE
  :CordovaLib:packageDebugLocalJar UP-TO-DATE
  :CordovaLib:packageDebugRenderscript UP-TO-DATE
  :CordovaLib:bundleDebug
  :CordovaLib:copyReleaseLint UP-TO-DATE
  :CordovaLib:mergeReleaseProguardFiles
  :CordovaLib:preReleaseBuild
  :CordovaLib:checkReleaseManifest
  :CordovaLib:prepareReleaseDependencies
  :CordovaLib:compileReleaseAidl
  :CordovaLib:compileReleaseRenderscript
  :CordovaLib:generateReleaseBuildConfig
  :CordovaLib:generateReleaseAssets UP-TO-DATE
  :CordovaLib:mergeReleaseAssets
  :CordovaLib:generateReleaseResValues
  :CordovaLib:generateReleaseResources
  :CordovaLib:packageReleaseResources
  :CordovaLib:processReleaseManifest
  :CordovaLib:processReleaseResources
  :CordovaLib:generateReleaseSources
  :CordovaLib:compileReleaseJavaNote: Some input files use or override a deprecated API.
  Note: Recompile with -Xlint:deprecation for details.

  :CordovaLib:processReleaseJavaRes UP-TO-DATE
  :CordovaLib:packageReleaseJar
  :CordovaLib:compileReleaseNdk
  :CordovaLib:packageReleaseJniLibs UP-TO-DATE
  :CordovaLib:packageReleaseLocalJar UP-TO-DATE
  :CordovaLib:packageReleaseRenderscript UP-TO-DATE
  :CordovaLib:bundleRelease
  :prepareComAndroidSupportAnimatedVectorDrawable2340Library
  :prepareComAndroidSupportAppcompatV72340Library
  :prepareComAndroidSupportSupportV42340Library
  :prepareComAndroidSupportSupportVectorDrawable2340Library
  :prepareProjectCordovaLibUnspecifiedReleaseLibrary
  :prepareReleaseDependencies
  :compileReleaseAidl
  :compileReleaseRenderscript
  :generateReleaseBuildConfig
  :generateReleaseAssets UP-TO-DATE
  :mergeReleaseAssets
  :generateReleaseResValues
  :generateReleaseResources
  :mergeReleaseResources
  :processReleaseManifest
  :processReleaseResources/project/build/intermediates/res/release/values-v23/values.xml:6: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.

  /project/build/intermediates/res/release/values-v23/values.xml:35: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.

   FAILED

  FAILURE: Build failed with an exception.

  * What went wrong:
  Execution failed for task ':processReleaseResources'.
  > com.android.ide.common.internal.LoggedErrorException: Failed to run command:
        /android-sdk/build-tools/23.0.1/aapt package -f --no-crunch -I /android-sdk/platforms/android-22/android.jar -M /project/build/intermediates/manifests/full/release/AndroidManifest.xml -S /project/build/intermediates/res/release -A /project/build/intermediates/assets/release -m -J /project/build/generated/source/r/release -F /project/build/intermediates/res/resources-release.ap_ --custom-package com.crondale.tippnett -0 apk --output-text-symbols /project/build/intermediates/symbols/release
    Error Code:
        1
    Output:
        /project/build/intermediates/res/release/values-v23/values.xml:6: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.

        /project/build/intermediates/res/release/values-v23/values.xml:35: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.



  * 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: 8.513 secs

  /project/cordova/node_modules/q/q.js:126
                      throw e;
                      ^
  Error code 1 for command: /project/gradlew with args: cdvBuildRelease,-b,/project/build.gradle,-Dorg.gradle.daemon=true,-PcdvBuildMultipleApks=false

Solution

  • As mentioned in the official diagnostic plugin page, if you are using Android API version 22 or lower (which is true in your case), you should use the legacy branch of the plugin (cordova.plugins.diagnostic.api-22) instead of main branch.

    The excerpt from the plugin page is as follows:

    For users who wish to build against API 22 or below, there is a branch of the plugin repo which contains all the functionality except Android 6 runtime permissions. This removes the dependency on API 23 and will allow you to build against legacy API versions (22 and below).

    The legacy branch is published to npm as cordova.plugins.diagnostic.api-22, so you'll need to use this plugin ID when adding it:

    cordova plugin add cordova.plugins.diagnostic.api-22
    

    This reolsves the issue in Android API 22 and below.