Gradle DSL Method not found: testCompile() - java

Hi I am working on a project and have reached a stage where it would be unwise to continue without unit testing. I thought unit testing in Android Studio would be straight forward but I can't run my tests.
Here are my dependencies. Everything works fine until I add the last line of code. I then receive the error message that is in the title.
How do I fix this and run my tests?
Here was the tutorial I was following: http://tools.android.com/tech-docs/unit-testing-support

Official Unit testing support was introduced in Android plugin starting from version 1.1. This means that testCompile configuration is not available on previous versions. Based on your comment, you are using Android Gradle plugin version 1.0.0. That's why your build complains about missing testCompile configuration.
As of today, the latest released Android Gradle plugin version is 1.3.0, so I would suggest moving to this version ASAP.
What you need to do - is in root level build.gradle file update com.android.tools.build:gradle version to 1.3.0:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}

For me, the problem was solved by commenting out the following line in the top-level build.gradle:
testCompile() "org.robolectric:robolectric:3.3.2"

Related

jitpack not finding new versions of github repo but can find old ones

I have the following build.gradle file:
apply plugin: "java"
version '1.0'
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = ["src"]
allprojects {
repositories {
mavenCentral()
jcenter()
maven { url "https://jitpack.io" }
}
}
dependencies{
compileOnly 'com.github.Recessive:repo:v0.5'
implementation 'mysql:mysql-connector-java:8.0.12'
}
jar{
archiveFileName = "${project.archivesBaseName}.jar"
from{
configurations.runtimeClasspath.collect{it.isDirectory() ? it : zipTree(it)}
}
from(rootDir){
include "plugin.json"
}
}
That isn't working and returning the error
LocalRepo1:main: Could not find com.github.Recessive.repo:v0.5:.
To add salt to the wound, I released a v0.2 three months ago, and this works perfectly fine. Changing the line
compileOnly 'com.github.Recessive:repo:v0.5'
to
compileOnly 'com.github.Recessive:repo:v0.2'
will build with the older version no problem. I've released v0.3 to v0.5 as troubleshooting just to try and get jitpack to work, they are all functionally the same. I tried using the master-SNAPSHOT as well but this stopped working when I made the v0.3 release for unknown reasons.
The only error I will get regardless of the issue is the one stated before, making it basically impossible to know what is going on without significant knowledge of jitpack and gradle, hence the question here.
If anyone has any idea why this error might have suddenly popped up help would be greatly appreciated
EDIT: Also I know jitpack is returning the v0.2 version properly as I checked the link manually. While gradle is just building from the cached version jitpack is also behaving as expected
90% sure this was caused by the git history being too long (ie, over 500mb). To fix this I did the following:
git checkout --orphan <orphan-branch-name>
git commit
git push <remote-name> <orphan-branch-name>
This created an orphan branch with no commit history. Then in the build file I replaced the version with:
dependencies{
compileOnly "com.github.Recessive:repo:orphan-SNAPSHOT"
}
And it started working. Gradle/Jitpack has a horrendous lack of proper error reporting, as is evident but the most common error message from Jitpack having 10 different answers

im getting build error after connecting firebase with my code [duplicate]

I have just started a new project and am trying to connect to Firebase.
As soon as I try to build my project I got the error:
Could not parse the Android application Module's Gradle Config
So I looked in my build which told me that jCenter() was deprecated and that I should remove it. When I removed it, everything worked fine. However, when I tried to connect to Firebase I got the error:
AbstractDynamicObject$CustomMessageMissingMethodException.
What may be causing this?
Full stack trace:
Caused by: java.lang.RuntimeException: com.android.build.gradle.internal.crash.ExternalApiUsageException: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method setVariantDir() for arguments [debug] on task ':app:processDebugGoogleServices' of type com.google.gms.googleservices.GoogleServicesTask.
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:71)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:54)
at com.android.build.gradle.internal.profile.AnalyticsResourceManager.recordBlockAtConfiguration(AnalyticsResourceManager.kt:206)
at com.android.build.gradle.internal.profile.AnalyticsConfiguratorService.recordBlock(AnalyticsConfiguratorService.kt:85)
at com.android.build.gradle.internal.plugins.BasePlugin.lambda$createTasks$9(BasePlugin.java:582)
at com.android.build.gradle.internal.crash.CrashReporting$afterEvaluate$1.execute(crash_reporting.kt:37)
at com.android.build.gradle.internal.crash.CrashReporting$afterEvaluate$1.execute(crash_reporting.kt)
I came here because I am getting the same error. Luckily I was updating dependencies when it happened and narrowed it down to:
classpath 'com.google.gms:google-services:4.3.6'
Change it to
classpath 'com.google.gms:google-services:4.3.5'
The error goes away for me. Hopefully for you too
Here is more info on my dependencies.
Running Android Studio 4.2 build April 28 2021
repositories {
google()
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.6.0'
classpath 'com.google.firebase:perf-plugin:1.4.0'
Gradle Plugin 4.2.0
Gradle 7.0.1
//Firebase
implementation 'com.google.firebase:firebase-ads:20.1.0'
implementation 'com.google.firebase:firebase-core:19.0.0'
implementation 'com.google.firebase:firebase-crash:16.2.1'
implementation 'com.google.firebase:firebase-messaging:22.0.0'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
implementation 'com.google.firebase:firebase-auth:21.0.0'
implementation 'com.google.firebase:firebase-firestore:23.0.0'
Update : Google has just fixed the problem in version 4.3.8 (Release Notes)
An updated version of the google-services plugin for Android (v4.3.8) is now available. For more information, see the Firebase Android SDK Release Notes.
The error came from classpath 'com.google.gms:google-services:4.3.6'
The easiest solution :
Go back to version 4.3.5
dependencies {
classpath 'com.google.gms:google-services:4.3.5'
}
Instead of 4.3.6
dependencies {
classpath 'com.google.gms:google-services:4.3.6'
}
In fact, version 4.3.6 is responsible for this error. The easiest
way is to go back to the previous version until it is fixed
Caused by: java.lang.RuntimeException:
com.android.build.gradle.internal.crash.ExternalApiUsageException:
org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException:
Could not find method setVariantDir()
Fixed bug
You should use the latest possible version.
DO
dependencies {
classpath 'com.google.gms:google-services:4.3.8'
}
Addition to RRiven fix,
I started getting error Plugin with id ‘maven’ not found after RRiven fix.
I fixed it with downgrading gradle version to 6.9 from file -> project structure -> project -> gradle version
Set Code in build.gradle(Project)
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.google.gms:google-services:4.3.5'
Set Line in gradle-wrapper
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
Best way. Google has resolved it.
classpath 'com.google.gms:google-services:4.3.8'
Go to the latest version now of 4.3.8
https://developers.google.com/android/guides/releases
https://firebase.google.com/support/release-notes/android#google-services_plugin_v4-3-8
In Kotlin, Gradle version 7.3.3
1- build.gradle (Project)
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2- build.gradle (Module)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
id 'com.google.gms.google-services'
}

how to fix Android Annotations 4.6.0 compile with android Studio 3.5 and 3.5.0 gradle

I updated Android studio to 3.5 but there is a problem when I use android annotations
Gradle may disable incremental compilation as the following annotation processors are not incremental: jetified-androidannotations-4.6.0.jar (org.androidannotations:androidannotations:4.6.0).
Consider setting the experimental feature flag android.enableSeparateAnnotationProcessing=true in the gradle.properties file to run annotation processing in a separate task and make compilation incremental
I've put android.enableSeparateAnnotationProcessing=true in the gradle.properties file
but it's say that
INFO: The option setting 'android.enableSeparateAnnotationProcessing=true' is experimental and unsupported.
The current default is 'false'.
Could not find the AndroidManifest.xml file
I had almost the same problem and couldn't build my app after updating android studio and gradle to 3.5 but according to this answer I added this to my defaultConfig{} in app gradle and problem solved!
javaCompileOptions {
annotationProcessorOptions {
arguments = [
"androidManifestFile": "$projectDir/src/main/AndroidManifest.xml".toString()
]
}
}
There is 2 way of fixing this issue
Method One - Use Snapshot version
Current Annotation lib version is 4.6, to fix these error temporary you can use a Snapshot version
add the following URL in Project-level Gradle
buildscript {
repositories {
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' }
}
Method Two - Use javaCompileOptions
Add following code in gradle DSL
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
arguments = ["resourcePackageName": android.defaultConfig.applicationId]
arguments = ["androidManifestFile": "$projectDir/src/main/AndroidManifest.xml".toString()]
}
}
}
Hope it will work :)
AndroidAnnotations does not support Gradle incremental annotation processing, yet. You can still build your app, it only means that incremental compilation time is not as fast as it could be. There is an issue for tracking the implementation of incremental processing.
I suggest not to set android.enableSeparateAnnotationProcessing flag, as it is experimental, can cause other issues, and will slow down your clean builds.

Cannot find symbol error: Lombok 1.18.6 does not work with Gradle 5.2.1, JDK 10

Builds with Gradle 5.2.1 and Lombok 1.18.6 dependency are failing with JDK 10. It seems Lombok annotation are not being processed appropriately. I keep getting "cannot find symbol" error across various Java files in my source. Any thoughts on why this might be happening? I found that a defect has already been created: https://github.com/rzwitserloot/lombok/issues/1572
I am using:
Java JDK 10
Gradle 5.2.1
Lombok 1.18.6
Thanks.
I found the following work around for this issue using a plugin for processing Lombok annotation in compile time.
I had to perform the following steps in build.gradle:
1) Add id "net.ltgt.apt" version "0.15" to plugins section.
2) Add maven { url 'https://projectlombok.org/edge-releases' } to repositories section.
3) Add the following to dependencies section:
compileOnly 'org.projectlombok:lombok:edge-SNAPSHOT'
apt 'org.projectlombok:lombok:edge-SNAPSHOT'
compileOnly 'org.projectlombok:lombok:1.18:6'
annotationProcessor 'org.projectlombok:lombok:1.18:6'
4) Add a task:
tasks.withType(JavaCompile) {
options.annotationProcessorPath = configurations.apt
}
This lets your build complete successfully.
Update 03/29/2019: This workaround also works with Gradle 5.3, Java JDK 10
Thanks.

gradle project sync failed even after upgrading gradle plugin

Gradle project sync failed and did not get answers from other related questions. Here are the details of my situation.
Initial sync attempt yielded the following error message:
Unsupported method: BaseConfig.getApplicationIdSuffix().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.
I have Android Studio 3.0. The build.gradle file includes the following dependency:
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
The gradle-wrapper.properties file includes the following distribution URL:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
According to https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#update_gradle I need to make some changes.
First, update the Gradle version for Android Studio 3.0 in gradle-wrapper.properties:
distributionUrl=\
  https://services.gradle.org/distributions/gradle-4.1-all.zip
(I believe the backslash right after the equal sign is an error and did not make that change.)
Second, add the following buildscript repository to build.gradle:
google()
Third, change the build.gradle dependency:
classpath 'com.android.tools.build:gradle:3.0.1'
The second and third changes apply the latest version of the Android plug-in.
When I try to sync after these changes it fails again with the following new error:
Plugin with id 'com.android.model.application' not found.
The error refers to the first line of build.gradle:
apply plugin: 'com.android.model.application'
What is happening and why? I recently added NDK to Android Studio. The project I'm trying to sync includes C code. I'm not completely certain I added NDK correctly. I wonder if that could be part of the problem.
First, the gradle-wrapper.properties is incorrect. You must include \ in it. It should be something like this:
#Sat Jun 17 17:47:18 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Then, add the experimental classpath to project build.gradle. Something like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle-experimental:0.7.0-alpha4"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Check the Experimental Plugin User Guide for details.
Go to your build.gradle version or update it
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
You should change you dependencies classpath
All steps are here :
Open build.gradle and change the gradle version to the recommended version:
classpath 'com.android.tools.build:gradle:1.3.0' to
classpath 'com.android.tools.build:gradle:2.3.2'
Hit 'Try Again'
In the messages box it'll say 'Fix Gradle Wrapper and re-import project' Click that, since the minimum gradle version is 3.3
A new error will popup and say The SDK Build Tools revision (23.0.1) is too low for project ':app'. Minimum required is 25.0.0 - Hit Update Build Tools version and sync project
A window may popup that says Android Gradle Plugin Update recommended, just update from there.
Now the project should be runnable now on any of your android virtual devices.
Make sure your Gradle version is compatible with your Android Gradle Plugin.
https://stackoverflow.com/questions/24795079
https://developer.android.com/studio/releases/gradle-plugin#updating-gradle

Categories

Resources