在Android上运行Clojure:“无法加载此类文件”

时间:2018-10-30 18:18:47

标签: android gradle clojure jvm javafxports

我正在尝试让Clojure和JavaFXPorts在Android上运行。但是它在启动时使用以下stacktrace崩溃。我对JVM内部了解甚少,所以我不知道为什么会发生这种特殊的UnsupportedOperationException。我的假设是Clojure向其编译器注册了新的类文件类型,由于某种原因,它在Android上失败-至少与JavaFXPorts结合使用(我没有尝试在没有JavaFXPorts的情况下创建Android应用;我将需要它无论如何)。

10-30 19:00:24.450 11088 11130 W System.err: java.lang.reflect.InvocationTargetException
10-30 19:00:24.450 11088 11130 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
10-30 19:00:24.450 11088 11130 W System.err:    at javafxports.android.DalvikLauncher$1.run(DalvikLauncher.java:188)
10-30 19:00:24.451 11088 11130 W System.err:    at java.lang.Thread.run(Thread.java:761)
10-30 19:00:24.452 11088 11130 W System.err: Caused by: java.lang.RuntimeException: Unable to construct Application instance: class lyrion.cec.core
10-30 19:00:24.452 11088 11130 W System.err:    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
10-30 19:00:24.452 11088 11130 W System.err:    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$138(LauncherImpl.java:182)
10-30 19:00:24.453 11088 11130 W System.err:    at com.sun.javafx.application.LauncherImpl.access$lambda$1(LauncherImpl.java)
10-30 19:00:24.453 11088 11130 W System.err:    at com.sun.javafx.application.LauncherImpl$$Lambda$2.run(Unknown Source)
10-30 19:00:24.453 11088 11130 W System.err:    ... 1 more
10-30 19:00:24.454 11088 11130 W System.err: Caused by: java.lang.ExceptionInInitializerError
10-30 19:00:24.454 11088 11130 W System.err:    at java.lang.Class.classForName(Native Method)
10-30 19:00:24.454 11088 11130 W System.err:    at java.lang.Class.forName(Class.java:400)
10-30 19:00:24.454 11088 11130 W System.err:    at clojure.lang.RT.classForName(RT.java:2204)
10-30 19:00:24.454 11088 11130 W System.err:    at clojure.lang.RT.classForName(RT.java:2213)
10-30 19:00:24.455 11088 11130 W System.err:    at clojure.lang.RT.loadClassForName(RT.java:2232)
10-30 19:00:24.455 11088 11130 W System.err:    at clojure.lang.RT.load(RT.java:450)
10-30 19:00:24.455 11088 11130 W System.err:    at clojure.lang.RT.load(RT.java:426)
10-30 19:00:24.455 11088 11130 W System.err:    at clojure.lang.RT.doInit(RT.java:468)
10-30 19:00:24.455 11088 11130 W System.err:    at clojure.lang.RT.<clinit>(RT.java:336)
10-30 19:00:24.455 11088 11130 W System.err:    at clojure.lang.Namespace.<init>(Namespace.java:34)
10-30 19:00:24.456 11088 11130 W System.err:    at clojure.lang.Namespace.findOrCreate(Namespace.java:176)
10-30 19:00:24.456 11088 11130 W System.err:    at clojure.lang.Var.internPrivate(Var.java:153)
10-30 19:00:24.456 11088 11130 W System.err:    at lyrion.cec.core.<clinit>(Unknown Source)
10-30 19:00:24.456 11088 11130 W System.err:    at java.lang.reflect.Constructor.newInstance0(Native Method)
10-30 19:00:24.456 11088 11130 W System.err:    at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
10-30 19:00:24.456 11088 11130 W System.err:    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$144(LauncherImpl.java:819)
10-30 19:00:24.457 11088 11130 W System.err:    at com.sun.javafx.application.LauncherImpl.access$lambda$7(LauncherImpl.java)
10-30 19:00:24.457 11088 11130 W System.err:    at com.sun.javafx.application.LauncherImpl$$Lambda$8.run(Unknown Source)
10-30 19:00:24.457 11088 11130 W System.err:    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$158(PlatformImpl.java:326)
10-30 19:00:24.457 11088 11130 W System.err:    at com.sun.javafx.application.PlatformImpl.access$lambda$6(PlatformImpl.java)
10-30 19:00:24.457 11088 11130 W System.err:    at com.sun.javafx.application.PlatformImpl$$Lambda$7.run(Unknown Source)
10-30 19:00:24.457 11088 11130 W System.err:    at com.sun.javafx.application.PlatformImpl.lambda$null$156(PlatformImpl.java:295)
10-30 19:00:24.458 11088 11130 W System.err:    at com.sun.javafx.application.PlatformImpl.access$lambda$18(PlatformImpl.java)
10-30 19:00:24.458 11088 11130 W System.err:    at com.sun.javafx.application.PlatformImpl$$Lambda$19.run(Unknown Source)
10-30 19:00:24.458 11088 11130 W System.err:    at java.security.AccessController.doPrivileged(AccessController.java:57)
10-30 19:00:24.458 11088 11130 W System.err:    at com.sun.javafx.application.PlatformImpl.lambda$runLater$157(PlatformImpl.java:294)
10-30 19:00:24.458 11088 11130 W System.err:    at com.sun.javafx.application.PlatformImpl.access$lambda$5(PlatformImpl.java)
10-30 19:00:24.458 11088 11130 W System.err:    at com.sun.javafx.application.PlatformImpl$$Lambda$6.run(Unknown Source)
10-30 19:00:24.459 11088 11130 W System.err:    at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:93)
10-30 19:00:24.459 11088 11130 W System.err:    at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:52)
10-30 19:00:24.459 11088 11130 W System.err:    ... 1 more
10-30 19:00:24.460 11088 11130 W System.err: Caused by: java.lang.UnsupportedOperationException: can't load this type of class file, compiling:(clojure/core_instant18.clj:9:1)
10-30 19:00:24.460 11088 11130 W System.err:    at clojure.lang.Compiler.analyzeSeq(Compiler.java:7010)
10-30 19:00:24.461 11088 11130 W System.err:    at clojure.lang.Compiler.analyze(Compiler.java:6773)
10-30 19:00:24.461 11088 11130 W System.err:    at clojure.lang.Compiler.eval(Compiler.java:7059)
10-30 19:00:24.461 11088 11130 W System.err:    at clojure.lang.Compiler.load(Compiler.java:7514)
10-30 19:00:24.493 11088 11130 W System.err:    at clojure.lang.RT.loadResourceScript(RT.java:379)
10-30 19:00:24.494 11088 11130 W System.err:    at clojure.lang.RT.loadResourceScript(RT.java:370)
10-30 19:00:24.494 11088 11130 W System.err:    at clojure.lang.RT.load(RT.java:460)
10-30 19:00:24.494 11088 11130 W System.err:    at clojure.lang.RT.load(RT.java:426)
10-30 19:00:24.494 11088 11130 W System.err:    at clojure.core$load$fn__6548.invoke(core.clj:6046)
10-30 19:00:24.494 11088 11130 W System.err:    at clojure.core$load.invokeStatic(core.clj:6045)
10-30 19:00:24.495 11088 11130 W System.err:    at clojure.core$load.doInvoke(core.clj:6029)
10-30 19:00:24.495 11088 11130 W System.err:    at clojure.lang.RestFn.invoke(RestFn.java:408)
10-30 19:00:24.495 11088 11130 W System.err:    at clojure.core$fn__8055.invokeStatic(core.clj:6709)
10-30 19:00:24.495 11088 11130 W System.err:    at clojure.core$fn__8055.invoke(core.clj:6708)
10-30 19:00:24.495 11088 11130 W System.err:    at clojure.core__init.load(Unknown Source)
10-30 19:00:24.495 11088 11130 W System.err:    at clojure.core__init.<clinit>(Unknown Source)
10-30 19:00:24.496 11088 11130 W System.err:    ... 31 more
10-30 19:00:24.497 11088 11130 W System.err: Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
10-30 19:00:24.497 11088 11130 W System.err:    at java.lang.ClassLoader.defineClass(ClassLoader.java:520)
10-30 19:00:24.497 11088 11130 W System.err:    at clojure.lang.DynamicClassLoader.defineClass(DynamicClassLoader.java:46)
10-30 19:00:24.497 11088 11130 W System.err:    at clojure.lang.Compiler$ObjExpr.getCompiledClass(Compiler.java:4979)
10-30 19:00:24.498 11088 11130 W System.err:    at clojure.lang.Compiler$FnExpr.parse(Compiler.java:4109)
10-30 19:00:24.498 11088 11130 W System.err:    at clojure.lang.Compiler.analyzeSeq(Compiler.java:7001)
10-30 19:00:24.498 11088 11130 W System.err:    ... 46 more

2 个答案:

答案 0 :(得分:0)

lein uberjar将为您构建一个标准的JVM jar。这些字节码将无法在Android的Dalvik JVM表亲中运行。

尝试将您的课程制作为dex文件:https://developer.android.com/studio/command-line/d8

答案 1 :(得分:0)

首先破坏者:对于Clojure,它已经完成了。

问题在于Clojure有一个DynamicClassLoader,您可能会猜到它会在运行时加载由类组成的类,而Android不支持该类。实际上,您可以通过ClassLoader.defineClass()在JVM上执行此操作,但是该方法在Android上的实现只会引发您看到的异常,这意味着Clojure甚至无法在Android上初始化。

另一个问题是,即使该方法可用,Android也将无法运行Clojure生成的JVM字节码,正是因为它是JVM字节码。

幸运的是,this hero通过添加另一个动态ClassLoader解决了此问题,该动态production.ERROR: There was an error while creating the signature: error:04066044:rsa routines:rsa_ossl_private_encrypt:internal error {"exception":"[object] (InvalidArgumentException(code: 0): There was an error while creating the signature: error:04066044:rsa routines:rsa_ossl_private_encrypt:internal error at /api/vendor/lcobucci/jwt/src/Signer/OpenSSL.php:27) [stacktrace] #0 /api/vendor/lcobucci/jwt/src/Signer/BaseSigner.php(36): Lcobucci\\JWT\\Signer\\OpenSSL->createHash('eyJ0eXAiOiJKV1Q...', Object(Lcobucci\\JWT\\Signer\\Key)) #1 /api/vendor/lcobucci/jwt/src/Builder.php(470): Lcobucci\\JWT\\Signer\\BaseSigner->sign('eyJ0eXAiOiJKV1Q...', Object(Lcobucci\\JWT\\Signer\\Key)) #2 /api/vendor/lcobucci/jwt/src/Builder.php(450): Lcobucci\\JWT\\Builder->createSignature(Array, Object(Lcobucci\\JWT\\Signer\\Rsa\\Sha256), Object(Lcobucci\\JWT\\Signer\\Key)) #3 /api/vendor/league/oauth2-server/src/Entities/Traits/AccessTokenTrait.php(41): Lcobucci\\JWT\\Builder->getToken() #4 /api/vendor/league/oauth2-server/src/ResponseTypes/BearerTokenResponse.php(28): Laravel\\Passport\\Bridge\\AccessToken->convertToJWT(Object(League\\OAuth2\\Server\\CryptKey)) #5 /api/vendor/league/oauth2-server/src/AuthorizationServer.php(202): League\\OAuth2\\Server\\ResponseTypes\\BearerTokenResponse->generateHttpResponse(Object(Zend\\Diactoros\\Response)) #6 /api/vendor/laravel/passport/src/Http/Controllers/AccessTokenController.php(63): League\\OAuth2\\Server\\AuthorizationServer->respondToAccessTokenRequest(Object(Zend\\Diactoros\\ServerRequest), Object(Zend\\Diactoros\\Response)) #7 /api/vendor/laravel/passport/src/Http/Controllers/HandlesOAuthErrors.php(28): Laravel\\Passport\\Http\\Controllers\\AccessTokenController->Laravel\\Passport\\Http\\Controllers\\{closure}() #8 /api/vendor/laravel/passport/src/Http/Controllers/AccessTokenController.php(65): Laravel\\Passport\\Http\\Controllers\\AccessTokenController->withErrorHandling(Object(Closure)) #9 /api/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(48): Laravel\\Passport\\Http\\Controllers\\AccessTokenController->issueToken(Object(Zend\\Diactoros\\ServerRequest)) #10 /api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(Laravel\\Passport\\Http\\Controllers\\AccessTokenController), 'issueToken') #11 /api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\\Routing\\Route->runController() #12 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(680): Illuminate\\Routing\\Route->run() #13 /api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request)) #14 /api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(58): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request)) #15 /api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #16 /api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #17 /api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request)) #18 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(682): Illuminate\\Pipeline\\Pipeline->then(Object(Closure)) #19 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(657): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request)) #20 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(623): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route)) #21 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(612): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request)) #22 /api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request)) #23 /api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request)) 将动态类的字节转换为DEX文件,然后转换为ODEX以供Android运行时接受(如果没有,则非常相似)与Instant Run在Android Studio上所做的相同)。

很遗憾,那是在2011年,他的Clojure fork至今已有四年没有养护。

您可以看到Clojure的Android fork的作者在他精彩的talk at ClojureConj 2011中对其进行了解释。