[エラー発生環境]
Nexus 7(2013) / Android 6.0.1
OpenCVバージョン2.4.11
エラーメッセージを確認したところ, OpenCVLoader#initAsyncメソッドでエラーが発生していた.
[エラーメッセージ]
01-09 21:56:28.665 14620-14620/com.moonlight_aska.android.vision.flironedemo I/LOG_TAG: onResume, init ImageProc!
01-09 21:56:28.666 14620-14620/com.moonlight_aska.android.vision.flironedemo D/AndroidRuntime: Shutting down VM
01-09 21:56:28.669 14620-14620/com.moonlight_aska.android.vision.flironedemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.moonlight_aska.android.vision.flironedemo, PID: 14620
java.lang.RuntimeException: Unable to resume activity {com.moonlight_aska.android.vision.flironedemo/com.moonlight_aska.android.vision.flironedemo.PreviewActivity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=org.opencv.engine.BIND }
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=org.opencv.engine.BIND }
at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1209)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1308)
at android.app.ContextImpl.bindService(ContextImpl.java:1286)
at android.content.ContextWrapper.bindService(ContextWrapper.java:604)
at org.opencv.android.AsyncServiceHelper.initOpenCV(AsyncServiceHelper.java:25)
at org.opencv.android.OpenCVLoader.initAsync(OpenCVLoader.java:89)
at com.moonlight_aska.android.vision.flironedemo.ImageProc.init(ImageProc.java:41)
at com.moonlight_aska.android.vision.flironedemo.PreviewActivity.onResume(PreviewActivity.java:218)
:
対応策について少し調べてみたところ, OpenCVのコードを以下のように修正すればよいようである. [1]
[対象ファイル]
org\opencv\Android\AsyncServiceHelper.java
[修正箇所]
public static boolean initOpenCV(String Version, final Context AppContext,
final LoaderCallbackInterface Callback)
{
AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback);
/* 修正前 2016.1.9
if (AppContext.bindService(new Intent("org.opencv.engine.BIND"),
helper.mServiceConnection, Context.BIND_AUTO_CREATE))
*/
Intent intent = new Intent("org.opencv.engine.BIND");
intent.setPackage("org.opencv.engine");
if (AppContext.bindService(intent,
helper.mServiceConnection, Context.BIND_AUTO_CREATE))
{
return true;
}
else
{
AppContext.unbindService(helper.mServiceConnection);
InstallService(AppContext, Callback);
return false;
}
}
一応, これで問題なくOpenCVが使用できることを確認した.
どうもAndroid 5.0以降で同じ問題が発生するようだ...
----
参照URL:
[1] Issue with OpenCV for Android on Android 5.0 (lollipop)