想当然的写了这样一段代码:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.thatlib", ThatService.class.getName()));
boolean bindRet = bindService(intent, thatServiceCon, Context.BIND_IMPORTANT);
Log.d(TAG, "--- bindService ret:"+bindRet) ;
结果 bindService返回false,ThatService并没有onBind ,why?
bing一下,Binding fails to remote service defined in Android library ,看里面的说法,可能在于是Component的packageName参数给错了;
改为
intent.setComponent(new ComponentName("com.myapp", ThatService.class.getName()));
继续看为什么会这样,
Android Studio - Gradle Manifest Merging Failed
这里 Paolo M的解答中的一句话提示了:“For what I can see, if you have a multi-module project with Android Studio and gradle, the IDE try to merge manifest files from every module into a Main manifest.”
这样AAR里的Service实际上是作为myapp里面的组件在运行了,所以参数要给myapp的packageName,应该就是这个原因。