jcasbin icon indicating copy to clipboard operation
jcasbin copied to clipboard

Android Support Below API 26 (Oreo)

Open JeffPereyma opened this issue 3 years ago • 5 comments

Hello,

I am using the jCasbin library on Android, and it looks like one of the dependencies of the project AviatorScript is using a Java 8 Language method only supported in Android 26 and above. This makes the jCasbin library unusable for a large portion of devices (~20%).

The Java method in question is invokeExact(Object... args) and invoke(Object... args)

And while Android does support backwards compatibility for most Java 8 language features, you will notice in this documentation that it does not include the two methods mentioned above.

Thanks!

JeffPereyma avatar Apr 05 '22 16:04 JeffPereyma

@tangyang9464 @seriouszyx @elfisworking @fangzhengjin

casbin-bot avatar Apr 05 '22 16:04 casbin-bot

@JeffPereyma Do you have any good suggestions to solve the issue? Android official advice can't solve this issue.

tangyang9464 avatar Apr 06 '22 04:04 tangyang9464

@JeffPereyma what Java SDK version do you need?

hsluoyz avatar Apr 06 '22 10:04 hsluoyz

@hsluoyz @tangyang9464 Java 7 and 8 features should all be fine, but it is specifically the MethodHandle class that is not available. My understanding is Android ports over their own version of Java as part of it's Android SDK. It would seem these ports for earlier versions of Android do not include the MethodHandle class.

Since then it seems they have been able to do things like desguaring to allow access to the newer features on older versions, but it specifically excludes the MethodHandle class as I referenced above.

I'm not sure on the fix (outside of removing the problem method from the dependency). But as to what to replace it with I am not sure as this is quite outside of my wheelhouse, but I will see if I can stumble through enough to give some better ideas.

I did find a similar issue on another android library that ran into the same issue (Library: Mockito, offending dependency: Objenesis). It looks like maybe they were able to solve the issue but I'm not totally sure I can confidently follow it.

This is the issue that was opened on the offending project: https://github.com/easymock/objenesis/issues/79

I'll continue to dig around but hopefully that at least gives some hints towards a solution?

JeffPereyma avatar Apr 06 '22 19:04 JeffPereyma

@JeffPereyma can you create an issue at: https://github.com/killme2008/aviatorscript ?

hsluoyz avatar Apr 07 '22 01:04 hsluoyz

@hsluoyz @JeffPereyma It sounds like the problem you're experiencing is due to the fact that the java.lang.invoke.MethodHandles class, which includes the invokeExact and invoke methods, is not supported on Android versions prior to 26. If the jCasbin library is using these methods and you need to support older Android versions, you may need to find a way to work around this limitation.

One option you might consider is trying to use a version of the jCasbin library that does not rely on these methods. It's possible that such a version exists, although I don't have any specific information on this. Another option could be to try modifying the jCasbin library to use an alternative approach that does not rely on these methods. This might involve replacing the use of java.lang.invoke.MethodHandles with a different reflection-based approach that is compatible with older Android versions.

PrathamJaiswal001 avatar Jan 07 '23 10:01 PrathamJaiswal001