在过去的几周里,我一直在研究一个Android应用程序,它的核心功能依赖于我编写的Groovy程序。我希望能够将我写的Groovy项目连接到我的android studio项目中。此外,我想从我的android活动中调用Groovy项目的主要功能。
基本上这种关系是这样的: - 将活动中的数据发送到Groovy主类 - Groovy用这些信息做了些什么 - 活动在过程结束时通知用户
但我仍然坚持如何让这两个人相处融洽。 我在android studio中开始了一个新项目,目的是练习和使用groovy和android。
每当我尝试将Groovy集成到android(GroovyShell,Eval,GroovyScriptEngine等等)中时,它会抛出MultipleCompilationErrorsException
这是我的主要活动:
package com.silverfix.groovyintegratedapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import groovy.lang.GroovyShell;
import groovy.util.Eval;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = (TextView) findViewById(R.id.text_view);
GroovyShell shell = new GroovyShell();
shell.evaluate("3*5");
}
}
错误输出:
E/AndroidRuntime:FATALEXCEPTION:main
Process:com.silverfix.groovyintegratedapp,PID:15604
java.lang.RuntimeException:UnabletostartactivityComponentInfo{com.silverfix.groovyintegratedapp/com.silverfix.groovyintegratedapp.MainActivity}:org.codehaus.groovy.control.MultipleCompilationErrorsException:startupfailed:
Generalerrorduringclassgeneration:can'tloadthistypeofclassfile
java.lang.UnsupportedOperationException:can'tloadthistypeofclassfile
atjava.lang.ClassLoader.defineClass(ClassLoader.java:300)
atjava.security.SecureClassLoader.defineClass(SecureClassLoader.java:93)
atgroovy.lang.GroovyClassLoader.access$400(GroovyClassLoader.java:62)
atgroovy.lang.GroovyClassLoader$ClassCollector.createClass(GroovyClassLoader.java:500)
atgroovy.lang.GroovyClassLoader$ClassCollector.onClassNode(GroovyClassLoader.java:517)
atgroovy.lang.GroovyClassLoader$ClassCollector.call(GroovyClassLoader.java:521)
atorg.codehaus.groovy.control.CompilationUnit$16.call(CompilationUnit.java:822)
atorg.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1053)
atorg.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591)
atorg.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
atorg.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
atgroovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
atgroovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
atgroovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
atgroovy.lang.GroovyShell.parse(GroovyShell.java:700)
atgroovy.lang.GroovyShell.evaluate(GroovyShell.java:584)
atgroovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
atgroovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
atcom.silverfix.groovyintegratedapp.MainActivity.onCreate(MainActivity.java:21)
atandroid.app.Activity.performCreate(Activity.java:5990)
atandroid.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
atandroid.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
atandroid.app.ActivityThread.access$800(ActivityThread.java:151)
atandroid.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
atandroid.os.Handler.dispatchMessage(Handler.java:102)
atandroid.os.Looper.loop(Looper.java:135)
atandroid.app.ActivityThread.main(ActivityThread.java:5254)
atjava.lang.reflect.Method.invoke(NativeMethod)
atjava.lang.reflect.Method.invoke(Method.java:372)
atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
1error
atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
atandroid.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
atandroid.app.ActivityThread.access$800(ActivityThread.java:151)
atandroid.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
atandroid.os.Handler.dispatchMessage(Handler.java:102)
atandroid.os.Looper.loop(Looper.java:135)
atandroid.app.ActivityThread.main(ActivityThread.java:5254)
atjava.lang.reflect.Method.invoke(NativeMethod)
atjava.lang.reflect.Method.invoke(Method.java:372)
atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Causedby:org.codehaus.groovy.control.MultipleCompilationErrorsException:startupfailed:
Generalerrorduringclassgeneration:can'tloadthistypeofclassfile
java.lang.UnsupportedOperationException:can'tloadthistypeofclassfile
atjava.lang.ClassLoader.defineClass(ClassLoader.java:300)
atjava.security.SecureClassLoader.defineClass(SecureClassLoader.java:93)