After adding Kotlin to a module I get the following error when syncing:
Error:null cannot be cast to non-null type org.jetbrains.kotlin.gradle.internal.WrappedVariantData
I added the kotlin plugin to this project. It is an appengine module. I'm running:
AS 2.3.2
gradle 3.4
kotlin 1.1.2-3
using these plugins:
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin'
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
apply plugin: 'idea'
Any ideas?
This is a known bug in the kotlin-kapt plugin. There is a fix in 1.1.3, which is currently in EAP and should be released very soon to stable(June 2017).
More info:
https://youtrack.jetbrains.com/issue/KT-17999#tab=Comments
Related
There is a build.gradle files in project level and module level. Both has a plugin section, i.e., the following is what I have:
project/build.gradle:
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}
project/app/build.gradle:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
the one in project level seems have extra one, and having version and apply false. Anyone can give me some explanation or any documentation?
I'm using the latest Android Studio and I'm able to build and run my app fine with compose_version set to 1.0.5. However, I'd like to use the latest stable compose version 1.1.1.
I try to simply update the project build.gradle so it contains the following pointing to the desired compose version and the corresponding compatible kotlin version. These values are referenced in the app's build.gradle.
buildscript {
ext {
compose_version = '1.1.1'
kotlin_version = '1.6.10'
}
And in Android Studio, I go to Tools > Kotlin > Configure Kotlin Plugin Updates and download the latest Kotlin plugin (Early Access).
If I open Tools > Kotlin > Kotlin REPL, I see Welcome to Kotlin version 1.7.0-RC2-release-258 (JRE 11.0.12+0-b1504.28-7817840).
Now, I try to Rebuild Project.
I get the error:
This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.5.31 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).
I don't wish to suppressKotlinVersionCompatibilityCheck given the warning, but I even tried that option and got other build errors.
Why is Kotlin version 1.5.31 being used? Shouldn't updating the Kotlin plugin have gotten Android Studio to switch to a more recent Kotlin version (as suggested by the Kotlin REPL message)? How can I make it such that Kotlin 1.6.10 is used and I stop getting the error?
Got the same error when using Compose 1.1.1. and Kotlin 1.7.0.
Task :app:compileDebugKotlin FAILED
e: This version (1.1.1) of the Compose Compiler requires
Kotlin version 1.6.10 but you appear to be using Kotlin version 1.7.0
which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).
Changed the below block in my build.gradle (app module)
composeOptions {
kotlinCompilerExtensionVersion 1.2.0
}
This is my plugins block in build.gradle (project):
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
id 'org.jetbrains.kotlin.jvm' version '1.7.0' apply false
}
This Android developers page helped with picking the compatible versions :-
Compose to Kotlin Compatibility Map
Don't forget to sync and rebuild.
Compose uses the kotlin compiler defined in your buildscript block:
buildscript {
ext.kotlin_version = '1.6.10'
//....
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.6.10'
}
}
Using this help me.
build.gradle (:app)
composeOptions {
kotlinCompilerExtensionVersion = "1.2.0-beta03"
}
There are 3 things you need to ensure are in sync(compatible with the other) for kotlin to work properly.
1)compose_ui_version='1.2.1' of buildscript in build.gradle(project)
2)plugin 'org.jetbrains.kotlin.android' version '1.7.10' in build.gradle(project)
3)kotlinCompilerExtensionVersion '1.3.1' in composeOptions in build.gradle(app)
To get the latest version of compose compiler and its corresponding kotlin version check here.
for me what I had to edit is to locate build graddle(Project):
first load compose_version to see the latest stable compose_version.
buildscript {
ext {
//2. change here to the latest stable (compose_version) that you got in step 1
compose_version = '1.3.0'
}
repositories {
google()
mavenCentral()
}
dependencies {
//when you run you app, The next error will tell you the version of Kotlin that the latest compose_version needs, edit as below to the version required in the error
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
}
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
}
}
plugins {
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
and build.gradle(Module)
composeOptions {
kotlinCompilerExtensionVersion '1.1.1'
}
Go to your project level build.gradle file
There in the plugin section below mentioned 2 libraries has to be in the same version to remove this error:
{
...
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'org.jetbrains.kotlin.jvm' version '1.6.10' apply false
}
If required, change:
compileSdk 33
&
targetSdk to 33
. (inside app level build.gradle file).
Now sync the project & reload the priview. It will work fine.
I was tried to run my code in Kotlin 1.5.10
With plugin as
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
and dependencies as below
dependencies {
...
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.33-beta"
kapt "com.google.dagger:hilt-android-compiler:2.33-beta"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0-beta01"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha01'
implementation 'com.android.support:palette-v7:28.0.0'
When I migrate to kotlin_version = "1.5.10", it just errors out stating
error: [Hilt]
Unsupported metadata version. Check that your Kotlin version is >= 1.0: java.lang.IllegalStateException: Unsupported metadata version. Check that your Kotlin version is >= 1.0
at dagger.internal.codegen.kotlin.KotlinMetadata.metadataOf(KotlinMetadata.java:206)
at dagger.internal.codegen.kotlin.KotlinMetadata.from(KotlinMetadata.java:186)
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1133)
...
Can anyone help me? I spent a lot of time on it, your answer will help me a lot
Go to https://dagger.dev/hilt/gradle-setup check Hilt currently version
Update: For now, you can use the newest version.
Kotlin:1.7.0 with Hilt:2.42
Update: kotlin:1.6.0 is compatible with hilt:2.40.5, thanks #Nazanin Nasab
Currently, Kotlin 1.5.21 is compatible with Hilt 2.38.
dependencies {
...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
}
I got the same error. I changed two gradle files and It worked for me.
Project Gradle
plugins {
// dependencies for dagger hilt
id 'com.google.dagger.hilt.android' version '2.42' apply false
}
Module Gradle
dependencies {
implementation 'com.google.dagger:hilt-android:2.42'
kapt 'com.google.dagger:hilt-compiler:2.42'
implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")
}
Adding this line to build.gradle dependencies helped me:
kapt("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0")
https://youtrack.jetbrains.com/issue/KT-45885
Thanks for the answer , i had to do a slight tweak in order to work for me because i'm using Arctic Fox, hopefully this answer will help as well
Build.gradle (project)
buildscript {
ext {
compose_version = '1.0.0'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0-alpha05'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.37"
}
}
Build.gradle (app)
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.34-beta"
kapt "com.google.dagger:hilt-android-compiler:2.34-beta"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha03'
For Kotlin 1.7.10, you just need to make the hilt versions 2.42.
in Project-level build.gradle change hilt version
id 'com.google.dagger.hilt.android' version '2.44' apply false
in App-Level build.gradle
implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-compiler:2.44"
general solution - in AS build console click link at bottom - build with -stacktrace param and find which annotation processor (KAPT) is causing error - then try to update dependency - if you are lucky new version should be available and supporting your gradle version
message in build output you should lookin for
Try:
Run with --stacktrace option to get the stack trace. Run with --info or
--debug option to get more log output. Run with --scan to get full insights.
I got same here. I was using dagger:hilt-android:2.33-beta with Kotlin 1.5.10.Please try this
Project gradle
implementation "com.google.dagger:hilt-android:2.33-beta"
Module gradle
plugins {
...
id 'dagger.hilt.android.plugin'
}
dependencies {
...
//dagger-hilt
implementation "com.google.dagger:hilt-android:2.35.1"
kapt "com.google.dagger:hilt-android-compiler:2.35.1"
}
If any solution solved your problem. Go to https://dagger.dev/hilt/gradle-setup, in Using Hilt with Kotlin section, copy the version mentioned in dependencies and update your build.gradle accordingly
I have an issue when upgrading kotlin-gradle-plugin:1.7.x for fulfill requirement of compose. I revert them to org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21 and kotlinCompilerExtensionVersion value
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
kotlinCompilerExtensionVersion compose_version
in my case, the problem was in the different versions that I specified in the dependencies.
"2.40" in classpath 'com.google.dagger:hilt-android-gradle-plugin'
and
"2.43.2" in implementation 'com.google.dagger:hilt-android'
Firstly check helt dependency versions with below url
https://dagger.dev/hilt/gradle-setup
Check you kotlin versions
Kotlin version 1.6.0
Project level gradle
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.40"
App level gradle
def hilt_version="2.40"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"
Kotlin version 1.7.0
Project level gradle
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
App level gradle
def hilt_version="2.42"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"
I am having an issue with building new projects on android studio. I keep on getting the error:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
AAPT: error: failed writing to 'D:\Libraries\Documents\AndroidStudio\SocketTest\app\build\intermediates\runtime_symbol_list\debug\R.txt': The data is invalid. (13).
Here is my project build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.sockettest"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
This problem only occurs on new projects I try to build and isn't an issue on older ones.
I have read through R.txt': The data is invalid. (13) which leads to Long package name build error in Android Studio which still does not solve the problem.
I only encounter this issue while using windows 10 (update 1909), and not while using android studio on ubuntu. I am running android studio version 3.6.2
I know this is a year late but could it be an antivirus blocking it? This is what Avast came up with:
In case someone new to android studios like me does not know how to downgrade Gradle and plugin, here's how (windows):
Select File>Project Structure.
Type in (3.6.3) the Android Gradle Plugin Version.
Type/select (6.0) from dropdown menu the Gradle Version.
Hit OK to Save.
Android Studios will download and set up the new Gradle for the current project. This resolved the data is invalid error for me.
Was getting the same error. I realized it had something to do with the Gradle version I was running, even though I usually stick to the stable channel of releases. I ended up downgrading to plugin version: 3.6.3 & Gradle version 6.0. I had previously been on plugin version 4.0.0 & Gradle version 6.1.1.
I don't know if this was for sure the same issue, this was happening to any projects on my Win10 PC (ver 2004) that were running that Gradle version.
Please follow this :
Uninstall your System(Windows OS)anti virus and most probably it will work.
I already solved by adding this in my dependency
implementation 'com.android.support:design:28.+'
I had a similar issue trying to build an ionic capacitor app with android studio. I later discovered that one of the directories' names in the project's path has space in the name.
I just copied the project into another directory to form a path that has no space and recompiled the project and the error vernished.
When I try to add Safe Args (Android Navigation) to my app's as following
( using this guide : https://developer.android.com/topic/libraries/architecture/navigation/navigation-pass-data ) :
apply plugin: 'com.android.application'
apply plugin: 'androidx.navigation.safeargs'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
android {...
I receive this error :
Plugin with id 'androidx.navigation.safeargs' not found.
To add androidx.navigation.safeargsplugin follow below step's
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha09"
(latest)
Add above to your Project Gradel file inside dependency block
Then add apply plugin: 'androidx.navigation.safeargs' to your app/Module gradle file
You can use dependencies as below in Project level bulild.gradle in Android Studio bumblebee
id 'androidx.navigation.safeargs' version '2.4.2' apply false
Just add this line in your build.gradle project level :
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0-rc02"
In newer version of Android Studio 3.2+, below dependency need to add in both build.gradle file
Project-Level build.gradle
dependencies {
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5'
}
App-Level build.gradle
plugins {
id 'androidx.navigation.safeargs'
}
Add
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0-alpha05"
In your project-level dependencies
For eg :
dependencies {
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0-alpha05"
}
Don't forget to add the latest version
It appears because you are declaring it in the wrong build.gradle file. You have to place it in the build.gradle that looks like this
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.1.0"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
This link explain how it is added https://developer.android.com/jetpack/androidx/releases/navigation#safe_args
as per this https://developer.android.com/jetpack/androidx/releases/navigation
Add above to your Project Gradel file inside dependency block
`classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:2.2.1`
then add
apply plugin: androidx.navigation.safeargs
to your app/Module gradle file
Add this line in Project-level build gradle
id 'androidx.navigation.safeargs' version '2.4.2' apply false
Add this in App-level build gradle
plugins {
id 'androidx.navigation.safeargs'
}
I had to add it to the top level build.gradle, not sure if you've just added it to your app level build.gradle instead
FYI: I had to add it in this manner in order for it to work in Android Studio Dolphin | 2021.3.1:
Gradle Scripts > build.gradle (Project: YourProject)
plugins {
id blah
.
.
.
id 'androidx.navigation.safeargs' version '2.4.2' apply false
}
And also here:
Gradle Scripts > build.gradle (Module: YourProject.app)
dependencies {
implementation blah
.
.
implementation 'androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0-alpha02'
testImplementation blah
androidTestImplementation blah
}
I hope this may help others. I followed the directions at developer.android.com and all the instructions here. None of them solved the issue for me.
Mine was a simple order of operation in my modules build.gradle file.
I had:
id 'androidx.navigation.safeargs.kotlin'
listed as the first line in my plugins block.
moving to the end of the block solved my issue