I recently updated my JAVA to 1.8 version and also made android studio updates and gradle plugin updates as well. After the update i get following error in one of my module’s(i.e. facebook module) build.gradle file on compiling my project:
My project level build.gradle looks like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-beta4'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
}
}
allprojects {
repositories {
jcenter()
}
}
Also there are few Symbol not found error like Cannot resolve Symbol ‘GradleScriptException’ and Cannot resolve symbol ‘MavenDeployment’ in facebook module build.gradle file. The full code of facebook buil.gradle is:
apply plugin: 'com.android.library'
repositories {
mavenCentral()
}
project.group = 'com.facebook.android'
dependencies {
// Facbook Dependancies
testCompile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.parse.bolts:bolts-android:1.2.1'
// Unit Tests
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'org.robolectric:shadows-support-v4:3.0'
def powerMockVersion = '1.6.1'
testCompile "org.powermock:powermock-module-junit4:$powerMockVersion" testCompile "org.powermock:powermock-module-junit4-rule:$powerMockVersion" testCompile "org.powermock:powermock-classloading-xstream:$powerMockVersion" androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
testCompile "org.powermock:powermock-api-mockito:$powerMockVersion" androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
// Connected Tests
androidTestCompile 'org.mockito:mockito-core:1.10.19'
}
android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
multiDexEnabled true
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
dataBinding {
enabled = true
}
}
apply plugin: 'maven'
apply plugin: 'signing'
def isSnapshot = version.endsWith('-SNAPSHOT')
def ossrhUsername = hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
def ossrhPassword = hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
task setVersion {
// The version will be derived from source
project.version = null
def sdkVersionFile = file('src/main/java/com/facebook/FacebookSdkVersion.java')
sdkVersionFile.eachLine{
def matcher = (it =~ /(?:.*BUILD = ")(.*)(?:".*)/)
if (matcher.matches()) {
project.version = matcher[0][1]
return
}
}
if (project.version.is('unspecified')) {
throw new GradleScriptException('Version could not be found.', null)
}
}
uploadArchives {
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'Facebook-Android-SDK'
artifactId = 'facebook-android-sdk'
packaging 'aar'
description 'Facebook Android SDK'
url 'https://github.com/facebook/facebook-android-sdk'
scm {
connection 'scm:[email protected]:facebook/facebook-android-sdk.git'
developerConnection 'scm:[email protected]:facebook/facebook-android-sdk.git'
url 'https://github.com/facebook/facebook-android-sdk'
}
licenses {
license {
name 'Facebook Platform License'
url 'https://github.com/facebook/facebook-android-sdk/blob/master/LICENSE.txt'
distribution 'repo'
}
}
developers {
developer {
id 'facebook'
name 'Facebook'
}
}
}
}
}
uploadArchives.dependsOn(setVersion)
signing {
required { !isSnapshot && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
// JDK 1.8 is more strict then 1.7. Have JDK 1.8 behave like 1.7 for javadoc generation
if (org.gradle.internal.jvm.Jvm.current().getJavaVersion() == JavaVersion.VERSION_1_8) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
afterEvaluate {
androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
}
Clicking on Upgrade plugin and sync project
does not do anything.
I have tried “Invalidate cache and restart” as suggested by various sources but it didn’t work. I already have mentioned the latest version of gradle plugin in my project build.gradle.
I have gone through Gradle DSL Method not found: testCompile() but it does not resolve my issue.
What should i do to remove this compile error?
TIA
EDIT 1:
I made the change as suggested by sm4, And this DSL method not found error went off but now it fails to compile with the following error:
2
Answers
After trying the fix mentioned by @sm4 i resolved the initial issue that i mentioned but it created another issue written in EDIT 1 section of question.
I followed this answer and then finally my project got compiled without any error.
The
testCompile
is actually a call to a method. Because you have multipletestCompile
on one line, it is being treated as a call to a method with many parameters. Such method does not exist.Keep only one definition per line and it should work: