将this示例代码导入Android Studio会出现此错误:
错误:(17,0)无法找到匹配的构造函数: org.gradle.api.internal.tasks.DefaultScalaSourceSet(java.lang.String中, org.gradle.api.internal.file.BaseDirFileResolver)
的build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:2.0.0"
classpath "jp.leafytree.gradle:gradle-android-scala-plugin:1.4"
}
}
repositories {
jcenter()
}
apply plugin: "com.android.application"
android{
compileSdkVersion "android-23"
buildToolsVersion "23.0.1"
}
apply plugin: "jp.leafytree.android-scala"
android {
defaultConfig {
targetSdkVersion 23
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
versionCode 1
versionName "1.0"
multiDexEnabled true
}
productFlavors {
dev {
minSdkVersion 21 // To reduce compilation time
}
prod {
minSdkVersion 8
}
}
dexOptions {
preDexLibraries false
javaMaxHeapSize "2g"
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile "org.scala-lang:scala-library:2.11.7"
compile "com.android.support:multidex:1.0.1"
androidTestCompile "com.android.support:multidex-instrumentation:1.0.1", { exclude module: "multidex" }
// to break 64k limit
compile "org.scalaz:scalaz-core_2.11:7.1.0"
compile "com.google.guava:guava-jdk5:17.0"
compile "org.apache.commons:commons-math3:3.3"
}
详细说明:
bash-3.2$ ./gradlew --info
Starting Build
Evaluating root project 'buildSrc' using build file '/Users/joco/dev/android/scala/gradle-android-scala-plugin/buildSrc/build.gradle'.
Selected primary task 'build' from project :
:compileJava (Thread[main,5,main]) started.
:buildSrc:compileJava
file or directory '/Users/joco/dev/android/scala/gradle-android-scala-plugin/buildSrc/src/main/java', not found
Skipping task ':compileJava' as it has no source files.
:buildSrc:compileJava UP-TO-DATE
:compileJava (Thread[main,5,main]) completed. Took 0.022 secs.
:compileGroovy (Thread[main,5,main]) started.
:buildSrc:compileGroovy
Executing task ':compileGroovy' (up-to-date check took 0.09 secs) due to:
Input file /Users/joco/.gradle/wrapper/dists/gradle-2.12-all/4ng70i0k4ou37vg5et2lk2qc7s/gradle-2.12/lib/plugins/maven-model-3.0.4.jar has been added.
Input file /Users/joco/.gradle/wrapper/dists/gradle-2.12-all/4ng70i0k4ou37vg5et2lk2qc7s/gradle-2.12/lib/plugins/servlet-api-2.5-20081211.jar has been added.
Input file /Users/joco/.gradle/wrapper/dists/gradle-2.12-all/4ng70i0k4ou37vg5et2lk2qc7s/gradle-2.12/lib/plugins/jsp-2.1-6.1.14.jar has been added.
Starting process 'Gradle Compiler Daemon 1'. Working directory: /Users/joco/dev/android/scala/gradle-android-scala-plugin/buildSrc Command: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java -Djava.security.manager=jarjar.org.gradle.process.internal.child.BootstrapSecurityManager -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp /Users/joco/.gradle/caches/2.12/workerMain/gradle-worker.jar jarjar.org.gradle.process.internal.launcher.GradleWorkerMain 'Gradle Compiler Daemon 1'
Successfully started process 'Gradle Compiler Daemon 1'
Started Gradle compiler daemon (0.516 secs) with fork options DaemonForkOptions{minHeapSize=null, maxHeapSize=null, jvmArgs=[], classpath=[/Users/joco/.gradle/wrapper/dists/gradle-2.12-all/4ng70i0k4ou37vg5et2lk2qc7s/gradle-2.12/lib/groovy-all-2.4.4.jar, /Users/joco/.gradle/wrapper/dists/gradle-2.12-all/4ng70i0k4ou37vg5et2lk2qc7s/gradle-2.12/lib/ant-1.9.3.jar, /Users/joco/.gradle/wrapper/dists/gradle-2.12-all/4ng70i0k4ou37vg5et2lk2qc7s/gradle-2.12/lib/ant-launcher-1.9.3.jar]}.
Executing org.gradle.api.internal.tasks.compile.ApiGroovyCompiler@58db718 in compiler daemon.
Successfully executed org.gradle.api.internal.tasks.compile.ApiGroovyCompiler@58db718 in compiler daemon.
:compileGroovy (Thread[main,5,main]) completed. Took 1.666 secs.
:processResources (Thread[main,5,main]) started.
:buildSrc:processResources
file or directory '/Users/joco/dev/android/scala/gradle-android-scala-plugin/buildSrc/src/main/resources', not found
Skipping task ':processResources' as it has no source files.
:buildSrc:processResources UP-TO-DATE
:processResources (Thread[main,5,main]) completed. Took 0.002 secs.
:classes (Thread[main,5,main]) started.
:buildSrc:classes
Skipping task ':classes' as it has no actions.
:classes (Thread[main,5,main]) completed. Took 0.001 secs.
:jar (Thread[main,5,main]) started.
:buildSrc:jar
Skipping task ':jar' as it is up-to-date (took 0.021 secs).
:buildSrc:jar UP-TO-DATE
:jar (Thread[main,5,main]) completed. Took 0.035 secs.
:assemble (Thread[main,5,main]) started.
:buildSrc:assemble
Skipping task ':assemble' as it has no actions.
:buildSrc:assemble UP-TO-DATE
:assemble (Thread[main,5,main]) completed. Took 0.002 secs.
:compileTestJava (Thread[main,5,main]) started.
:buildSrc:compileTestJava
file or directory '/Users/joco/dev/android/scala/gradle-android-scala-plugin/buildSrc/src/test/java', not found
Skipping task ':compileTestJava' as it has no source files.
:buildSrc:compileTestJava UP-TO-DATE
:compileTestJava (Thread[main,5,main]) completed. Took 0.002 secs.
:compileTestGroovy (Thread[main,5,main]) started.
:buildSrc:compileTestGroovy
file or directory '/Users/joco/dev/android/scala/gradle-android-scala-plugin/buildSrc/src/test/groovy', not found
Skipping task ':compileTestGroovy' as it has no source files.
:buildSrc:compileTestGroovy UP-TO-DATE
:compileTestGroovy (Thread[main,5,main]) completed. Took 0.002 secs.
:processTestResources (Thread[main,5,main]) started.
:buildSrc:processTestResources
file or directory '/Users/joco/dev/android/scala/gradle-android-scala-plugin/buildSrc/src/test/resources', not found
Skipping task ':processTestResources' as it has no source files.
:buildSrc:processTestResources UP-TO-DATE
:processTestResources (Thread[main,5,main]) completed. Took 0.002 secs.
:testClasses (Thread[main,5,main]) started.
:buildSrc:testClasses
Skipping task ':testClasses' as it has no actions.
:buildSrc:testClasses UP-TO-DATE
:testClasses (Thread[main,5,main]) completed. Took 0.001 secs.
:test (Thread[main,5,main]) started.
:buildSrc:test
file or directory '/Users/joco/dev/android/scala/gradle-android-scala-plugin/buildSrc/build/classes/test', not found
Skipping task ':test' as it has no source files.
:buildSrc:test UP-TO-DATE
:test (Thread[main,5,main]) completed. Took 0.001 secs.
:check (Thread[main,5,main]) started.
:buildSrc:check
Skipping task ':check' as it has no actions.
:buildSrc:check UP-TO-DATE
:check (Thread[main,5,main]) completed. Took 0.001 secs.
:build (Thread[main,5,main]) started.
:buildSrc:build
Skipping task ':build' as it has no actions.
:buildSrc:build UP-TO-DATE
:build (Thread[main,5,main]) completed. Took 0.001 secs.
Stopped 1 compiler daemon(s).
Settings evaluated using empty settings script.
Projects loaded. Root project using build file '/Users/joco/dev/android/scala/gradle-android-scala-plugin/sample/hello/build.gradle'.
Included projects: [root project 'hello']
Evaluating root project 'hello' using build file '/Users/joco/dev/android/scala/gradle-android-scala-plugin/sample/hello/build.gradle'.
Creating configuration compile
Creating configuration apk
Creating configuration provided
Creating configuration wearApp
Creating configuration androidTestCompile
Creating configuration androidTestApk
Creating configuration androidTestProvided
Creating configuration androidTestWearApp
Creating configuration testCompile
Creating configuration testApk
Creating configuration testProvided
Creating configuration testWearApp
Creating configuration debugCompile
Creating configuration debugApk
Creating configuration debugProvided
Creating configuration debugWearApp
Creating configuration testDebugCompile
Creating configuration testDebugApk
Creating configuration testDebugProvided
Creating configuration testDebugWearApp
Creating configuration releaseCompile
Creating configuration releaseApk
Creating configuration releaseProvided
Creating configuration releaseWearApp
Creating configuration testReleaseCompile
Creating configuration testReleaseApk
Creating configuration testReleaseProvided
Creating configuration testReleaseWearApp
Parsing the SDK, no caching allowed
Parsing /Users/joco/Library/Android/sdk/build-tools/20.0.0/package.xml
Parsing /Users/joco/Library/Android/sdk/build-tools/21.0.0/package.xml
Parsing /Users/joco/Library/Android/sdk/build-tools/21.1.2/package.xml
Parsing /Users/joco/Library/Android/sdk/build-tools/23.0.1/package.xml
Parsing /Users/joco/Library/Android/sdk/build-tools/23.0.3/package.xml
Parsing /Users/joco/Library/Android/sdk/build-tools/24.0.0/package.xml
Parsing /Users/joco/Library/Android/sdk/build-tools/24.0.1/package.xml
Parsing /Users/joco/Library/Android/sdk/extras/android/m2repository/package.xml
Parsing /Users/joco/Library/Android/sdk/extras/google/m2repository/package.xml
Parsing /Users/joco/Library/Android/sdk/platform-tools/package.xml
Parsing /Users/joco/Library/Android/sdk/platforms/android-20/package.xml
Parsing /Users/joco/Library/Android/sdk/platforms/android-21/package.xml
Parsing /Users/joco/Library/Android/sdk/platforms/android-23/package.xml
Parsing /Users/joco/Library/Android/sdk/platforms/android-24/package.xml
Parsing /Users/joco/Library/Android/sdk/sources/android-21/package.xml
Parsing /Users/joco/Library/Android/sdk/system-images/android-21/google_apis/x86_64/package.xml
Parsing /Users/joco/Library/Android/sdk/system-images/android-23/google_apis/x86_64/package.xml
Parsing /Users/joco/Library/Android/sdk/system-images/android-24/default/x86_64/package.xml
Parsing /Users/joco/Library/Android/sdk/tools/package.xml
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/joco/dev/android/scala/gradle-android-scala-plugin/sample/hello/build.gradle' line: 21
* What went wrong:
A problem occurred evaluating root project 'hello'.
> Failed to apply plugin [id 'jp.leafytree.android-scala']
> Could not find matching constructor for: org.gradle.api.internal.tasks.DefaultScalaSourceSet(java.lang.String, org.gradle.api.internal.file.BaseDirFileResolver)
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
BUILD FAILED
Total time: 6.334 secs
Stopped 0 compiler daemon(s).
知道如何解决这个问题吗?
答案 0 :(得分:7)
我刚刚将新版本上传到JitPack。
它支持Android Gradle Plugin 2.3.0和Gradle 3.3。
在你的项目build.gradle中:
buildscript {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.github.xingda920813:gradle-android-scala-plugin:android-gradle-2.3.0'
}
}