Phonegap诊断插件无法正常工作

时间:2016-06-03 12:10:35

标签: cordova npm phonegap-plugins cordova-plugins

我正在尝试使用Phonegap插件诊断,但它不起作用。以下是我在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="support@crondale.com">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>

这是我在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);
    });

我在android和ios上都试过了。但是我在两者中都得到了相同的结果。

这是我的构建日志

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

1 个答案:

答案 0 :(得分:1)

正如官方诊断插件页面所述,如果您使用的是Android API 22或更低版本(在您的情况下也是如此),您应该使用插件的旧版分支(cordova.plugins.diagnostic.api-22)而不是主分支。

插件页面的摘录如下:

  

对于希望针对API 22或更低版本构建的用户,插件存储库的一个分支包含除Android 6运行时权限之外的所有功能。这消除了对API 23的依赖性,并允许您针对旧版API(22及更低版本)进行构建。

     

旧版分​​支作为cordova.plugins.diagnostic.api-22发布到npm,因此您在添加时需要使用此插件ID:

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

这可以解决Android API 22及以下版本中的问题。