简体   繁体   English

使用Cordova 3.4和Pushwoosh错误构建Android应用

[英]Error build android apps using cordova 3.4 and pushwoosh

First: I used Cordova 3.4 to build android apps, but when I installed PushWoosh to push notification Error build faced me. 首先:我使用Cordova 3.4来构建android应用程序,但是当我安装PushWoosh来推送通知时,错误构建就遇到了我。

1- I installed PushWoosh: cordova plugin add https://github.com/Pushwoosh/pushwoosh-phonegap-3.0-plugin.git 2- PushWoosh code: 1-我安装了PushWoosh:cordova插件添加https://github.com/Pushwoosh/pushwoosh-phonegap-3.0-plugin.git 2- PushWoosh代码:

    function init() {
        document.addEventListener("deviceready", initPushwoosh, true);

        //rest of the code
    }

    function initPushwoosh()
    {
        var pushNotification = window.plugins.pushNotification;

        //set push notifications handler
        document.addEventListener('push-notification', function(event) {
            var title = event.notification.title;
            var userData = event.notification.userdata;

            if (typeof (userData) !== "undefined") {
                console.warn('user data: ' + JSON.stringify(userData));
            }

            navigator.notification.alert(title);
        });

        //initialize Pushwoosh with projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
        pushNotification.onDeviceReady({projectid: "Google_Project_Number", appid: "ID_Of-PushWoosh"});

        //register for pushes
        pushNotification.registerDevice(
                function(status) {
                    var pushToken = status;
                    console.warn('push token: ' + pushToken);
                },
                function(status) {
                    console.warn(JSON.stringify(['failed to register ', status]));
                }
        );
    }

    </script>

3- when build the project using: cordova build android 3-当使用以下项目构建项目时:cordova build android

cordova build android -d
cordova library for "android" already exists. No need to download. Continuing.
Generating config.xml from defaults for platform "android"
Calling plugman.prepare for platform "android"
Preparing android project
Processing configuration changes for plugins.
Iterating over installed plugins: [ 'org.apache.cordova.device',
  'org.apache.cordova.console',
  'org.apache.cordova.camera',
  'org.apache.cordova.geolocation',
  'org.apache.cordova.vibration',
  'org.apache.cordova.splashscreen',
  'org.apache.cordova.media-capture',
  'org.apache.cordova.file-transfer',
  'org.apache.cordova.battery-status',
  'org.apache.cordova.contacts',
  'org.apache.cordova.media',
  'org.apache.cordova.network-information',
  'org.apache.cordova.globalization',
  'org.apache.cordova.device-motion',
  'org.apache.cordova.dialogs',
  'org.apache.cordova.device-orientation',
  'de.appplant.cordova.plugin.background-mode',
  'com.phonegap.plugins.PushPlugin',
  'com.pushwoosh.plugins.pushwoosh',
  'org.apache.cordova.file' ]
Writing out cordova_plugins.js...
Wrote out Android application name to "Insurance"
Wrote out Android package name to "com.coolappz.Insurance"
Running command: /Users/newaccount/projects/Insurance/platforms/android/cordova/build 
Buildfile: /Users/newaccount/projects/Insurance/platforms/android/build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 22.3.0
 [checkenv] Installed at /Users/newaccount/opt/android-sdk

-setup:
 [echo] Project Name: Insurance
  [gettype] Project Type: Application

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 19.0.1
 [echo] Resolving Build Target for Insurance...
[gettarget] Project Target:   Android 4.4.2
[gettarget] API level:        19
 [echo] ----------
  [echo] Creating output directories if needed...
  [echo] ----------
  [echo] Resolving Dependencies for Insurance...
[dependency] Library dependencies:
[dependency] 
[dependency] ------------------
[dependency] Ordered libraries:
[dependency] 
[dependency] ------------------
 [echo] ----------
 [echo] Building Libraries with 'debug'...

nodeps:

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 22.3.0
 [checkenv] Installed at /Users/newaccount/opt/android-sdk

-setup:
  [echo] Project Name: CordovaLib
  [gettype] Project Type: Android Library

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 19.0.1
  [echo] Resolving Build Target for CordovaLib...
[gettarget] Project Target:   Android 4.4.2
[gettarget] API level:        19
  [echo] ----------
  [echo] Creating output directories if needed...
  [echo] ----------
  [echo] Resolving Dependencies for CordovaLib...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency] 
[dependency] ------------------

-code-gen:
[mergemanifest] No changes in the AndroidManifest files.
 [echo] Handling aidl files...
 [aidl] No AIDL files to compile.
 [echo] ----------
 [echo] Handling RenderScript files...
  [echo] ----------
  [echo] Handling Resources...
  [aapt] No changed resources. R.java and Manifest.java untouched.
  [echo] ----------
  [echo] Handling BuildConfig class...
[buildconfig] No need to generate new BuildConfig.

-pre-compile:

-compile:
 [echo] Creating library output jar file...

-post-compile:

-obfuscate:

-dex:
 [echo] Library project: do not convert bytecode...

-crunch:
 [crunch] Crunching PNG Files in source dir:                 /Users/newaccount/projects/Insurance/platforms/android/CordovaLib/res
 [crunch] To destination dir:     /Users/newaccount/projects/Insurance/platforms/android/CordovaLib/ant-build/res
 [crunch] Crunched 0 PNG files to update cache

-package-resources:
 [echo] Library project: do not package resources...

-package:
 [echo] Library project: do not package apk...

-post-package:

-do-debug:
 [echo] Library project: do not create apk...
[propertyfile] Updating property file:     /Users/newaccount/projects/Insurance/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file:     /Users/newaccount/projects/Insurance/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /Users/newaccount/projects/Insurance/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /Users/newaccount/projects/Insurance/platforms/android/CordovaLib/ant-build/build.prop

-post-build:

debug:

-code-gen:
[mergemanifest] Found modified input file
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
 [aidl] No AIDL files to compile.
 [echo] ----------
 [echo] Handling RenderScript files...
  [echo] ----------
 [echo] Handling Resources...
 [aapt] Found modified input file
 [aapt] Generating resource IDs...
  [echo] ----------
  [echo] Handling BuildConfig class...
[buildconfig] No need to generate new BuildConfig.

-pre-compile:
 [echo] Set jars path to: /Users/newaccount/projects/Insurance/platforms/android/CordovaLib/ant-    build/classes.jar:/Users/newaccount/projects/Insurance/platforms/android/libs/gcm.jar:/Users/n    ewaccount/projects/Insurance/platforms/android/libs/android-support-    v13.jar:/Users/newaccount/projects/Insurance/platforms/android/libs/Pushwoosh.jar

-compile:
 [javac] Compiling 3 source files to     /Users/newaccount/projects/Insurance/platforms/android/ant-build/classes

-post-compile:

-obfuscate:

-dex:
 [dex] input: /Users/newaccount/projects/Insurance/platforms/android/ant-build/classes
 [dex] input: /Users/newaccount/projects/Insurance/platforms/android/CordovaLib/ant-    build/classes.jar
[dex] input: /Users/newaccount/projects/Insurance/platforms/android/libs/gcm.jar
 [dex] input: /Users/newaccount/projects/Insurance/platforms/android/libs/android-support-v13.jar
 [dex] input: /Users/newaccount/projects/Insurance/platforms/android/libs/Pushwoosh.jar
 [dex] Using Pre-Dexed classes-e368cee6db5bb9478a5a486c3a854124.jar <-     /Users/newaccount/projects/Insurance/platforms/android/CordovaLib/ant-build/classes.jar
 [dex] Using Pre-Dexed gcm-e0369832eeefafff8956756cd54fc4fc.jar <- /Users/newaccount/projects/Insurance/platforms/android/libs/gcm.jar
  [dex] Using Pre-Dexed android-support-v13-38130f7a5981a081f33db833ecedaa4f.jar <- /Users/newaccount/projects/Insurance/platforms/android/libs/android-support-v13.jar
 [dex] Using Pre-Dexed Pushwoosh-1f9e6f24e222422f2432a7f4365495c2.jar <- /Users/newaccount/projects/Insurance/platforms/android/libs/Pushwoosh.jar
 [dex] Found modified input file
  [dex] Converting compiled files and external libraries into /Users/newaccount/projects/Insurance/platforms/android/ant-build/classes.dex...
 [dx] Merged dex A (124 defs/201.5KiB) with dex B (205 defs/312.8KiB). Result is 329 defs/628.5KiB. Took 0.5s
 [dx] Merged dex A (329 defs/628.5KiB) with dex B (4 defs/18.7KiB). Result is 333 defs/826.4KiB. Took 0.2s
   [dx] Merged dex A (333 defs/826.4KiB) with dex B (324 defs/359.0KiB). Result is 657 defs/1582.4KiB. Took 0.2s
 [dx] 
 [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
 [dx] com.android.dex.DexException: Multiple dex files define     Lcom/google/android/gcm/GCMBaseIntentService;
 [dx]   at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
 [dx]   at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
 [dx]   at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
 [dx]   at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
  [dx]  at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
  [dx]  at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
  [dx]  at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
  [dx]  at com.android.dx.command.dexer.Main.run(Main.java:230)
  [dx]  at com.android.dx.command.dexer.Main.main(Main.java:199)
[dx]    at com.android.dx.command.Main.main(Main.java:103)
 [dx] 

BUILD FAILED /Users/newaccount/opt/android-sdk/tools/ant/build.xml:892: The following error occurred while executing this line: /Users/newaccount/opt/android-sdk/tools/ant/build.xml:894: The following error occurred while executing this line: /Users/newaccount/opt/android-sdk/tools/ant/build.xml:906: The following error occurred while executing this line: /Users/newaccount/opt/android-sdk/tools/ant/build.xml:284: null returned: 2 失败/Users/newaccount/opt/android-sdk/tools/ant/build.xml:892:执行此行时发生以下错误:/Users/newaccount/opt/android-sdk/tools/ant/build.xml :894:执行此行时发生以下错误:/Users/newaccount/opt/android-sdk/tools/ant/build.xml:906:执行此行时发生以下错误:/ Users / newaccount / opt / android -sdk / tools / ant / build.xml:284:返回null:2

Total time: 17 seconds
Error code 1 for command: ant with args: debug,-    f,/Users/newaccount/projects/Insurance/platforms/android/build.xml,-Dout.dir=ant-build,-    Dgen.absolute.dir=ant-gen
Command finished with error code 2:     /Users/newaccount/projects/Insurance/platforms/android/cordova/build 
Error: /Users/newaccount/projects/Insurance/platforms/android/cordova/build: Command         failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/src/superspawn.js:126:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
 at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)

Second Question: using cordova or php how can I push notification t specific devices installed this apps not broadcast. 第二个问题:使用cordova或php如何推送通知,此应用未安装的特定设备不会广播。

Thanks for advanced. 感谢高级。

First of all you don't need: com.phonegap.plugins.PushPlugin Yes, also it is a reason for the error as stated above. 首先,您不需要:com.phonegap.plugins.PushPlugin是的,这也是上述错误的原因。

If you don't receive notifications follow these simple checks: 如果您没有收到通知,请遵循以下简单检查:

  1. Make sure you've got Google project id and Pushwoosh app id right 确保您正确设置了Google项目ID和Pushwoosh应用ID
  2. Make sure subscribers count have increased in Pushwoosh Control Panel after you register for push notifications. 注册推送通知后,请确保在Pushwoosh控制面板中增加了订阅者数量。
  3. Check status of push notification in "Pushes". 在“推送”中检查推送通知的状态。 It might give some insights if GCM returned an error. 如果GCM返回错误,则可能会提供一些见解。
  4. Make sure you've got Server Key right in the Pushwoosh App configuration. 确保在Pushwoosh应用程序配置中正确设置了服务器密钥。 Sometimes (still have no idea about the pattern) Browser key works instead. 有时(仍然不了解该模式)浏览器键起作用。
  5. Try on 3G as sometimes Wi-Fi (rarely but happens, especially if you have any enterprise firewall) may block push GCM ports. 尝试3G有时是因为Wi-Fi有时会发生(但很少发生,尤其是在您有企业防火墙的情况下)可能会阻止推送GCM端口。

Pushwoosh team. Pushwoosh团队。

I had the same error and the problem was generated because I have installed another plugin before the Pushwoosh one. 我有同样的错误,并且由于在Pushwoosh之前安装了另一个插件而产生了问题。

Try: 尝试:

cordova plugin list

and check if you have two Notification plugins: 并检查您是否有两个Notification插件:

In this scenario, you should: 在这种情况下,您应该:

1.Remove the platform: 1.删​​除平台:

cordova platform rm android (or ios...)

2.Remove the plugin you don't need anymore from the /plugins folder 2.从/plugins文件夹中删除不再需要的/plugins

3.Create the platform again: 3.再次创建平台:

cordova platform add android (or ios...)

4.Run on device: 4,在设备上运行

cordova run android

or build: 或构建:

cordova build android

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM