Android Studio 与 MobileFirst 的集成

Posted

技术标签:

【中文标题】Android Studio 与 MobileFirst 的集成【英文标题】:Android Studio integration with MobileFirst 【发布时间】:2015-02-20 15:21:55 【问题描述】:

我在运行与 android Studio 集成的 IBM MobileFirst Studio (Eclipse Kepler) 的本机 android 示例 (Hello World) 时遇到了几个问题。

我遵循了文档中的所有步骤,包括所有先决条件here。当我通过上下文菜单运行应用程序时:右键单击应用程序 Run As > Android Studio Project。 MobileFirst 启动 Android Studio,但应用程序在 AndroidStudio 配置中仍然存在以下错误和警告:

    警告:AndroidStudio 要求我迁移到 Gradle。我忽略了这次迁移,因为我发现 Gradle 的编译和部署延迟相当大。 我选择我的项目并按F4,在Project > Project SDK选项中,SDK无效,我选择一个有效。 在Modules > Modules SDK选项中,SDK无效,我选择了一个喜欢的,同上。 在“库”选项中,找不到 3 个库,因此我删除了引用。 在 SDK 选项中,我只选择 API 10。

此时,应用程序编译并正确部署了模拟器。运行时,IBM 启动画面出现并立即关闭,无需进入应用程序。

logcat 上出现以下内容:

02-20 09:43:00.135      582-582/com.HelloWorld I/CordovaLog﹕ Changing log level to DEBUG(3)
02-20 09:43:00.165      582-582/com.HelloWorld I/dalvikvm﹕ Failed resolving Lcom/worklight/wlclient/api/WLClient$ActivityListener; interface 16 'Landroid/app/Application$ActivityLifecycleCallbacks;'
02-20 09:43:00.165      582-582/com.HelloWorld W/dalvikvm﹕ Link of class 'Lcom/worklight/wlclient/api/WLClient$ActivityListener;' failed
02-20 09:43:00.176      582-582/com.HelloWorld I/dalvikvm﹕ Failed resolving Lcom/worklight/wlclient/api/WLClient$ActivityListener; interface 16 'Landroid/app/Application$ActivityLifecycleCallbacks;'
02-20 09:43:00.176      582-582/com.HelloWorld W/dalvikvm﹕ Link of class 'Lcom/worklight/wlclient/api/WLClient$ActivityListener;' failed
02-20 09:43:00.176      582-582/com.HelloWorld E/dalvikvm﹕ Could not find class 'com.worklight.wlclient.api.WLClient$ActivityListener', referenced from method com.worklight.wlclient.api.WLClient.<init>
02-20 09:43:00.176      582-582/com.HelloWorld W/dalvikvm﹕ VFY: unable to resolve new-instance 1728 (Lcom/worklight/wlclient/api/WLClient$ActivityListener;) in Lcom/worklight/wlclient/api/WLClient;
02-20 09:43:00.176      582-582/com.HelloWorld D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x003d
02-20 09:43:00.195      582-582/com.HelloWorld D/dalvikvm﹕ VFY: dead code 0x003f-0048 in Lcom/worklight/wlclient/api/WLClient;.<init> (Landroid/content/Context;)V
02-20 09:43:00.205      582-582/com.HelloWorld I/dalvikvm﹕ Failed resolving Lcom/worklight/wlclient/api/WLClient$ActivityListener; interface 16 'Landroid/app/Application$ActivityLifecycleCallbacks;'
02-20 09:43:00.205      582-582/com.HelloWorld W/dalvikvm﹕ Link of class 'Lcom/worklight/wlclient/api/WLClient$ActivityListener;' failed
02-20 09:43:00.205      582-582/com.HelloWorld I/dalvikvm﹕ Failed resolving Lcom/worklight/wlclient/api/WLClient$ActivityListener; interface 16 'Landroid/app/Application$ActivityLifecycleCallbacks;'
02-20 09:43:00.205      582-582/com.HelloWorld W/dalvikvm﹕ Link of class 'Lcom/worklight/wlclient/api/WLClient$ActivityListener;' failed
02-20 09:43:00.215      582-582/com.HelloWorld I/dalvikvm﹕ Could not find method com.worklight.wlclient.api.WLClient$ActivityListener.isAppInBackground, referenced from method com.worklight.wlclient.api.WLClient.isApplicationSentToBackground
02-20 09:43:00.215      582-582/com.HelloWorld W/dalvikvm﹕ VFY: unable to resolve virtual method 12490: Lcom/worklight/wlclient/api/WLClient$ActivityListener;.isAppInBackground ()Z
02-20 09:43:00.215      582-582/com.HelloWorld D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000c
02-20 09:43:00.215      582-582/com.HelloWorld D/dalvikvm﹕ VFY: dead code 0x000f-000f in Lcom/worklight/wlclient/api/WLClient;.isApplicationSentToBackground (Landroid/content/Context;)Z
02-20 09:43:00.365      582-592/com.HelloWorld W/WLClient﹕ WLClient.createInstance in WLClient.java:208 :: You should pass a context that is assignable from the Activity class. WLClient instance may be used to start an activity.
02-20 09:43:00.955      582-582/com.HelloWorld I/dalvikvm﹕ Failed resolving Lcom/worklight/androidgap/WLSplashScreen$ActivityListener; interface 16 'Landroid/app/Application$ActivityLifecycleCallbacks;'
02-20 09:43:00.955      582-582/com.HelloWorld W/dalvikvm﹕ Link of class 'Lcom/worklight/androidgap/WLSplashScreen$ActivityListener;' failed
02-20 09:43:00.955      582-582/com.HelloWorld E/dalvikvm﹕ Could not find class 'com.worklight.androidgap.WLSplashScreen$ActivityListener', referenced from method com.worklight.androidgap.WLSplashScreen.displaySplashDialog
02-20 09:43:00.955      582-582/com.HelloWorld W/dalvikvm﹕ VFY: unable to resolve new-instance 1261 (Lcom/worklight/androidgap/WLSplashScreen$ActivityListener;) in Lcom/worklight/androidgap/WLSplashScreen;
02-20 09:43:00.955      582-582/com.HelloWorld D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x0064
02-20 09:43:00.955      582-582/com.HelloWorld D/dalvikvm﹕ VFY: dead code 0x0066-006f in Lcom/worklight/androidgap/WLSplashScreen;.displaySplashDialog (Landroid/app/Activity;I)V
02-20 09:43:00.975      582-592/com.HelloWorld D/wl.splashscreen﹕ WLSplashScreen.show in WLSplashScreen.java:64 :: Showing Splash Screen
02-20 09:43:01.035      582-582/com.HelloWorld D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed 735K, 55% free 2796K/6151K, external 2002K/2137K, paused 60ms
02-20 09:43:01.105      582-582/com.HelloWorld D/CordovaActivity﹕ Resuming the App
02-20 09:43:01.855      582-592/com.HelloWorld D/prepackagedAssetManager﹕ PrepackagedAssetsManager.copyPrepackagedAssetsToLocalStorage in PrepackagedAssetsManager.java:68 :: New installation/upgrade detected, copying resources and saving new checksum
02-20 09:43:02.195      582-592/com.HelloWorld D/wl﹕ WL.doPrepareAssetsWork in WL.java:287 :: no need to check web resource integrity
02-20 09:43:02.205      582-582/com.HelloWorld D/CordovaActivity﹕ CordovaActivity.init()
02-20 09:43:02.215      582-582/com.HelloWorld I/dalvikvm﹕ Could not find method android.webkit.WebView.<init>, referenced from method org.apache.cordova.CordovaWebView.<init>
02-20 09:43:02.215      582-582/com.HelloWorld W/dalvikvm﹕ VFY: unable to resolve direct method 551: Landroid/webkit/WebView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;IZ)V
02-20 09:43:02.215      582-582/com.HelloWorld D/dalvikvm﹕ VFY: replacing opcode 0x70 at 0x0000
02-20 09:43:02.215      582-582/com.HelloWorld D/dalvikvm﹕ VFY: dead code 0x0003-0011 in Lorg/apache/cordova/CordovaWebView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;IZ)V
02-20 09:43:02.215      582-582/com.HelloWorld I/dalvikvm﹕ Could not find method android.webkit.WebView.setWebContentsDebuggingEnabled, referenced from method org.apache.cordova.CordovaWebView.enableRemoteDebugging
02-20 09:43:02.215      582-582/com.HelloWorld W/dalvikvm﹕ VFY: unable to resolve static method 569: Landroid/webkit/WebView;.setWebContentsDebuggingEnabled (Z)V
02-20 09:43:02.215      582-582/com.HelloWorld D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x0001
02-20 09:43:02.295      582-582/com.HelloWorld I/dalvikvm﹕ Could not find method android.content.Intent.setSelector, referenced from method org.apache.cordova.CordovaUriHelper.shouldOverrideUrlLoading
02-20 09:43:02.295      582-582/com.HelloWorld W/dalvikvm﹕ VFY: unable to resolve virtual method 186: Landroid/content/Intent;.setSelector (Landroid/content/Intent;)V
02-20 09:43:02.305      582-582/com.HelloWorld D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x005a
02-20 09:43:02.345      582-582/com.HelloWorld D/CordovaWebView﹕ CordovaWebView is running on device made by: unknown
02-20 09:43:02.375      582-582/com.HelloWorld I/CordovaWebView﹕ Disabled addjavascriptInterface() bridge since Android version is old.
02-20 09:43:02.375      582-582/com.HelloWorld D/CordovaActivity﹕ CordovaActivity.createViews()
02-20 09:43:02.385      582-582/com.HelloWorld D/CordovaWebView﹕ >>> loadUrl(file:///android_asset/www/skinLoader.html)
02-20 09:43:02.385      582-582/com.HelloWorld D/PluginManager﹕ init()
02-20 09:43:02.385      582-582/com.HelloWorld I/dalvikvm﹕ Could not find method android.webkit.CookieManager.setAcceptThirdPartyCookies, referenced from method com.worklight.androidgap.plugin.WLInitializationPlugin.initialize
02-20 09:43:02.385      582-582/com.HelloWorld W/dalvikvm﹕ VFY: unable to resolve virtual method 505: Landroid/webkit/CookieManager;.setAcceptThirdPartyCookies (Landroid/webkit/WebView;Z)V
02-20 09:43:02.385      582-582/com.HelloWorld D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x001a
02-20 09:43:02.405      582-582/com.HelloWorld D/CordovaWebView﹕ >>> loadUrlNow()
02-20 09:43:02.415      582-582/com.HelloWorld D/SoftKeyboardDetect﹕ Ignore this event
02-20 09:43:02.575      582-582/com.HelloWorld D/CordovaWebViewClient﹕ onPageStarted(file:///android_asset/www/skinLoader.html)
02-20 09:43:02.609      582-582/com.HelloWorld D/CordovaActivity﹕ onMessage(onPageStarted,file:///android_asset/www/skinLoader.html)
02-20 09:43:03.065      582-582/com.HelloWorld D/JsMessageQueue﹕ Set native->JS mode to OnlineEventsBridgeMode
02-20 09:43:03.105      582-582/com.HelloWorld D/CordovaWebViewClient﹕ onPageFinished(file:///android_asset/www/skinLoader.html)
02-20 09:43:03.105      582-582/com.HelloWorld D/CordovaActivity﹕ onMessage(onPageFinished,file:///android_asset/www/skinLoader.html)
02-20 09:43:03.465      582-584/com.HelloWorld D/dalvikvm﹕ GC_CONCURRENT freed 762K, 51% free 3311K/6727K, external 2660K/2812K, paused 3ms+4ms
02-20 09:43:03.485      582-583/com.HelloWorld D/webviewglue﹕ nativeDestroy view: 0x2b5580
02-20 09:43:03.495      582-594/com.HelloWorld D/dalvikvm﹕ GREF has increased to 201
02-20 09:43:04.295      582-582/com.HelloWorld V/StatusBar﹕ StatusBar: initialization
02-20 09:43:04.295      582-582/com.HelloWorld V/StatusBar﹕ Executing action: _ready
02-20 09:43:04.295      582-582/com.HelloWorld W/CordovaPlugin﹕ Attempted to send a second callback for ID: StatusBar792861772
    Result was: "Invalid action"
02-20 09:43:04.325      582-582/com.HelloWorld D/CordovaActivity﹕ onMessage(spinner,stop)
02-20 09:43:04.715      582-582/com.HelloWorld D/CordovaNetworkManager﹕ Connection Type: 3g
02-20 09:43:04.715      582-582/com.HelloWorld D/CordovaNetworkManager﹕ Connection Extra Info: internet
02-20 09:43:04.745      582-582/com.HelloWorld D/CordovaNetworkManager﹕ Connection Type: 3g
02-20 09:43:04.745      582-582/com.HelloWorld D/CordovaNetworkManager﹕ Connection Extra Info: internet
02-20 09:43:04.745      582-582/com.HelloWorld D/CordovaActivity﹕ onMessage(networkconnection,3g)
02-20 09:43:04.805      582-582/com.HelloWorld D/CordovaWebViewClient﹕ onPageStarted(file:///android_asset/www/default/index.html)
02-20 09:43:04.805      582-582/com.HelloWorld D/JsMessageQueue﹕ Set native->JS mode to null
02-20 09:43:04.805      582-582/com.HelloWorld D/CordovaActivity﹕ onMessage(onPageStarted,file:///android_asset/www/default/index.html)
02-20 09:43:04.835      582-600/com.HelloWorld D/szipinf﹕ Initializing inflate state
02-20 09:43:04.845      582-600/com.HelloWorld D/szipinf﹕ Initializing zlib to inflate
02-20 09:43:04.885      582-600/com.HelloWorld D/szipinf﹕ Initializing inflate state
02-20 09:43:04.885      582-600/com.HelloWorld D/szipinf﹕ Initializing zlib to inflate
02-20 09:43:05.065      582-584/com.HelloWorld D/dalvikvm﹕ GC_CONCURRENT freed 609K, 46% free 3905K/7175K, external 2283K/2812K, paused 3ms+17ms
02-20 09:43:05.125      582-582/com.HelloWorld D/CordovaActivity﹕ onMessage(spinner,stop)
02-20 09:43:05.215      582-582/com.HelloWorld D/JsMessageQueue﹕ Set native->JS mode to OnlineEventsBridgeMode
02-20 09:43:09.196      582-582/com.HelloWorld D/CordovaWebViewClient﹕ onPageFinished(file:///android_asset/www/default/index.html)
02-20 09:43:09.196      582-582/com.HelloWorld D/CordovaActivity﹕ onMessage(onPageFinished,file:///android_asset/www/default/index.html)
02-20 09:43:09.826      582-582/com.HelloWorld V/StatusBar﹕ Executing action: _ready
02-20 09:43:09.826      582-582/com.HelloWorld W/CordovaPlugin﹕ Attempted to send a second callback for ID: StatusBar12635921
    Result was: "Invalid action"
02-20 09:43:09.836      582-582/com.HelloWorld D/CordovaActivity﹕ onMessage(spinner,stop)
02-20 09:43:09.866      582-582/com.HelloWorld D/CordovaNetworkManager﹕ Connection Type: 3g
02-20 09:43:09.866      582-582/com.HelloWorld D/CordovaNetworkManager﹕ Connection Extra Info: internet
02-20 09:43:10.206      582-592/com.HelloWorld D/NONE﹕ ondeviceready event dispatched
02-20 09:43:10.316      582-582/com.HelloWorld W/PluginManager﹕ THREAD WARNING: exec() call to Globalization.getLocaleName blocked the main thread for 80ms. Plugin should use CordovaInterface.getThreadPool().
02-20 09:43:10.366      582-582/com.HelloWorld W/PluginManager﹕ THREAD WARNING: exec() call to Globalization.getNumberPattern blocked the main thread for 46ms. Plugin should use CordovaInterface.getThreadPool().
02-20 09:43:10.416      582-592/com.HelloWorld D/NONE﹕ wlclient init started
02-20 09:43:10.515      582-582/com.HelloWorld W/PluginManager﹕ THREAD WARNING: exec() call to LoggerPlugin.log blocked the main thread for 22ms. Plugin should use CordovaInterface.getThreadPool().
02-20 09:43:10.526      582-592/com.HelloWorld D/NONE﹕ Read cookies: null
02-20 09:43:10.546      582-592/com.HelloWorld D/NONE﹕ CookieMgr read cookies: 
02-20 09:43:10.606      582-594/com.HelloWorld W/dalvikvm﹕ JNI WARNING: jarray 0x406abb20 points to non-array object (Ljava/lang/String;)
02-20 09:43:10.606      582-594/com.HelloWorld I/dalvikvm﹕ "WebViewCoreThread" prio=5 tid=11 NATIVE
02-20 09:43:10.616      582-594/com.HelloWorld I/dalvikvm﹕ | group="main" sCount=0 dsCount=0 obj=0x40589878 self=0x2c5620
02-20 09:43:10.616      582-594/com.HelloWorld I/dalvikvm﹕ | sysTid=594 nice=0 sched=0/0 cgrp=default handle=2917456
02-20 09:43:10.616      582-594/com.HelloWorld I/dalvikvm﹕ | schedstat=( 6162204949 1843580323 915 )
02-20 09:43:10.616      582-594/com.HelloWorld I/dalvikvm﹕ at android.webkit.JWebCoreJavaBridge.setNetworkOnLine(Native Method)
02-20 09:43:10.616      582-594/com.HelloWorld I/dalvikvm﹕ at android.webkit.JWebCoreJavaBridge.setNetworkOnLine(Native Method)
02-20 09:43:10.616      582-594/com.HelloWorld I/dalvikvm﹕ at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1099)
02-20 09:43:10.616      582-594/com.HelloWorld I/dalvikvm﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 09:43:10.616      582-594/com.HelloWorld I/dalvikvm﹕ at android.os.Looper.loop(Looper.java:123)
02-20 09:43:10.616      582-594/com.HelloWorld I/dalvikvm﹕ at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:629)
02-20 09:43:10.616      582-594/com.HelloWorld I/dalvikvm﹕ at java.lang.Thread.run(Thread.java:1019)
02-20 09:43:10.616      582-594/com.HelloWorld I/dalvikvm﹕ [ 02-20 09:43:10.616   582:0x252 E/dalvikvm ]
    VM aborting

另一个问题是,当我返回从 MobileFirst 启动应用程序时,AndroidStudio 会打开并要求我从外部重新加载修改过的文件(来自 MobileFirst),显然没有同步并且对设置的更改消失了。

有人知道如何解决这些问题吗?

我应该澄清一下,要执行 AndroidStudio,我必须安装 Fix Pack MobileFirst。

对不起我的英语。

感谢您的意见和帮助。

【问题讨论】:

您使用的是来自developer.ibm.com/mobilefirstplatform/documentation/… 的样本之一吗?另外,这是完整的 logcat 输出吗? 没有两个问题。 我用完整的日志更新了问题 我在 IBM MobileFirst Platform 中从零开始创建了 helloworld 项目 您可以在步骤 2、3 和 4 上花费时间吗?那里什么是无效的,你把它改成了什么?缺少什么? 【参考方案1】:

Android 的 Worklight 项目目前不支持 Gradle。

对于其余的问题,我通过以下方式解决了问题:

    指定 SDK

    在 app-name.iml 中,从以下行中删除范围:

    <orderEntry type="library" name="libs" level="project" />
    

最近在 Android Studio 中似乎发生了一些变化,因为项目过去使用它开箱即用(Gradle 除外,目前不支持)。

试试上面的。

【讨论】:

如果我删除该行,应用程序会抛出编译错误:\GCMIntentService.java 错误:(3, 68) java: com.worklight.androidgap.push 包不存在 HelloWorldAgain2.java 错误:(8 , 26) java: 包 org.apache.cordova 不存在 错误:(10, 36) java: 包 com.worklight.androidgap.api 不存在 错误:(11, 36) java: 包 com.worklight.androidgap. api 不存在 Error:(12, 36) java: package com.worklight.androidgap.api 不存在 Error:(14, 39) java: cannot find symbol symbol: class CordovaActivity ...... 我的意思是,用我的替换那行。这只是删除“范围”属性。 那行和我的一样,没有范围属性 嗯,很奇怪。在指出 libs 错误的设置屏幕中,您有一个包含 4 个选项的下拉列表,选择一个后,您可以返回该文件,然后删除范围属性(至少我在那里看到),然后编译工作并显示应用程序。

以上是关于Android Studio 与 MobileFirst 的集成的主要内容,如果未能解决你的问题,请参考以下文章

如何建立与 Android studio和 gradle android 库

Jetpack入门系列(一)android studio 安装与配置

Android studio安装与配置

Android studio安装与配置

拥抱Android Studio:Android Studio与Gradle深入

Android学习—— Android studio的安装与配置