Cordova 插件不起作用 [英] Cordova plugins not working

查看:54
本文介绍了Cordova 插件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑以澄清:您在以下某些文件中看到的 实际上并不是文件的一部分,但它包含我不得不审查的公司名称.

Edit for clarification: The <name> you see in some of the files below is not actually part of the files, but it includes the company name which I had to censor.

测试情况:

  • 科尔多瓦 4
  • OS X 优胜美地
  • Android 4.4 设备(搭配 USB)
  • 使用终端;不是 Eclipse

会发生什么:使用 cordova run --release 成功构建和签署 .apk,移动设备安装和打开它没有问题.但是,没有一个插件工作.例如:

What happens: Using cordova run --release successfully builds and signs the .apk and the mobile device installs and opens it without issues. But, none of the plugins work. For example:

    title.on('click', function() {
        if (!navigator.camera) {
            alert('no camera!');
        } else {
            navigator.camera.getPicture(function success(data) {
            // do something
            }, function error(data) {});
        }
    });

总是提示没有摄像头,这意味着 Cordova 没有将 camera 对象添加到 window.navigator 对象中.

Always alerts that there is no camera, which means Cordova did not add a camera object to the window.navigator object.

以下是关于我的cordova 安装和一些xml 文件的一些信息,据我所知,没有什么不合适的.请注意,不只是相机不工作,我只是以它为例.

Below is some information about my cordova installation and some xml files, as far as I can tell nothing looks out of place. Note that it is not just the camera that does not work, I just used it as an example.

科尔多瓦信息:

Node version: v0.10.29

Cordova version: 4.0.1-nightly.2014.9.29

Config.xml file: 

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.<name>.App" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name><name> Mini</name>
    <description>
        De <name> app voor je telefoon
    </description>
    <author email="stephan@<name>.nl" href="https://<name>.nl">
        Het <name> Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="2000" />
</widget>


Plugins: 

org.apache.cordova.camera,org.apache.cordova.dialogs,org.apache.cordova.file,org.apache.cordova.file-transfer,org.apache.cordova.media,org.apache.cordova.media-capture,org.apache.cordova.splashscreen,org.apache.cordova.vibration

Android platform:

Available Android targets:
----------
id: 1 or "android-19"
     Name: Android 4.4.2
     Type: Platform
     API level: 19
     Revision: 4
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
 Tag/ABIs : default/armeabi-v7a, default/x86

cordova/config.xml

cordova/config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.<name>.App" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name><name> Mini</name>
    <description>
        De <name> app voor je telefoon
    </description>
    <author email="stephan@<name>.nl" href="https://<name>.nl">
        Het <name> Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="2000" />
</widget>

cordova/platforms/android/AndroidManifest.xml<

cordova/platforms/android/AndroidManifest.xml <

?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.kaartje2go.App" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="CordovaApp" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.RECORD_VIDEO" />
    <uses-permission android:name="android.permission.VIBRATE" />
</manifest>

cordova/platforms/android/res/xml/config.xml

cordova/platforms/android/res/xml/config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.<name>.App" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <preference name="loglevel" value="DEBUG" />
    <feature name="Camera">
        <param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
    </feature>
    <feature name="Notification">
        <param name="android-package" value="org.apache.cordova.dialogs.Notification" />
    </feature>
    <feature name="File">
        <param name="android-package" value="org.apache.cordova.file.FileUtils" />
        <param name="onload" value="true" />
    </feature>
    <feature name="FileTransfer">
        <param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
    </feature>
    <feature name="Media">
        <param name="android-package" value="org.apache.cordova.media.AudioHandler" />
    </feature>
    <feature name="Capture">
        <param name="android-package" value="org.apache.cordova.mediacapture.Capture" />
    </feature>
    <feature name="SplashScreen">
        <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
    </feature>
    <feature name="Vibration">
        <param name="android-package" value="org.apache.cordova.vibration.Vibration" />
    </feature>
    <name><name> Mini</name>
    <description>
        De <name> app voor je telefoon
    </description>
    <author email="stephan@<name>.nl" href="https://<name>.nl">
        Het <name> Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="2000" />
</widget>

推荐答案

检查清单:你的插件加载了吗?

Checklist: Is your plugin loaded?

  • 您的 index.html 是否加载了 cordova.js 脚本?(即如果你有 www/index.html 那么你可以只引用 cordova.js.这个文件不在 www 目录中,但是由 Cordova 自动生成并插入到您的应用中)
  • 插件 javascript 是否已加载?使用 Chrome 或 Safari 远程调试您的 android/iOS 应用.
  • cordova plugin ls:您的插件是否已列出?
  • plugins/android.json:您的插件是否已列出?
  • platforms/android/assets/www 有所有文件吗?(即带有脚本的 plugins 文件夹,cordova_plugins.js 应该提到你的插件,一个特定于平台的 cordova.js)
  • Does your index.html load the cordova.js script? (i.e. if you have www/index.html then you can just reference cordova.js. This file is not in the www directory, but automatically generated by Cordova and inserted in your app)
  • Is the plugin javascript loaded? Use Chrome or Safari to remote debug your android/iOS app.
  • cordova plugin ls: Is your plugin listed?
  • plugins/android.json: Is your plugin listed?
  • Does platforms/android/assets/www have all files? (i.e. a plugins folder with scripts, cordova_plugins.js should mention your plugin, a platform-specific cordova.js)

您能否通过监听 deviceready 事件来检查 Cordova 是否完全初始化?(如果所有脚本都到位)

Can you listen to the deviceready event to check if Cordova initializes at all? (If all scripts are in place)

这篇关于Cordova 插件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆