xiaofei-it / hermes Goto Github PK
View Code? Open in Web Editor NEWA smart, novel and easy-to-use framework for Android Inter-Process Communication (IPC). (简单易用的安卓进程间通信IPC框架)
License: Other
A smart, novel and easy-to-use framework for Android Inter-Process Communication (IPC). (简单易用的安卓进程间通信IPC框架)
License: Other
按照文档上写的,但是第二个APP拿不到数据
2019-03-07 22:21:20.049 1376-1762/? E/WindowManager: Performed 6 layouts in a row. Skipping
2019-03-07 22:21:20.482 10161-10161/justree.cn.otherapplication E/HERMES: Error occurs during getting instance. Error code: 16
2019-03-07 22:21:20.482 10161-10161/justree.cn.otherapplication E/HERMES: Error message: Cannot find class with ClassId annotation on it. ClassId = Singleton. Please add the same annotation on the corresponding class in the remote process and register it. Have you forgotten to register the class?
2019-03-07 22:21:20.483 10161-10161/justree.cn.otherapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: justree.cn.otherapplication, PID: 10161
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String justree.cn.otherapplication.ISingleton.getData()' on a null object reference
Android 5.1.0 on Genymotion.
This test case is just a little bit modification from Hermes demo.
Interface:
@ClassId("UserManager")
public interface IUserManager {
@MethodId("getUser")
String getUser();
@MethodId("getDate1")
Date getDate1();
@MethodId("getDateText")
String getDateText();
}
Implemantation:
@ClassId("UserManager")
public class UserManager implements IUserManager {
private static UserManager sInstance = null;
private UserManager() {
}
public static synchronized UserManager getInstance() {
if (sInstance == null) {
sInstance = new UserManager();
}
return sInstance;
}
@MethodId("getUser")
@Override
public String getUser() {
return "Xiaofei";
}
@MethodId("getDate1")
@Override
public Date getDate1() {
return new Date();
}
@MethodId("getDateText")
@Override
public String getDateText() {
return "DateText";
}
}
Client side code:
IUserManager userManager = Hermes.getInstanceInService(HermesService.HermesService1.class, IUserManager.class);
Date date = userManager.getDate1();
Exception stacktrace:
07-23 02:33:25.976 11397-11414/xiaofei.library.hermestest:g W/System.err﹕ xiaofei.library.hermes.util.HermesException
07-23 02:33:25.976 11397-11414/xiaofei.library.hermestest:g W/System.err﹕ at xiaofei.library.hermes.util.TypeCenter.getClassType(TypeCenter.java:145)
07-23 02:33:25.976 11397-11414/xiaofei.library.hermestest:g W/System.err﹕ at xiaofei.library.hermes.receiver.InstanceGettingReceiver.<init>(InstanceGettingReceiver.java:44)
07-23 02:33:25.976 11397-11414/xiaofei.library.hermestest:g W/System.err﹕ at xiaofei.library.hermes.receiver.ReceiverDesignator.getReceiver(ReceiverDesignator.java:35)
07-23 02:33:25.976 11397-11414/xiaofei.library.hermestest:g W/System.err﹕ at xiaofei.library.hermes.HermesService$1.send(HermesService.java:48)
07-23 02:33:25.976 11397-11414/xiaofei.library.hermestest:g W/System.err﹕ at xiaofei.library.hermes.internal.IHermesService$Stub.onTransact(IHermesService.java:70)
07-23 02:33:25.976 11397-11414/xiaofei.library.hermestest:g W/System.err﹕ at android.os.Binder.execTransact(Binder.java:446)
07-23 02:33:25.979 11380-11380/? E/HERMES﹕ Error occurs during getting instance. Error code: 16
07-23 02:33:25.979 11380-11380/? E/HERMES﹕ Error message: Cannot find class with ClassId annotation on it. ClassId = UserManager. Please add the same annotation on the corresponding class in the remote process and register it. Have you forgotten to register the class?
07-23 02:33:25.979 11380-11380/? D/AndroidRuntime﹕ Shutting down VM
07-23 02:33:25.979 11380-11380/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: xiaofei.library.hermestest:h, PID: 11380
java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Date xiaofei.library.hermestest.IUserManager.getDate1()' on a null object reference
at xiaofei.library.hermestest.DemoActivity$4.onClick(DemoActivity.java:71)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
1000 次,接口计算和回调用了1204毫秒
一样也是使用动态代理来实现的的简单demo, 耗时是333毫秒
目前手机是一加8,系统是Android 10
For example, I changed this code in demo UserManager class.
@MethodId("getUser")
@Override
public String getUser() {
// I tried 64k works.
return new String(new byte[1024*100]);
}
This got exception:
07-07 15:59:59.325 25466-25466/? E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!
07-07 15:59:59.325 25466-25466/? E/HERMES_INVOCATION: Error occurs. Error 1: Remote Exception: Check whether the process you are communicating with is still alive.
I suppose this hit the limit of android IPC max data size. But 100k or 10m is not a big size for modern android device.
update
Hi! Is possibile use this library for a communication Activity- Service???
大神,我们公司目前还停留在Eclipse的阶段,我是不是没办法用你这个神器了?
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/app/ActionBarActivity;
at xiaofei.library.hermes.util.TypeUtils$1.(TypeUtils.java:51)
at xiaofei.library.hermes.util.TypeUtils.(TypeUtils.java:48)
在另一个项目下~~发错了项目,没找到如何删除问题~~~~
看了半天,还是不理解。
我们现在用的aidl最多只支持到2M,所以后来这部分是用sharememory解决的,麻烦问下用你们的框架是否能解决数据量的问题?
我看了代码,如果Activity作为参数传递,接收到的是对方进程的Application context . 正常跳转是没问题,但是如果是需要返回值的startActivityForResult。就需要取得Activity的实例进行跳转。context 是不包含此方法的。我要怎么去获取传递过来的Activity 的实例?
CodeUtils中使用的静态变量GSON存在线程安全问题。
Getting error at runtime :
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/ActionBarActivity;
at xiaofei.library.hermes.util.TypeUtils$1.(TypeUtils.java:51)
at xiaofei.library.hermes.util.TypeUtils.(TypeUtils.java:48)
at xiaofei.library.hermes.util.TypeCenter.register(TypeCenter.java:94)
at xiaofei.library.hermes.Hermes.register(Hermes.java:71)
at xiaofei.library.hermeseventbus.HermesEventBus.init(HermesEventBus.java:122)
at com.cloudblocks.android.user.MainApplication.onCreate(MainApplication.java:44)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1036)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4728)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1415)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
I think its due to add(ActionBarActivity.class);
in > xiaofei.library.hermes.util.TypeUtils.java
For temporarily solving this issue, I created a empty class android.support.v7.app.ActionBarActivity.java
and extend to AppCompatActivity
and my app starting running again :)
package android.support.v7.app;
/**
* Created by blackadmin on 07/10/17.
*/
public class ActionBarActivity extends AppCompatActivity {
}
之前service0 启动后 验证 service 已经起~
public static boolean isServiceExisted(Context context, String className) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(Integer.MAX_VALUE);
if(!(serviceList.size() > 0)) {
return false;
}
for(int i = 0; i < serviceList.size(); i++) {
ActivityManager.RunningServiceInfo serviceInfo = serviceList.get(i);
ComponentName serviceName = serviceInfo.service;
if(serviceName.getClassName().equals(className)) {
return true;
}
}
return false;
}
但是到了 B APP进程里 总是绑不上~
@ClassId(“Singleton”)
public interface ISingleton {
@MethodId(“setData”)
void setData(String data);
@MethodId(“getData”)
String getData();
}
@ClassId(“Singleton”)
public class Singleton {
...
@MethodId(“setData”)
public void setData(String data) {
mData = data;
}
@MethodId(“getData”)
public String getData() {
return mData;
}
}
不知道有没有理解偏了。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.