例如,使用此处的 groovyshell-example 应用程序动态加载以下代码:https ://github.com/pieces029/grooidshell-example/tree/update/build-tools-and-scripts :
def class Outer {
def class Inner {}
}
new Outer.Inner()
结果 Android Emulator API 23
Result = Outer$Inner@a9ea1cd
结果 Android Emulator API 24
Result = null
API 24 中的堆栈跟踪
08-13 02:23:03.233 3147-3147/me.champeau.groovydroid E/GrooidShell: Dynamic loading failed!
BUG! exception in phase 'semantic analysis' in source unit 'script14710549832242032452851.groovy' throw with null exception
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:935)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:542)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:254)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:211)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:221)
at me.champeau.groovydroid.GrooidShell.evaluate(GrooidShell.java:85)
at me.champeau.groovydroid.GroovyActivity.generateMessage(GroovyActivity.groovy:38)
at me.champeau.groovydroid.GroovyActivity.executeCode(GroovyActivity.groovy:31)
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4693)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22260)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NullPointerException: throw with null exception
at java.net.URLClassLoader.findClass(URLClassLoader.java:371)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:677)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:545)
at org.codehaus.groovy.control.ClassNodeResolver.tryAsLoaderClassOrScript(ClassNodeResolver.java:185)
at org.codehaus.groovy.control.ClassNodeResolver.findClassNode(ClassNodeResolver.java:170)
at org.codehaus.groovy.control.ClassNodeResolver.resolveName(ClassNodeResolver.java:126)
at org.codehaus.groovy.control.ResolveVisitor.resolveToOuter(ResolveVisitor.java:676)
at org.codehaus.groovy.control.ResolveVisitor.resolve(ResolveVisitor.java:308)
at org.codehaus.groovy.control.ResolveVisitor.resolveNestedClass(ResolveVisitor.java:341)
at org.codehaus.groovy.control.ResolveVisitor.resolve(ResolveVisitor.java:308)
at org.codehaus.groovy.control.ResolveVisitor.resolve(ResolveVisitor.java:276)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:260)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:272)
at org.codehaus.groovy.control.ResolveVisitor.transformConstructorCallExpression(ResolveVisitor.java:1047)
at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:706)
at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitExpressionStatement(ClassCodeExpressionTransformer.java:142)
at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42)
at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:37)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:166)
at org.codehaus.groovy.control.ResolveVisitor.visitBlockStatement(ResolveVisitor.java:1318)
at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:71)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:104)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:115)
at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitConstructorOrMethod(ClassCodeExpressionTransformer.java:53)
08-13 02:23:03.234 3147-3147/me.champeau.groovydroid E/GrooidShell: at org.codehaus.groovy.control.ResolveVisitor.visitConstructorOrMethod(ResolveVisitor.java:201)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:126)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1078)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:53)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1261)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:176)
at org.codehaus.groovy.control.CompilationUnit$11.call(CompilationUnit.java:651)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:931)
... 21 more