I'm using androidx for quite a while and my Android project compiles fine, however recently my Android Studio throws tons of red for all Activity classes
because of
cannot access 'androidx.activity.result.ActivityResultCaller' which is a supertype of ...
I use
AppCompatActivity from androidx.appcompat:appcompat:1.1.0
My build.gradle has:
ext.kotlin_version = '1.3.71'
...
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.google.gms:google-services:4.3.3'
And gradle version
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
My gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
org.gradle.jvmargs=-Xmx4608m
org.gradle.parallel=true
# Use kapt in parallel
kapt.use.worker.api=true
# Kapt compile avoidance
kapt.include.compile.classpath=false
This happened because of Gradle when resolving dependency libraries versions upgraded androidx.core:core to version more than 1.2.0, probably to 1.3.0-beta01 or 1.3.0-rc01
AppCompatActivity extends FragmentActivity
that extends ComponentActivity
that extends androidx.core.app.ComponentActivity
that implements ActivityResultCaller
introduced in androidx.activity:activity:1.2.0-alpha03 only.
To resolve this issue add this dependency to your module build.gradle:
dependencies {
implementation "androidx.activity:activity-ktx:1.2.0-alpha03"
}
In my case, turns out I had conflicting androidx.activity:activity-ktx gradle dependencies between my core/base and app module.
In addition to ActivityResultCaller, mine was throwing an issue with ActivityResultRegistryOwner.
For me, removing the dependency from the app module, pushing the core module dependency to androidx.activity:activity-ktx:1.2.0-alpha04 and bumping implementation "androidx.core:core-ktx:1.3.0 > 1.3.1 solved both issues.
I also have an androidx.appcompat:appcompat:1.3.0-alpha01 dependency in core, which I kept, but it seems removing it has no effect.
In my case, I needed to remove implementation 'androidx.appcompat:appcompat:1.3.0-alpha01' while keeping implementation "androidx.core:core-ktx:1.3.1"
Related
Gradle has multiple dependency configurations. I know that compile, implementation, api dependencies are shipped with the library/app; while compileOnly, testCompile, and testImplementation dependencies are not. What about the classpath dependencies in the top-level buildscript, are those dependencies included in the AAR/APK?
For E.g. Dokka (https://github.com/Kotlin/dokka) library, this only needs to be added as buildscript.classpath dependency, will dokka be included in the library aar file?
I tried searching in the Gradle docs but could not find an answer to my question. I am ssuming that it should not be shipped with the app/library.
I have questions about android hilt.
I have added hilt plugin.
//build.gradle(:project)
buildscript {
ext.hilt_version = '2.37'
dependencies {
...
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
}
}
//build.gradle(:app)
plugins {
...
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
dependencies {
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"
}
//MyApplication.kt
#HiltAndroidApp
class MyApplication : Application() {...}
When I build the project,
I get the error message saying
"Expected #HiltAndroidApp to have a value. Did you forget to apply the Gradle Plugin?"
Do you have any idea?
I am also having same problem in my new projects. This error had gone after lowering kotlin version to 1.5.10. I think hilt has compatibility issues with latest kotlin plugin.
As mentioned by others, Kotlin 1.5.20 has a bug in Kapt which causes this issue.
It is fixed in 1.5.21. Just increase the version and you're good.
There is a bug in 1.5.20
To avoid this bug there is a workaround.
in build.gradle (app) file paste this code below.
generally, in the hilt Gradle plugin, these options are set automatically. in 1.5.20 it is not. if you set it manually it will resolve the issue.
kapt {
javacOptions {
option("-Adagger.fastInit=ENABLED")
option("-Adagger.hilt.android.internal.disableAndroidSuperclassValidation=true")
}}
I have an Android studio project in which I have added a Java library module, which I call core. My three Gradle build files look like this.
project/build.gradle
buildscript {
ext.kotlin_version = '1.2.40'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
core/build.gradle
apply plugin: 'java-library'
apply plugin: 'kotlin'
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
...
}
app/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android { ... }
dependencies {
implementation project(':core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
testImplementation 'junit:junit:4.12'
}
The problem I have is that, in core/build.gradle, the kotlin-stdlib-jdk7 line is giving me the warning Plugin version (1.2.40) is not the same as library version (jdk7-1.2.40). I have tried changing it to:
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.2.40"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.40"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
But the warning is still there. The build still runs successfully, and I know I can surpress the warning without any problems and ignore it, but I really want to know why this is happening and how I can get rid of it. I am using Android Studio 3.0.1. Does anyone know of a solution to this?
Starting from Kotlin 1.4 dependency on the standard library added by default:
You no longer need to declare a dependency on the stdlib library in any Kotlin Gradle project, including a multiplatform one. The dependency is added by default.
The automatically added standard library will be the same version of the Kotlin Gradle plugin, since they have the same versioning.
For platform-specific source sets, the corresponding platform-specific variant of the library is used, while a common standard library is added to the rest. The Kotlin Gradle plugin will select the appropriate JVM standard library depending on the kotlinOptions.jvmTarget compiler option of your Gradle build script.
Link to Kotlin Gradle plugin documentation.
This is a bug in the Kotlin plugin. I've filed an issue in the Kotlin issue tracker. You can simply ignore the message.
EDIT: JetBrains marked the issue as a duplicate of KT-23744 "Kotlin library and Gradle plugin versions are different" inspection false positive for non-JVM dependencies".
Solution, in my case, I got rid of the line
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
in the app level Gradle and the warning disappear
As the Kotlin page says :
" You no longer need to declare a dependency on the stdlib library in any Kotlin Gradle project, including a multiplatform one. The dependency is added by default.
The automatically added standard library will be the same version of the Kotlin Gradle plugin, since they have the same versioning.
For platform-specific source sets, the corresponding platform-specific variant of the library is used, while a common standard library is added to the rest. The Kotlin Gradle plugin will select the appropriate JVM standard library depending on the kotlinOptions.jvmTarget compiler option of your Gradle build script."
You might be facing this after upgrading kotlin version, Actually, older versions are still in your caches, In this case, you need to do the following steps
Invalidate cache
Clean project
Sync project with gradle files
Now your warning will be gone.
[build.gradle(Module)]
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.5.10'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.10'
...
}
My project automatically added
(implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.10')
to the project build file. After moving the implementation to the module file, and removing
(implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.10')
the warning went away.
The 'stdlib' needs to match the 'stdlib-jdk' in the module file.
I faced the same issue while using Firebase with Kotlin.
I had to upgrade all the dependencies with their latest version available.
Note: have your kotlin-reflect and kotlin-stdlib versions same.
after many days i have solve the issue
Update the kotlin_version to '1.4.32'
In my case, I set the version number for all modules the same as gradle of app as latest version, and problem resolved.
I am attempting to add a maven repository to my Android Studio project.
When I do a Gradle project sync everything is fine. However, whenever I try to build my apk, I get this error:
Execution failed for task ':app:javaPreCompileDebug'.
> Annotation processors must be explicitly declared now. The following dependencies on
the compile classpath are found to contain annotation processor. Please add them to
the annotationProcessor configuration.
- classindex-3.3.jar
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions
.includeCompileClasspath = true to continue with previous behavior. Note that this
option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
The link included (https://developer.android.com/r/tools/annotation-processor-error-message.html) in the error 404s so its of no help.
I have enabled annotation processing in the android studio settings, and added includeCompileClasspath = true to my Annotation Processor options. I have also tried adding classindex, classindex-3.3 and classindex-3.3.jar to Processor FQ Name, but that did not help either.
these are the lines I have added to the default build.gradle under dependecies:
dependencies {
...
compile group: 'com.skadistats', name: 'clarity', version:'2.1.1'
compile group: 'org.atteo.classindex', name: 'classindex', version:'3.3'
}
Originally I just had the "clarity" one added, because that is the one I care about, but I added the "classindex" entry in the hopes that it would fix it. Removing "clarity" and keeping "classindex" gives me the exact same error.
I'm not all too familiar with gradle/maven so any help would be appreciated.
To fix the error, simply change the configuration of those dependencies to use annotationProcessor. If a dependency includes components that also need to be on the compile classpath, declare that dependency a second time and use the compile dependency configuration.
For example:
annotationProcessor 'com.jakewharton:butterknife:7.0.1'
compile 'com.jakewharton:butterknife:7.0.1'
This link describes it in detail: https://developer.android.com/studio/preview/features/new-android-plugin-migration.html#annotationProcessor_config
Relevant snippet included for completeness.
Use the annotation processor dependency configuration
In previous versions of the Android plugin for Gradle, dependencies on
the compile classpath were automatically added to the processor
classpath. That is, you could add an annotation processor to the
compile classpath and it would work as expected. However, this causes
a significant impact to performance by adding a large number of
unnecessary dependencies to the processor.
When using the new plugin, annotation processors must be added to the
processor classpath using the annotationProcessor dependency
configuration, as shown below:
dependencies {
...
annotationProcessor 'com.google.dagger:dagger-compiler:' }
The plugin assumes a dependency is an annotation processor if its JAR
file contains the following file: META-
INF/services/javax.annotation.processing.Processor. If the plugin
detects annotation processors on the compile classpath, your build
fails and you get an error message that lists each annotation
processor on the compile classpath. To fix the error, simply change
the configuration of those dependencies to use annotationProcessor. If
a dependency includes components that also need to be on the compile
classpath, declare that dependency a second time and use the compile
dependency configuration.
I was with a similar error. I follow the instructions on the Google link and it works.
try to add the follow instructions to your app gradle file:
defaultConfig {
applicationId "com.yourdomain.yourapp"
minSdkVersion 17
targetSdkVersion 25
versionCode 1
versionName "1.0"
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = false
}
}
}
Attention to -> includeCompileClasspath false
Add this code to your gradle app
defaultConfig{
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
I found the solution here https://github.com/JakeWharton/butterknife/issues/908
Simply update your butter knife with Annotation processor
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
i hope it's help you
Add this in defaultConfig
android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
In the build.gradle(module app)
apply the plugin:
apply plugin: 'com.jakewharton.butterknife'
Add the following lines in the dependencies section:
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
implementation 'com.jakewharton:butterknife:8.7.0'
in the build.gradle(Project:projectName), add the classPath in the dependencies like this :
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
It will fix this issue.
In case if not then add maven:
maven {
url 'https://maven.google.com'
}
If you have dependencies on the compile classpath that include annotation processors you don't need, you can disable the error check by adding the following to your build.gradle file. Keep in mind, the annotation processors you add to the compile classpath are still not added to the processor classpath.
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}
}
}
If you are experiencing issues migrating to the new dependency resolution strategy, you can restore behavior to that of Android plugin 2.3.0 by setting includeCompileClasspath true. However, restoring behavior to version 2.3.0 is not recommended, and the option to do so will be removed in a future update.
See here https://developer.android.com/r/tools/annotation-processor-error-message.html for more details
If nothing works from above answers add following step as well, specially for new update of Android Studio 3.0.1:
Android Studio 3.0.1:
Add this to your app.gradle file in dependencies:
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
In previous versions of the plugin, dependencies on the compile classpath were automatically added to the processor classpath. That is, you could add an annotation processor to the compile classpath and it would work as expected. However, this causes a significant impact to performance by adding a large number of unnecessary dependencies to the processor.
When using the Android plugin 3.0.0, you must add annotation processors to the processor classpath using the annotationProcessor dependency configuration, as shown below:
dependencies {
...
annotationProcessor 'com.google.dagger:dagger-compiler:<version-number>'
implementation 'com.google.dagger:dagger-compiler:<version-number>'
}
Two warnings show up when I try to build my project:
Warning:Using incompatible plugins for the annotation processing: android-apt. This may result in an unexpected behavior.
and also at the end of all the binding errors:
Warning:The following options were not recognized by any processor: '[android.databinding.artifactType, android.databinding.printEncodedErrors, android.databinding.minApi, android.databinding.isTestVariant, android.databinding.enableDebugLogs, android.databinding.sdkDir, android.databinding.bindingBuildFolder, android.databinding.enableForTests, android.databinding.modulePackage, android.databinding.generationalFileOutDir, android.databinding.xmlOutDir]'
I tried to enable annotation processors and removed all apt reference and changed this:
apt 'com.jakewharton:butterknife-compiler:8.2.1'
to this:
annotationProcessor 'com.jakewharton:butterknife-compiler:8.2.1'
but it didn't work.
Just replace apt with annotationProcessor in your build.gradle file.
And remove apt plugins wherever you see them.
You can down version of tools build gradle from 2.3.0 to 2.2.3 to avoid warning like that
classpath 'com.android.tools.build:gradle:2.2.3'
Android apt is no longer supported in Android studio 2.3
see https://bitbucket.org/hvisser/android-apt/issues/73/no-longer-compatible-with-gradle-at-v230
after i update. i also have this kind of situation. Remove any apt like "com.neenbedankt.gradle.plugins:android-apt:1.8" from your dependencies classpath
but before that.. please invalidate cache/restart AS and clean gradle.
then
dependencies {
classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
}
then
apply plugin: 'com.jakewharton.butterknife'
then
compile "com.jakewharton:butterknife:8.5.1",
annotationProcessor "com.jakewharton:butterknife-compiler:8.5.1"
the lastly..put this in last app module
configurations.all {
resolutionStrategy {
force "com.android.support:support-annotations:25.2.0"
}
}