W Groovy możliwe jest przetestowanie kolekcje nieważne i puste po prostu poprzez umieszczenie zmiennej sama wewnątrz jeśli tak:Groovy CompileStatic na Androida bałagan Groovy Prawdę
def collection = [ 'test' ]
if(!collection) {
//Collection is either null or empty, handle exceptional business here
}
Jednak po umieszczeniu @CompileStatic
od klasy, która zawiera Kod ten sposób, że przestaje działać (ale tylko na Androidzie) z błędem:
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: []
to nie wydaje się występować podczas uruchamiania wersji pulpitu.
Aby podać więcej kontekstu. Jest to wygenerowany projekt LibGDX z trzema projektami (-core, -desktop, -android), w których projekt -core został skonwertowany do ciekawego projektu. Odwołanie do projektu-projektu i zależność między projektami -desktop i tablicami
Wersja na komputery działa bez żadnych problemów, niezależnie od tego, czy klasy są opatrzone adnotacją z komentarzem , a Groovy Truth jest poprawnie rozpoznawany.
Na Androidzie pojawia się wspomniany błąd.
Nie korzystam z biblioteki grooid, ponieważ projekt, który jest konwertowany na groovy, jest dzielony między komputerami i systemem Android.
Jeśli jest jakiejkolwiek wartości, oto treść build.gradle
na poziomie projektu:
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"
}
Wydaje się, że są problemy ze ścieżkami do repozytoriów wgłębnych, kompilacja org.codehaus.groovy: groovy: 2.4.1: grooid'' w gradle tworzy inną ścieżkę niż ścieżka zależności rzeczywistych, więc nie mogę tego przetestować . Kiedy wymyślę, co jest nie tak i jak to naprawić, wypróbuję twoje rozwiązanie i odpowiednio rozdzielę nagrodę. Dzięki za pomoc. – MrPlow
Zawierasz zależność groovy-all od rdzenia do projektu Android. Trzeba to wykluczyć, ponieważ groovy-all i groids słoiki nie mogą być zestawiane razem. – Pieces