kotlinCompilerVersion is deprecated - android

I've just started a new Jetpack Compose project using the "Empty Compose Activity" Android Studio (2020.3.1 Canary 14) template, but I'm getting the following warning in my build.gradle.kts (:app) file:
'kotlinCompilerVersion: String?' is deprecated.
The deprecation does not provide any information about what to use instead. Should I simply remove this option or do something else?

kotlinCompilerVersion can be safely removed.
Compose now uses the kotlin compiler defined in your buildscript.
buildscript {
ext.kotlin_version = '1.5.21'
//....
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
If you are using the plugins block (in settings.gradle or build.gradle)
pluginManagement {
//..
plugins {
id 'org.jetbrains.kotlin.android' version '1.5.21'
}
}

Related

How to add Crashlytics to the new architecture sample by Google

I am starting a new project by using the architecture-templates by google (https://github.com/android/architecture-templates)
In this template, they use Gradle with Kotlin DSL. I am trying to add Crashlytics to this project but the structure of gradle is quite different from my old projects.
I am stuck on the step 2 of the base guide (Firebase Get Started Documentation)
Error resolving plugin [id: 'com.android.application', version:
'7.3.1']
The request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so
compatibility cannot be checked.
Any suggestion?
After some research I found that the architecture template is based on gradle 7.6 which use the version catalog feature.
So I based my Version Catalog file on this https://github.com/RedMadRobot/gradle-version-catalogs/blob/main/versions-stack/libs.versions.toml
Now my build.gradle.kts file is
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.hilt.gradle)
alias(libs.plugins.firebase.crashlitycs)
alias(libs.plugins.gms.googleServices)
}
....
dependencies {
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.crashlytics)
implementation(libs.firebase.analytics)
}
I used to be confused about this too, but after some tries, I found the correct answer.
I think this is the first point of step 2 where you are confused. Just add the following code at the top of the project level build.gradle:
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.14'
}
}
Just follow the Google guide for the rest.
Complete code:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.14'
}
}
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Edited:
DSL version:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath("com.google.gms:google-services:4.3.14")
classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.2")
}
}
plugins {
id("com.android.application") version "7.2.2" apply false
id("com.android.library") version "7.2.2" apply false
id("org.jetbrains.kotlin.android") version "1.7.10" apply false
}
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
This website(Gradle Kotlinize - Groovy to Kotlin converter online) may be able to help you.

Upgrading compose/gradle

I copied project from GitHub and I want to modify it.
But I can't add LazyHorizontalGrid so I guess I need to update Jetpack Compose version or Gradle right?
What is proper way of doing that because if I do it with Project Structure as IDE suggest app crashes and I can't even build project.
I googled error and then next one and then next one and so on. But I think that it shouldn't be so hard to just update project.
LazyHorizontalGrid was added with 1.2.0 of the Compose Foundation dependency.
To update just change your build.gradle files.
In the root build.gradle file:
buildscript {
ext {
compose_version = '1.2.1'
}
//..
dependencies {
//...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
}
}
In your app/build.gradle:
android {
compileSdk 33
//...
composeOptions {
kotlinCompilerExtensionVersion 1.3.1
}
}
dependencies {
implementation "androidx.compose.foundation:foundation:$compose_version"
//...all the other compose dependencies
}
Check also the compatibility map for Compose Compiler Version/Kotlin Version.

Can I define kotlinVer either plugins or dependencies when I use Android Studio?

I find there are two ways to define kotlin version in build.gradle (Project) based some sample projects, such as Code A and Code B.
Are they the same way? which one is better?
Code A
buildscript {
ext {
kotlinVer = '1.7.10'
...
}
}
plugins {
...
id 'org.jetbrains.kotlin.android' version "$kotlinVer" apply false
}
Code B
buildscript {
ext {
...
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
...
}
}
Both serve the same purpose, and the reason they are different is because of newer Gradle upgrades from 7.1 upward.
You can check out how it's done in the android Doc. here

Unresolved Reference kotlinx

I am encountering with an error like
Unresolved reference: kotlinx
and the import statement is like
kotlinx.android.synthetic.main.activity_main.*
The bold code goes red and I am not able to use Kotlin Android extensions.This project was working fine for the past 2 days.
Seeing the other post,I added
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
in the Project level build.gradle and
apply plugin: 'kotlin-android-extensions'
in module level but they also fail.
Android studio version : 3.0.1
Kotlin version : 1.1.51
Thanks in advance :)
You only need the Kotlin plugin in your project level build.gradle file, as it itself includes Kotlin Android Extensions - there's no need for another Gradle dependency. That would look something like this:
buildscript {
ext.kotlin_version = '1.2.21'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Unresolved reference: kotlin
The kotlin-gradle-plugin compiles Kotlin sources and modules.
The version of Kotlin to use is usually defined as the kotlin_version property:
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Your build.gradle (Project Level) will be
buildscript {
ext.kotlin_version = '1.2.21'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Android Data Binding build.gradle syncing prob?

For databinding
1) I have added
android {
dataBinding {
enabled = true
}
to my project build.gradle, but this error occurs:
Error:(5, 0) Gradle DSL method not found: 'dataBinding()'
Possible causes:
.The project 'exampleDatabinding' may be using a version of Gradle that does
not contain the method.
Gradle settings
.The build file may be missing a Gradle plugin.
Apply Gradle plugin
2) Then I added:
apply plugin: "com.android.databinding" (to project build.gradle)
and classpath "com.android.databinding:dataBinder:1.0-rc1" (to project build.gradle)
But the same error occured.
In the file build.gradle of the project add the dependency
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0-beta2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
And in the file build.gradle of the module include the dataBinding section:
android{
...
dataBinding {
enabled = true
}
...
}
The versions of build.gradle can be found here: Versions
The project 'exampleDatabinding' may be using a version of Gradle that does
not contain the method.
You need to update your gradle to latest version 2.10
To update gradle do as follows
YourProject->gradle->wrapper->gradle-wrapper.properties
update the distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.
Also add dataBinding:
android{
...
dataBinding {
enabled = true
}
...
}
Also update your classpath:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}

Categories

Resources