Phonegap 应用程序在 Android 上安装但在 iOS 上运行时崩溃

Posted

技术标签:

【中文标题】Phonegap 应用程序在 Android 上安装但在 iOS 上运行时崩溃【英文标题】:Phonegap app crashes when installed on Android but working on iOS 【发布时间】:2015-07-13 09:33:20 【问题描述】:

我为 android 创建了一个密钥,并通过 phonegap build 用它签署了我的应用程序。当我尝试运行它时,应用程序崩溃了。从logcat我可以发现有一些系统级别的权限问题:

07-12 17:04:34.495    2714-3126/? W/ActivityManager﹕ Permission Denial: getCurrentUser() from pid=15691, uid=10194 requires android.permission.INTERACT_ACROSS_USERS

这是我的应用程序的完整 logcat:

07-12 17:04:34.360  15691-15691/? I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
07-12 17:04:34.360  15691-15691/? I/SELinux﹕ Function: selinux_android_load_priority [1], There is no sepolicy version file.
07-12 17:04:34.360  15691-15691/? I/SELinux﹕ Function: selinux_android_load_priority , priority version is VE=SEPF_SM-T800_4.4.2_0018
07-12 17:04:34.360  15691-15691/? I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
07-12 17:04:34.360  15691-15691/? E/SELinux﹕ [DEBUG] seapp_context_lookup: seinfoCategory = default
07-12 17:04:34.365  15691-15691/? E/dalvikvm﹕ >>>>> Normal User
07-12 17:04:34.365  15691-15691/? E/dalvikvm﹕ >>>>> com.phonegap.helloworld [ userId:0 | appId:10194 ]
07-12 17:04:34.365  15691-15691/? E/SELinux﹕ [DEBUG] seapp_context_lookup: seinfoCategory = default
07-12 17:04:34.385  15691-15691/? I/dalvikvm﹕ Enabling JNI app bug workarounds for target SDK version 7...
07-12 17:04:34.495    2714-3126/? W/ActivityManager﹕ Permission Denial: getCurrentUser() from pid=15691, uid=10194 requires android.permission.INTERACT_ACROSS_USERS
07-12 17:04:34.515  15691-15691/? I/PersonaManager﹕ getPersonaService() name persona_policy
07-12 17:04:34.545  15691-15691/? I/CordovaLog﹕ Changing log level to DEBUG(3)
07-12 17:04:34.545  15691-15691/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x416eac08)
07-12 17:04:34.550  15691-15691/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.phonegap.helloworld, PID: 15691
    java.lang.RuntimeException: Unable to start activity ComponentInfocom.phonegap.helloworld/com.phonegap.helloworld.ICT: java.lang.NumberFormatException: Invalid long: ""
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2404)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5653)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NumberFormatException: Invalid long: ""
            at java.lang.Long.invalidLong(Long.java:124)
            at java.lang.Long.decode(Long.java:142)
            at org.apache.cordova.CordovaPreferences.copyIntoIntentExtras(CordovaPreferences.java:142)
            at org.apache.cordova.CordovaActivity.loadConfig(CordovaActivity.java:235)
            at org.apache.cordova.CordovaActivity.onCreate(CordovaActivity.java:202)
            at com.phonegap.helloworld.ICTSandBox.onCreate(ICTSandBox.java:30)
            at android.app.Activity.performCreate(Activity.java:5539)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5653)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
07-12 17:04:36.345  15691-15691/? I/Process﹕ Sending signal. PID: 15691 SIG: 9
07-12 17:04:36.360    2714-3506/? I/ActivityManager﹕ Process com.phonegap.helloworld (pid 15691) (adj 9) has died.

这是我的 config.xml:

<?xml version="1.0" encoding="UTF-8"?>
    <widget xmlns = "http://www.w3.org/ns/widgets"
        xmlns:gap = "http://phonegap.com/ns/1.0"
        id        = "com.phonegap.helloworld"
        versionCode=""
        version   = "1.0.0">
        <name>ICT Sand Box</name>
        <description>
ICT     </description>
        <author href="http://phonegap.com" email="support@phonegap.com">
PhoneGap Team
        </author>
        <preference name="phonegap-version" value="3.7.0" />
        <preference name="orientation" value="default" />
        <preference name="fullscreen" value="true" />
        <preference name="target-device" value="universal" />
        <preference name="webviewbounce" value="true" />
        <preference name="prerendered-icon" value="true" />
        <preference name="stay-in-webview" value="true" />
        <preference name="ios-statusbarstyle" value="black-opaque" />
        <preference name="detect-data-types" value="true" />
        <preference name="exit-on-suspend" value="true" />
        <preference name="show-splash-screen-spinner" value="true" />
        <preference name="auto-hide-splash-screen" value="true" />
        <preference name="EnableViewportScale" value="true" />
        <preference name="MediaPlaybackRequiresUserAction" value="true" />
        <preference name="AllowInlineMediaPlayback" value="true" />
        <preference name="BackupWebStorage" value="cloud" />
        <preference name="TopActivityIndicator" value="gray" />
        <preference name="KeyboardDisplayRequiresUserAction" value="true" />
        <preference name="HideKeyboardFormAccessoryBar" value="true" />
        <preference name="SuppressesIncrementalRendering" value="true" />
        <preference name="android-minSdkVersion" value="7" />
        <preference name="android-installLocation" value="auto" />
        <preference name="SplashScreenDelay" value="5000" />
        <preference name="ErrorUrl" value=""/>
        <preference name="BackgroundColor" value=""/>
        <preference name="KeepRunning" value="true"/>
        <preference name="DisallowOverscroll" value="true"/>
        <preference name="LoadingDialog" value=","/> 
        <preference name="LoadUrlTimeoutValue" value="20000" />
        <preference name="disable-cursor" value="true" />
        <gap:platform name="ios" />
        <gap:platform name="android" />
        <gap:platform name="winphone" />
        <gap:plugin name="org.apache.cordova.battery-status"  />
        <gap:plugin name="org.apache.cordova.camera"  />
        <gap:plugin name="org.apache.cordova.console"  />
        <gap:plugin name="org.apache.cordova.contacts"  />
        <gap:plugin name="org.apache.cordova.device"  />
        <gap:plugin name="org.apache.cordova.device-orientation"  />
        <gap:plugin name="org.apache.cordova.device-motion"  />
        <gap:plugin name="org.apache.cordova.dialogs"  />
        <gap:plugin name="org.apache.cordova.file-transfer"  />
        <gap:plugin name="org.apache.cordova.geolocation"  />
        <gap:plugin name="org.apache.cordova.globalization"  />
        <gap:plugin name="org.apache.cordova.inappbrowser"  />
        <gap:plugin name="org.apache.cordova.media"  />
        <gap:plugin name="org.apache.cordova.media-capture"  />
        <gap:plugin name="org.apache.cordova.network-information"  />
        <gap:plugin name="org.apache.cordova.splashscreen"  />
        <gap:plugin name="org.apache.cordova.vibration"  />
        <icon src="icon.png" />
        <gap:splash src="splash.png" />
        <access origin="*" />
        <!--gap:plugin name="com.moust.cordova.videoplayer"  version="1.0.0" />
        <gap:plugin name="com.sharinglabs.cordova.plugin.cache"  version="1.0.0" /-->
    </widget>

知道如何处理这个问题吗?

【问题讨论】:

无需为测试构建创建签名的 apk。 谢谢你的回复,能详细点吗?我用phonegap build来做。我可以在没有密钥的情况下从 phonegap build 下载应用程序(与 IOS 不同)吗?当您说不需要时,您的意思是它不会与密钥一起使用或者它只是不需要? 根据 phonegap 构建团队的说法:签名与否,对于 Android 的测试构建无关紧要。它没有太多禁忌 您不需要从 Phonegap 构建中为 Android 构建添加密钥。只需上传 www 文件并使用“未选择密钥”进行构建。 我试过了,但还是崩溃 【参考方案1】:

好的。感谢所有降级问题的人,因为我相信你们都知道答案: config.xml 中的以下行:

<preference name="BackgroundColor" value=""/>

必须省略。

开发团队没有给出确切的解释,但这是他们发现的。 请注意,此参数默认为空。

顺便说一句,即使您使用 configGap 实用程序,它也不会删除此参数。

【讨论】:

我升级了问答 :) *** 满是烧焦的驴子,只有少数人升级问题

以上是关于Phonegap 应用程序在 Android 上安装但在 iOS 上运行时崩溃的主要内容,如果未能解决你的问题,请参考以下文章

在 Android 上为 PhoneGap App 更改应用程序主题(使用 phonegap Build)

如何在phonegap中使用android原生代码?

在 android 和 IOS 中运行 phoneGap 应用程序需要进行啥配置?

Phonegap - 为 Android 应用添加启动画面

PhoneGap 应用程序在 android 设备中仅显示白屏

带有 Phonegap 的 Android 应用程序在横向旋转时崩溃