Bluemix云平台实战日志:IBM Mobile Data云服务和Android应用开发

时间:2023-02-04 11:23:41

由于Bluemix处在快速迭代周期,中文资料很容易过时,所以参考的英文教程也有少许地方有变化,原文链接:http://www.ibm.com/developerworks/library/mo-android-mobiledata-app/#N10268

1.通过终端下载已经建立初始工程(没有跟Bluemix Mobile Data Service对接)

$ git clone https://hub.jazz.net/git/mobilecloud/bluelist-base


或者下载完整的代码,不需要补充数据序列化保存到Mobile Data部分的代码,省去Step5的4个步骤

$ git clone https://hub.jazz.net/git/mobilecloud/bluelist-mobiledata


2.上面下载的源码包括iOS和Hybrid、Android等目录,通过Eclipse导入Android工程

3. 登录Bluemix控制台创建应用,获取applicationID、applicationSercet、applicationRoute,并修改bluelist.properties中对应的值

4.下载Android SDK,添加ibmbluemix.jar, ibmdata.jar, and ibmfilesync.jar到Eclipse工程Buildpath。

5. 运行,看到界面了,但是点击添加进行数据添加就报错

 
<span style="font-family: Arial, Helvetica, sans-serif;"><img src="webkit-fake-url://4ab6b751-c5a1-40d5-87b0-5f0f95b0b11c/image.tiff" alt="" /></span>
05-04 16:12:42.692: E/AndroidRuntime(5630): FATAL EXCEPTION: main05-04 16:12:42.692: E/AndroidRuntime(5630): java.lang.IllegalStateException: Could not execute method of the activity05-04 16:12:42.692: E/AndroidRuntime(5630): 	at android.view.View$1.onClick(View.java:3591)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at android.view.View.performClick(View.java:4084)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at android.view.View$PerformClick.run(View.java:16966)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at android.os.Handler.handleCallback(Handler.java:615)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at android.os.Handler.dispatchMessage(Handler.java:92)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at android.os.Looper.loop(Looper.java:137)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at android.app.ActivityThread.main(ActivityThread.java:4745)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at java.lang.reflect.Method.invokeNative(Native Method)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at java.lang.reflect.Method.invoke(Method.java:511)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at dalvik.system.NativeStart.main(Native Method)05-04 16:12:42.692: E/AndroidRuntime(5630): Caused by: java.lang.reflect.InvocationTargetException05-04 16:12:42.692: E/AndroidRuntime(5630): 	at java.lang.reflect.Method.invokeNative(Native Method)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at java.lang.reflect.Method.invoke(Method.java:511)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at android.view.View$1.onClick(View.java:3586)05-04 16:12:42.692: E/AndroidRuntime(5630): 	... 11 more05-04 16:12:42.692: E/AndroidRuntime(5630): Caused by: java.lang.VerifyError: com/ibm/mobile/services/data/internal/MBaasJSONSerialization05-04 16:12:42.692: E/AndroidRuntime(5630): 	at com.ibm.mobile.services.data.internal.DataServiceObjectInternal.getJSONSerializedObject(DataServiceObjectInternal.java:366)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at com.ibm.mobile.services.data.internal.DataServiceObjectInternal.processSaves(DataServiceObjectInternal.java:273)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at com.ibm.mobile.services.data.internal.DataServiceObjectInternal.saveInBackground(DataServiceObjectInternal.java:232)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at com.ibm.mobile.services.data.IBMDataObject.saveInBackground(IBMDataObject.java:240)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at com.ibm.mobile.services.data.IBMDataObject.save(IBMDataObject.java:214)05-04 16:12:42.692: E/AndroidRuntime(5630): 	at com.ibm.bluelist.MainActivity.createItem(MainActivity.java:149)05-04 16:12:42.692: E/AndroidRuntime(5630): 	... 14 more


分析原因,可能是第4步下载的Android SDK有问题,改用Android Studio,Gradle采用的是maven管理的库,数据可以添加到Mibile Data,通过!

登录Dashboard可查看Mobile Data数据,还有Device列表,有图有真相,另外有个小发现点:蓝色按钮可以上传文件

Bluemix云平台实战日志:IBM Mobile Data云服务和Android应用开发