Giter Site home page Giter Site logo

hermes's Issues

Error with java.util.Date type

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.errxiaofei.library.hermes.util.HermesException
07-23 02:33:25.976  11397-11414/xiaofei.library.hermestest:g W/System.errat xiaofei.library.hermes.util.TypeCenter.getClassType(TypeCenter.java:145)
07-23 02:33:25.976  11397-11414/xiaofei.library.hermestest:g W/System.errat xiaofei.library.hermes.receiver.InstanceGettingReceiver.<init>(InstanceGettingReceiver.java:44)
07-23 02:33:25.976  11397-11414/xiaofei.library.hermestest:g W/System.errat xiaofei.library.hermes.receiver.ReceiverDesignator.getReceiver(ReceiverDesignator.java:35)
07-23 02:33:25.976  11397-11414/xiaofei.library.hermestest:g W/System.errat xiaofei.library.hermes.HermesService$1.send(HermesService.java:48)
07-23 02:33:25.976  11397-11414/xiaofei.library.hermestest:g W/System.errat xiaofei.library.hermes.internal.IHermesService$Stub.onTransact(IHermesService.java:70)
07-23 02:33:25.976  11397-11414/xiaofei.library.hermestest:g W/System.errat android.os.Binder.execTransact(Binder.java:446)
07-23 02:33:25.979  11380-11380/? E/HERMESError occurs during getting instance. Error code: 16
07-23 02:33:25.979  11380-11380/? E/HERMESError 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/AndroidRuntimeShutting down VM
07-23 02:33:25.979  11380-11380/? E/AndroidRuntimeFATAL 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)

Can't send or receive data larger then 100k

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.

关于这个库的个人理解~

@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;
    }

}
  1. ISingleton 基本就是 java 版的 AIDL
  2. Singleton 可以看做 extends ISingleton.Stub (代入到AIDL视角的话)
  3. 底层由 Service + Binder 实现
  4. 使用了动态代理,某种程度上有点像Retrofit

不知道有没有理解偏了。

androidx报错

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)

启动第2个app进程的时候发现service0无法绑上

之前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进程里 总是绑不上~

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/ActionBarActivity;

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 {
}

不理解

看了半天,还是不理解。

Activity 作为参数传递

我看了代码,如果Activity作为参数传递,接收到的是对方进程的Application context . 正常跳转是没问题,但是如果是需要返回值的startActivityForResult。就需要取得Activity的实例进行跳转。context 是不包含此方法的。我要怎么去获取传递过来的Activity 的实例?

第二个APP

按照文档上写的,但是第二个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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.