Unresolved Reference kotlinx - android

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"
}
}

Related

Hilt implement issue - Expected #HiltAndroidApp to have a value

I'm having a issue implement Hilt on android app...
The error is:
Expected #HiltAndroidApp to have a value. Did you forget to apply the Gradle Plugin?
Project gradle file
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
//Hilt
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
}
}
Model gradle file
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
dependencies {
def dagger_hilt_android = "2.38.1"
implementation("com.google.dagger:hilt-android:$dagger_hilt_android")
kapt("com.google.dagger:hilt-android-compiler:$dagger_hilt_android")
}
It is an issue with Kotlin-gradle-plugin: 1.5.20 as mentioned here https://github.com/google/dagger/issues/2684. Try upgrading your plugin to 1.5.21, and it will work.
Mohmd.h.bh,
Try applying this plugin in your build.gradle of your Android Gradle
apply plugin: 'com.google.dagger.hilt.android'
android {
// .......
}
I don't think you need to change the version of the kotlin-gradle-plugin
Regards

Is there any way to remove "classpath 'com.google.gms:google-services:4.2.0' dependency from top level project gradle

For firebase setup now my project gradle has classpath 'com.google.gms:google-services:4.2.0'.
app gradle contains apply plugin: 'com.google.gms.google-services'
I want to move firebase related code to the dynamic module
So I moved apply plugin: 'com.google.gms.google-services' from app Gradle to module Gradle
but classpath 'com.google.gms:google-services:4.2.0' is still related to full project.
Is there any way to remove this dependency from top-level project Gradle?
Just add the buildscript block inside the module/build.gradle file:
buildscript {
repositories {
//...
}
dependencies {
//..
classpath 'com.google.gms:google-services:4.2.0'
}
}

Outdated Kotlin Runtime warning in Android Studio

After downloaded and installed latest Kotlin plugin I have Outdated Kotlin Runtime warning from Android Studio that telling me:
Your version of Kotlin runtime in 'kotlin-stdlib-1.1.2' library is
1.1.2, while plugin version is 1.1.2-release-Studio2.3-3. Runtime library should be updated to avoid compatibility problems.
I tried to click Update Runtime button but getting another message:
Automatic library version update for Gradle projects is currently
unsupported. Please update your build.gradle manually.
How to solve this issue?
In your (Project: [projectName]) build.gradle file find this:
ext.kotlin_version = 'x.x.x' and replace x.x.x with the current version of your Kotlin plugin.
In order to check which is the current version of your Kotlin plugin:
Go to: Tools -> Kotlin -> Confugure Kotlin Plugin Updates
Click "Check again". After a second you will see the version of your Kotlin plugin. (If not up to date, your Kotlin plugin will be updated.)
N.B.: Also check your (Module: app) build.gradle file and assure that you do not use:
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.21"
but
compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.40'
Note the difference "...jre7..." -> "...jdk7...". Also replace "1.2.40" with your current Kotlin plugin version.
You can update your Kotlin version in your project level build.gradle file. If you have it configured the usual way, you should have the following line in it around the top:
ext.kotlin_version = '1.1.2'
To upgrade to the version matching your plugin, simply change this line to:
ext.kotlin_version = '1.1.2-3'
Edit (to respond to a question below):
The error tells you that you need to upgrade your version, the question is where to find out that you have to put in 1.1.2-3 instead of saying, for example, 1.1.2-release-Studio2.3-3.
The best way to find out the latest version of Kotlin is by going to kotlinlang.org and looking for "Latest version". Should be right there on the front page.
Another thing to do if the version number is non-trivial like this is to check the repositories where the versions are hosted. In the case of Android, you'll probably be getting it from jcenter, for which you can find the repository page, which has all the available versions listed.
You can also browse the raw maven repository of jcenter where the files are actually hosted by going here, or look up Kotlin either on mvnrepository or on mavencentral (raw version of the latter here).
it complained (on Android Studio 3.0.1) ...most likely because of referenced libraries' dependencies:
Your version of Kotlin runtime in 'org.jetbrains.kotlin:kotlin-stdlib:1.1.3#jar' library is 1.1.3, while plugin version is 1.1.51-release-Studio3.0-1.
then I've enforced building against the version it demanded, in the module level build.gradle:
configurations.all() {
resolutionStrategy.force 'org.jetbrains.kotlin:kotlin-stdlib:1.1.51'
}
and the result is:
./gradlew app:dependencies | grep kotlin
Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib/1.1.51/kotlin-stdlib-1.1.51.pom
| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.51
...
There are two pieces you may want to update:
kotlin runtime for the project
kotlin plugin
The answer by Ivo Stoyanov shows how to do this using the android studio menus. When I got the error message and tried this (updating the kotlin plugin) alone, it still complained about the kotlin runtime. You can update that on a project by project basis, by adding the line on ext.kotlin_version to the project build gradle, as some of the other answers indicate. But you'll need to know the kotlin runtime version for that. Alternatively, you can also do it through the menus, as I show here below, with the bonus that android studio shows you the available versions, and you can pick the most recent.
And then android studio will add in the appropriate line in your project build gradle.
changing your ext.kotlin_version from '1.1.2-4'to ext.kotlin_version = '1.1.2-5' solved the problem for me
the latest version of kotlin is 1.2.41 use this and syn your project.
buildscript {
ext.kotlin_version = '1.2.41'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
As of March 8, 2019 the current kotlin version is '1.3.21'
Under build.gradle
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
cheers
This issue comes when you update the kotlin plugin version popped up from android studio, but issue is current version of Android studio is not able to dynamically change the kotlin gradle plugin which is located in your project level Build.gradle file.
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.10"
}
How to solve this issue?
So you need to manually change this version, You can find that Here
I've run into this issue a few times in Android Studio and IDEA, found that if you go into your projects Gradle file and in your dependencies if you set the version of the kotlin-gradle-plugin to $kotlin_version then the warning message will tell you what version you need to set ext.kotlin_version to.
buildscript {
ext.kotlin_version = '1.2.40'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
buildscript {
ext.kotlin_version = '1.2.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
search for these two lines of code
ext.kotlin_version = '1.3.11'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
replace $kotlin_version with actual value (here it's 1.3.11)
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11"
after this your IDE will automatically suggest you the updated version
happy coding :)
Kotlin newest version:
buildscript {
ext.kotlin_version = '1.2.41'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.google.gms:google-services:1.5.0-beta2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Bit annoying but studio acts like it some times. Below steps can fix the issue.
Go to
Settings -> Build, Execution, Development -> Gradle -> Use default gradle wrapper(recommended)
change this to Use local and back to Use default. Studio will ask about updating gradle after closing the settings windows.
I was facing same problem after updation my android studio from 3.0.1 to 3.2.1.My problem was solved after using this.
buildscript {
ext.kotlin_version = '1.2.51'
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
I had faced this issue on latest Android Studio from Canary channel. You might want to consider downgrading Android Studio to stable version as well.
It happened for me on Android Studio 3.0 RC1.

issue with gradle 2.0.0 and DataBinding

Recently i have updated Android studio from 1.5.1 to 2.0, after updation it asked me to use latest gradle i.e. com.android.tools.build:gradle:2.0.0
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath "com.android.databinding:dataBinder:1.0-rc1"
}
But after updating it is showing error with DataBinding plugin.
apply plugin: 'com.android.databinding' //error on this line
Error message :
Error:(2, 0) Cause: org/apache/commons/lang3/StringUtils
Open File
I have not used any apache library or any deprected apache classes.
UPDATE :
Harshad's answer helped me, so final conclusion is we don't need to add those plugins with gradle 2.0.+
classpath "com.android.databinding:dataBinder:1.0-rc1" remove
apply plugin: 'com.android.databinding' remove
This may be help you.
You can just remove these two lines of code:
apply plugin: 'com.android.databinding'
And this one in buildscript's dependencies:
classpath 'com.android.databinding:dataBinder:1.0-rc1'
Then add the dataBinding section to your build.gradle like this.
buildscript {
...
}
android {
...
dataBinding {
enabled = true
}
...
}
dependencies {
...
}

com.android.library not find

I use gradle build my android code ,here is my build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
}
}
so I can apply
plugin:com.android.model.application ,but when I want to depend a module , I got a error:
error:plugin with com.android.library not find
which is my
android library module's build.gradle begin with
apply plugin: 'com.android.library
if I write build.gradle like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
I cannnot find
plugin: 'com.android.model.application' my question is what should I do to depend my library successfully
Hey you have to update the plugin to match the plugins available in the experimental build:
IE. change "com.android.library" to "com.android.model.library"
You can read more about it here on the experimental gradle build documentation.
Search for "com.android.model.library" and you'll go right to it.
Be sure to read the other stuff in the doc; there are other differences you will have to add to your old library-model build.gradle file also. (eg. "targetSdkVersion 23" changes to "targetSdkVersion.apiLevel 23"

Categories

Resources