Android、Java、Web系、Linux、マラソン等の備忘録

2012/10/13

Evernote SDK for Androidサンプルを自分のプロジェクトで実装する時の注意点

0 件のコメント
Evernote SDK for AndroidのクラウドAPIサンプルを参考にしながら、自前のプロジェクト上で実装してみた際の注意点というかエラーについてです。今後SDKのバージョンアップがあれば発生しなくなるかと思われますが下記環境に関しては注意が必要です。

環境


実装

基本的には、こちらの

”Using the SDK in your app”の項目を参考にすれば良いと思いますが、見落としてました...


エラー

10-13 01:50:11.513: E/EvernoteOAuthActivity(11406): Failed to obtain OAuth request token
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406): org.scribe.exceptions.OAuthConnectionException: There was a problem while creating a connection to the remote service.
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at org.scribe.model.Request.send(Request.java:66)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at org.scribe.model.OAuthRequest.send(OAuthRequest.java:12)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:47)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at com.evernote.client.oauth.android.EvernoteOAuthActivity.beginAuthentication(EvernoteOAuthActivity.java:173)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at com.evernote.client.oauth.android.EvernoteOAuthActivity.onResume(EvernoteOAuthActivity.java:120)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at android.app.Activity.performResume(Activity.java:4539)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at android.os.Handler.dispatchMessage(Handler.java:99)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at android.os.Looper.loop(Looper.java:137)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at android.app.ActivityThread.main(ActivityThread.java:4424)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at java.lang.reflect.Method.invokeNative(Native Method)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at java.lang.reflect.Method.invoke(Method.java:511)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at dalvik.system.NativeStart.main(Native Method)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406): Caused by: android.os.NetworkOnMainThreadException
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at java.net.InetAddress.getAllByName(InetAddress.java:220)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:460)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:432)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at libcore.net.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:280)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at org.scribe.model.Request.addBody(Request.java:125)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at org.scribe.model.Request.doSend(Request.java:104)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      at org.scribe.model.Request.send(Request.java:62)
10-13 01:50:11.513: E/EvernoteOAuthActivity(11406):      ... 19 more

原因


AndroidManifest.xml

     <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="15" />

超絶見落としてました。SDKのREADMEに書いてありました(;´_`A

・evernote/evernote-sdk-android
https://github.com/evernote/evernote-sdk-android#include-the-code
Known Issues
The current version of the SDK performs OAuth network requests on the main thread, resulting in a NetworkOnMainThreadException when the targetSDK is set to 11 or higher.

ターゲットSDKがLevel11以上だと上記のようなエラーが出るようです。

対応

AndroidManifest.xml

     <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="9" />


かなり実装した後に気付くとめんどくさそうですね(;^_^A


PR:本格アプリを作ろう! Androidプログラミングレシピ
PR:Android UI Cookbook for 4.0 ICS(Ice Cream Sandwich)アプリ開発術
PR:EclipseではじめるAndroidプログラミング入門―SDK2.1~2.3/4.0対応

0 件のコメント :

コメントを投稿