我目前正在尝试在MainActivity中运行一个groovy脚本。
apply plugin: 'com.android.application'
apply plugin: 'groovyx.grooid.groovy-android'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.8'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.muco.staemme"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile "org.gebish:geb-core:0.13.1"
compile "org.seleniumhq.selenium:selenium-firefox-driver:2.52.0"
compile "org.seleniumhq.selenium:selenium-support:2.52.0"
}
android.packagingOptions {
exclude 'META-INF/services/org.codehaus.groovy.transform.ASTTransformation'
exclude 'META-INF/services/org.codehaus.groovy.runtime.ExtensionModule'
exclude 'META-INF/LICENSE.txt'
}
package com.example.muco.staemme
import android.util.Log
import geb.Browser
class Gebbi extends Script{
public String run() {
Browser.drive {
go "https://www.die-staemme.de/"
$("#login_form").with {
user = "..."
password = "..."
cookie = false
}
$("span", class: "button_middle").click()
Log.i("groovy",$("span", class: "button_middle"))
}
}
}
我想在我的MainActivity(Java)中运行此代码,但我总是得到像
这样的错误java.lang.ExceptionInInitializerError
和
java.lang.NoClassDefFoundError: org.codehaus.groovy.control.io.NullWriter
与
GroovyShell shell = new GroovyShell()
或
GroovyClassLoader gcl = new GroovyClassLoader()
等。
有人可以告诉我,如何从JavaActivity调用groovy脚本?我也尝试在桌面上从java调用groovy脚本,它在那里运行。我搜索了Stackoverflow中的所有主题,这里是doc。
问候