Groovy CompileStatic on Android messes up Groovy Truth
In Groovy it is possible to test collections for null and empty simply by placing the variable by itself inside if like:
def collection = [ 'test' ]
if(!collection) {
//Collection is either null or empty, handle exceptional business here
}
However upon placing @CompileStatic
on the class which contains code like this, it stops working (but only on Android) with an error:
02-16 20:49:03.837: E/AndroidRuntime(9013): org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: java.util.ArrayList.asBoolean() is applicable for argument types: () values: []
This does not seem to occur when running the desktop version.
To give more context. This is a generated LibGDX project with three projects (-core, -desktop, -android) where the -core project has been converted to a groovy project. The -core project is referenced, and a dependency of both -desktop and -android projects
Desktop version works without any issues regardless whether the classes are annotated with @CompileStatic
annotation, and Groovy Truth is properly recognized.
On android on the other hand, the aforementioned error occurs.
I am not using the grooid library because the project which is converted to groovy is shared between both desktop and android.
If it's of any worth, here are the contents of build.gradle
on the project level:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.5'
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = 'CastleShuffle'
gdxVersion = '1.5.4'
roboVMVersion = '1.0.0-beta-04'
box2DLightsVersion = '1.3'
ashleyVersion = '1.3.1'
aiVersion = '1.5.0'
}
repositories {
mavenCentral()
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
}
}
project(":android") {
apply plugin: "android"
//apply plugin: "groovyx.grooid.groovy-android"
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
// compile 'org.codehaus.groovy:groovy:2.4.0:grooid' //Adding this causes a Dex exception where groovy class Bindable is referenced multiple times
// compile 'org.codehaus.groovy:groovy-all:2.4.0'
}
}
project(":core") {
apply plugin: "groovy"
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.0'
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
}
}
tasks.eclipse.doLast {
delete ".project"
}
You need to use the "grooid" version of Groovy for all your modules, otherwise you will have code generated that uses a runtime targetted at normal JVMs. Using '2.4.1-grooid' for all your modules should be good I think.
链接地址: http://www.djcxy.com/p/83762.html上一篇: 强制实现接口的类定义常量