Why can't Gradle resolve the Kotlin Gradle plugin - android

I'm trying to manage my dependencies in Android Studio and it cannot resolve the Kotlin gradle plugin. I've tried manually adding it to my build.gradle using the code from Maven Central and adding it using the project structure feature in Android Studio.
As far as I know everything here is correct, so it should just download it and build.
(project) plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0-RC2' apply false
id 'org.jetbrains.kotlin.kapt' version '1.7.0-RC' apply false
}
---
(app) plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
---
//Kotlin dependencies (app)
implementation 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.7.0-RC'
implementation 'org.jetbrains.kotlin.kapt:org.jetbrains.kotlin.kapt.gradle.plugin:1.7.0-RC'
implementation 'com.google.devtools.ksp:symbol-processing-gradle-plugin:1.7.0-RC-1.0.5'
implementation 'org.jetbrains.kotlin.android:org.jetbrains.kotlin.android.gradle.plugin:1.7.0-RC'
implementation 'androidx.test:core-ktx:1.4.0'
implementation 'androidx.test.ext:junit-ktx:1.1.3'
implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0-RC2'
The details from the failed build are
The consumer was configured to find an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.0'. However we cannot choose between the following variants of org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0-RC2:
I'm rather inexperienced in android development, as I'm still a student and I've been thrown into a android app project by my school even though i haven't done the relevant classes. It's completely possible I'm doing something really obviously incorrect, but I can't identify it at my current skill level
How do I resolve this? Help would be greatly appreciated as my deadline is coming up soon and I've spent all day on this

Remove implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0-RC2' line from the app dependencies and there is no need id 'org.jetbrains.kotlin.kapt' version '1.7.0-RC' apply false in the project plugins
To solve these problems, my first suggestion to you is to update the Android version to the latest available version (Stable version today is Android Studio Chipmunk), and if the project is new, let Android Studio set and create all the gradle values for you by default from the beginning.

I'm a begginer too and this resolved for me
Open build.graddle (project) find dependecies and look for this line:
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0-RC2" (or other plugin version)
Replace with:
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_kotlin"

in build.gradle (project) replace
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
with
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version".
And it working

Open build.graddle (project) find buildscript and look for version_kotlin and copy version number
then Open build.graddle (project) again and find dependecies and look for this line:
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0" (or other plugin version)
Replace replace the version number with that copied

Related

Android Studio 4.0.2 Gradle Error: No value has been specified for property 'enableGradleWorkers'

I am using Android Studio 4.0.2 and I am getting error:
No value has been specified for property 'enableGradleWorkers'.
This happens because of crashlytics gradle plugin on version 2.7.1
To fix, simple downgrade to the latest working version:
open your project level build.gradle
dependencies {
//your stuff
//classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1' THIS VERSION DOESNT WORK
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.6.1'
}
UPDATE
As suggested by #صلي علي محمد Atef Farouk, recent versions of firebase-crashlytics-gradle plugin must be applied by last on build.grandle
So in your project level build.gradle you can use any version of but in the module level build.gradle you must ensure that com.google.firebase.crashlytics is the last one to be applied:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}
These are gradle combinations working fine for me .
in project level:
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.google.gms:google-services:4.3.8'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
so, if like this don't downgrade to any other version.
The trick is in gradle app level:
how?
you need to move this line apply plugin: 'com.google.firebase.crashlytics' to be last line in the file.
like this:
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
This worked for me.
There was a log at Build Output. There is an issue under
.gradle\caches\modules-2\files-2.1\folderofdependency'
Delete this cached folder and rebuild again.
For problem -
A problem was found with the configuration of task ':app:generateSafeArgsDebug' (type 'ArgumentsGenerationTask').
No value has been specified for property 'enableGradleWorkers'.
I solved it by using -
In App's gradle -
apply plugin: 'androidx.navigation.safeargs'
In Project's gradle -
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0-rc02'
The problem I had that I was using classpath of android.arch.xxxx
May be helpful to those who encountered this frustrating error like me.
This is likely due to the ordering of your plugins. See this SO to fix:
Type 'UploadMappingFileTask' property 'googleServicesResourceRoot' doesn't have a configured value
Add this to your gradle: android.enableGradleWorkers=true
See BooleanOption.kt
The problem originates from Android project itself
So I searched for a lot of solution but nothing works, So the only thing that you can do is:
Start a new Project
if the code is available on github them import it and please dont update the plugins
And from next time the thing that you can do is after each change in your android project test it if it is working fine, and keep pushing it on github
So that if any error appears again you can revert back the changes
If anyone solved this problem without creating a new project please tell

3rd-party Gradle plug-ins may be the cause

After updating to Android Studio 3.1 I got this error message:
The project works fine and this is mostly just a warning, so my question is what's the meaning of the warning and how can I get rid of it?
The relevant parts from gradle files:
This is my project's build.gradle
buildscript {
ext {
kotlin_version = '1.2.31'
anko_version = '0.10.4'
room_version = '1.0.0'
support_version = '27.1.0'
firebase_version = '12.0.0'
gms_version = '12.0.0'
}
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
}
}
And this is my app's build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
To solve the issue, remove Instant App Provision from the "Run Configurations" and leave only the Gradle-Aware Make.
Run -> Edit Configurations..
I have AndroidStudio 3.1, Gradle Plugin 3.1.0 and Kotlin library version 1.2.30.
I restarted Android Studio and the problem disappeared.
Click File -> Invalidate Caches/Restart
Every time I change the gradle file, I must restart Android Studio to or the problem returns.
You can also try this:
Re-ordered repositories to:
mavenCentral()
maven { url 'https://jitpack.io' }
google()
jcenter()
Clearing this folder: user's ~/.gradle/caches and deleting app
build folder manually, then clean and rebuild.
What fixed the issue for me:
Change gradle plugin version to 3.1.0
Change Kotlin version to 1.2.30
Then Android studio changed gradle wrapper to version 4.4
Then Android studio was saying that the build tools version used was
27.0.3 and that I should change it to 27.0.3 so I also changed the target SDK to 27
I added this to my gradle.build:
kapt {
generateStubs = true
}
I hope it helps
at android studio v3.1.2 , happen Error:
Folder D:\AndroidProjects\app\build\generated\source\kaptKotlin\debug
Folder D:\AndroidProjects\app\build\generated\source\kaptKotlin\release
3rd-party Gradle plug-ins may be the cause
because dataBinding use apply plugin: 'kotlin-kapt' so add
kapt {
generateStubs = true
}
Change gradle plugin version to 3.1.2
Change Kotlin version to 1.2.30
Then Android studio changed gradle wrapper to version 4.4
Then Android studio was saying that the build tools version used was
27.1.1 and that I should change it to 27.1.1 so I also changed the target SDK to 27
Here are some steps that I've followed. In my case it's fixed the issue!
Platform modules targeting Android
The update of the experimental multiplatform projects feature introduces support for Android platform modules. These modules should apply the corresponding plugin in the Gradle build script and can use the shared code from a common module:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-platform-android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
// ...
// ...
Kapt diagnostic locations
As of now, kapt, the Kotlin annotation processing tool, can offer links to locations in the original Kotlin code rather than generated Java stubs as it reports errors encountered during annotation processing. You can enable this feature by adding these lines to the Gradle build script (build.gradle):
kapt {
mapDiagnosticLocations = true
}
Add this:
allprojects {
repositories {
jcenter()
google()
}
}
Don't forget the next:
// Architecture Component - Room
implementation "android.arch.persistence.room:runtime:1.1.0-beta1"
kapt "android.arch.persistence.room:compiler:1.1.0-beta1"
// Lifecyles, LiveData and ViewModel
kapt 'com.android.databinding:compiler:3.1.0'
// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:1.1.1"
// alternatively, just ViewModel
implementation "android.arch.lifecycle:viewmodel:1.1.1"
// alternatively, just LiveData
implementation "android.arch.lifecycle:livedata:1.1.1"
kapt "android.arch.lifecycle:compiler:1.1.1"
// Room (use 1.1.0-beta1 for latest beta)
implementation "android.arch.persistence.room:runtime:1.0.0"
kapt "android.arch.persistence.room:compiler:1.0.0"
// Paging
implementation "android.arch.paging:runtime:1.0.0-alpha7"
// Test helpers for LiveData
testImplementation "android.arch.core:core-testing:1.1.1"
// Test helpers for Room
testImplementation "android.arch.persistence.room:testing:1.0.0"
Clean your project
Build and That's it!
Add all of this, Clean your project, build and That's it! :) Let me know if this works! (If it is not working for you, I will help you with another solution)
More Info: Android Site
:) Let me know if it works! (If it does not work, I will
try to help you finding a better way)
If you give a downVote explain why
What actually helped for me is adding this
kapt {
generateStubs = true
}
into build.gradle
Try removing Instant run from settings and gradle will good to go.
It worked for me.
Here are some steps that i have followed and it's fixed the issue in my case.
First of all install kotlin plugin version to '1.2.31' and update it in build.gradle file like below.
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$1.2.31"
}
Clean Project.
Finally Rebuild the project.
In my case none of the above solutions solved my problem, I was using 1.2.50 Kotlin version without any mention to Instant Run, and the build wasn't generating the Dagger classes, so I find out this question that solved my issue, apparently, in my situation it's an issue related to the new Kotlin version, so I downgraded to version 1.2.41 and worked fine.
By the way, I just tracked to that point because I used the Toggle View on Build screen.
1:Select the Toggle View and build your project
2:You're going to be able to see exactly what happened
Stackoverflow question:
Kotlin 1.2.50 asks for baseFeatureInfoDir
Issue tracker:
https://issuetracker.google.com/issues/110198434
remove apply plugin: 'kotlin-kapt'
add mavenCentral() in build.gradle like:
allprojects {
repositories {
mavenCentral()
google()
jcenter() } }
Sync and Clean project
Here is the some approach how I fix this issue for my case:
First of all update your android gradle plugin version from project build gradle file and then update your gradle version from gradle properties.
Finally update your kotlin version(Mandatory) to kotlin_version = '1.2.30' or later from project build gradle file.
Now try to clean your project and build. Issue should be resolved.
Each time after build if you build again then probably issue will occur again so, just clean your project again and then build.
This happens because the Kapt annotation processor uses this directory to store Kotlin generated files. Android currently does not recognize the path by default.
See Further Details
Adding another answer for those who could not remove Instant App Provision, because it keeps reappearing.
Build the project manually: ./gradlew assembleDebug
It is a hotfix, but it will work (because the issue is probably related to Android Studio).
I had this issue when using Realm with kotlin in android studio.
To solve follow these steps :
After adding Realm to project build.gradle, Make sure your app build.gradle file is like this:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
.
.
.
androidExtensions {
experimental = true
}
Use kapt instead of annotationProcessor in your app build.gradle dependencies.
Go to Run -> Edit Configurations.. and remove Instant App Provision option.
Run this command in Android studio's terminal :
gradlew assembleDebug
It's OK !
Note: If you see "3rd-party Gradle plug-ins may be the cause" message again, Do step 3 & 4 again.
Configuration on demand with Gradle 4.6 and above: If you're using
Android Gradle Plugin 3.0.x or 3.1.x with Gradle 4.6 and above, you
should disable configuration on demand to avoid some unpredictable
build errors. (If you are using Android Gradle Plugin 3.2.0 or higher,
you do not need to take any action to disable configuration on
demand.)
Disable configuration on demand in your gradle.properties file as
shown below:
org.gradle.configureondemand=false To disable configuration on demand
in the Android Studio settings, choose File > Settings (Android Studio
Preferences on Mac), select the Compiler category in the left pane, and clear the Configure on demand checkbox.
In Android Studio 3.2 Beta 1 and higher, the options for enabling
configuration on demand have been removed.
Please read known issues section from below link.
enter link description here
Actually,I was also facing the same error.
What i did is updating my kotlin version to the latest.
This may resolve Your problem.
Well, I found it is because of apply plugin: 'kotlin-kapt',if you delete this line in build.gradle(app), then you will build successfully...
Have no idea why this plugin results in these warnings.

Error when migrating Crashlytics to Firebase Android

I'm basically following the migration guide from within Crashlytics (which is pretty much summarized in this post).
I followed the same instructions verbatim, you can see that from my git diff:
Yet when I sync my Gradle, I get this error:
5:02 PM Gradle sync failed: Could not find method compile() for
arguments [com.google.firebase:firebase-core:11.4.2] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Update
As mentioned in the comments (and as experienced by us at the end), we shouldn't migrate anyway until further notice:
Update 2
In fabric, if you click on Crashlytics, there is a link on the left nav bar that says Firebase, when you click on it you get this ad
The buildscript block is not a place for your application level dependencies. See this answer for more information on the buildscript block.
You need to place your compile or implementation/api(for gradle 3.4+ and android gradle plugin 3.0+) dependencies into the separate dependencies{} block with the rest of your dependencies, that is usually on the same level as your android plugin configuration.
In your project level grade file, you need to add, maven {
url 'https://maven.fabric.io/public'
} to the repositories.
add the following to your dependencies classpath 'io.fabric.tools:gradle:1.25.1''
In your app level Gradle file put apply plugin: 'io.fabric' below apply plugin: 'com.android.application' and under depencies place this implementation('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true
}
place apply plugin:'com.google.gms.google-services' at the bottom of the app level gradle file.
Change compile '...' to implementation '...'
You are using Google Services plugin 3.0.0. The instructions for adding the Crashlytics SDK indicate that 3.1.2 or higher is required:
Note: Crashlytics requires Google Services plugin version 3.1.2 or
higher. Check the com.google.gms:google-services version number in
your project's build.gradle dependencies.

Gradle sync failed: Cause: org/gradle/listener/ActionBroadcast

Getting this error in Android studio canary 3.0 preview while building.
You do not need to remove the plugin, just update the version to 2.6.1.
plugins {
id "org.sonarqube" version "2.6.1"
}
You also have to add flavor dimension, check out this link:
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html?utm_source=android-studio#variant_aware
https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle
And if you're just applying the plugin and using a classpath, like this:
apply plugin: 'org.sonarqube'
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2'
Just change the version as defined in the classpath to:
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5'
And then just do a gradle sync again. That's all!

Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed

I just updated Google play services to the latest release - 23 - in the Android SDK Manager. Next I updated dependency in my project to:
com.google.android.gms:play-services-gcm:8.3.0
But I got:
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
:app:processDebugGoogleServices FAILED
Error:Execution failed for task ':app:processDebugGoogleServices'.
> Please fix the version conflict.
What is wrong? Do you have this problem also?
In your top-level build.gradle file you need to update the dependencies to use
classpath 'com.google.gms:google-services:1.5.0-beta2'
Extra Info:
The latest version of this can be found by looking at the entry on JFrog Bintray
Further Update:
Yes this has been updated since I answered the question. The latest version is:
classpath 'com.google.gms:google-services:3.0.0'
However, it's always worth following the provided link to find the latest version.
Working solution for 8.4.0 (maybe same for previous versions too with this crazy issue)
project build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:2.1.2'
}
app/mobile build.gradle
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'android-apt'
android {
...
...
...
}
dependencies {
// Google Play Services
compile 'com.google.android.gms:play-services-analytics:8.4.0'
// another play services in v8.4.0
}
apply plugin: 'com.google.gms.google-services' // why here on end? Because GOOGLE...
WARNING:
When you move apply plugin: 'com.google.gms.google-services' on top of build gradle, it can not compile...
The Google Play Services guides saved me from this problem
According to the guide,
In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.
From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:
compile 'com.google.android.gms:play-services:8.4.0'
with these lines:
compile 'com.google.android.gms:play-services-fitness:8.4.0'
compile 'com.google.android.gms:play-services-wearable:8.4.0'
I encountered this issue as well, although mine was
Found com.google.android.gms:play-services-gcm:8.4.0, but version
8.3.0 is needed
To fix, I combined Jeff Sutton and mtrakal's answers. I had to make sure I was using the latest Gradle plugin and Google Services versions in the project-level Gradle file (I had Gradle 1.5 and it didn't work):
classpath 'com.google.gms:google-services:2.0.0-beta6'
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
Then I put the apply plugin: 'com.google.gms.google-services' line in the last line of the app Gradle file.
In your top-level build.gradle file you need to change the dependencies to
classpath 'com.google.gms:google-services:+'
I am also getting the same of conflict com.google.android.gms:play-services-gcm:8.3.0 then
I have updated the google playservice tool then it has been resolved
From the SDK manager selected the tool and update now it resolve

Categories

Resources