I had dagger included in build.gradle (app) as follows:
{compile 'com.squareup.dagger:dagger:1.2.+'
provided 'com.squareup.dagger:dagger-compiler:1.2.+'}
Now I am trying to upgrade my project to Dagger 2.0 and create unit test with Mockito and Espresso, my new dependency consists of:
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
provided 'org.glassfish:javax.annotation:10.0-b28'
I have Facebook SDK included in the project included in the project and I am getting error as error: cannot find symbol class R
I also have added as repository maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
I would appreciate any help understanding what is going on here and how to resolve it.
Add this to the Project build.gradle as a dependency{}
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
and add this to the module build.gradle
apply plugin: 'com.neenbedankt.android-apt'
View https://oss.sonatype.org/content/repositories/snapshots/com/google/dagger/dagger-compiler/2.1-SNAPSHOT/
there is no 2.0-SNAPSHOT version. Just change your 2.0-SNAPSHOT to 2.1-SNAPSHOT. It helps to me in same case.
Related
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 have problems referencing my android library modules in my projects. Beside the main app module I use to have an android library module with either util stuff or as data module. I reference it in app module like that:
dependencies {
implementation project(":data")
}
When I build the project, it´s giving me lot of error messages 'Unresolved reference: ...' for all stuff that I reference in the app module to the android library module. But the IDE itself doesn´t have a problem, Intelligent finds all classes, interfaces etc., imports are fine, nothing is red. The android library module itself builds and creates aar-file in the output. It´s the compileDebugKotlin task that fails
Any general idea what may be related to that?
Found the problem, my android library module was missing the kotlin configuration:
apply plugin: 'kotlin-android'
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion:<version>"
}
Although I used kotlin .kt files in it, it could build without and also
Tools -> Kotlin -> 'Configure Kotlin in projects'
had told me 'All modules with Kotlin files are configured'
Your module's build.gradle file should have:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
dependencies {
...
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
...
}
In my case It was apply plugin: 'kotlin-android',
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
and also added it on build.gradle
androidExtensions {
experimental = true
}
If it is a kotlin module make sure to add in its build.gradle file
apply plugin: 'kotlin'
I was using CoroutineWorkers and in my case I had to add work-runtime-ktx dependency to use it
implementation "androidx.work:work-runtime-ktx:2.4.0"
I get the following errors when trying to execute my project:
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.
- butterknife-7.0.1.jar (com.jakewharton:butterknife:7.0.1) 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.
Please don't mark this question as duplicate as other question regrading this, here, is for lombok, which I'm not using.
As the error says, you need to use annotationProcessor in your app build.gradle. Afaik, you need to upgrade the ButterKnife library to version 8.8.1. You need to use something like this:
dependencies {
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
Please check Android studio 3.0 butterknife error issue for the details.
Going through the following process makes my problem solved.
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'
}
Adding these two line in app/build.gradle
dependencies {
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
It worked for me
I applied to my project Android Architecture Components, by adding this lines to build.gradle:
// Android Architecture Lifecycle
compile "android.arch.lifecycle:runtime:1.0.0-alpha1"
compile "android.arch.lifecycle:extensions:1.0.0-alpha1"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"
// Android Architecture Room
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
compile "android.arch.persistence.room:rxjava2:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
It worked, but after updating Android Studio to Canary 3 version I'm still getting this error while compiling
Error:org.gradle.api.resources.ResourceException: Could not get
resource
'https://jitpack.io/android/arch/lifecycle/runtime/1.0.0-alpha1/runtime-1.0.0-alpha1.pom'.
Error:org.gradle.api.UncheckedIOException: Could not HEAD
'https://jitpack.io/android/arch/lifecycle/runtime/1.0.0-alpha1/runtime-1.0.0-alpha1.pom'.
Received status code 401 from server: Unauthorized
... other poms from library with the same error.
I tried restarting Android Studio, uninstalling app and of course clean-rebuild.
You need to add the new public Maven repo that Google is using to your build.gradle file.
For example, you could add it to the allprojects closure in the top-level build.gradle file:
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
Then, all of your modules (e.g., app/) will know to look there in addition to other places for the artifacts.
From your error message, it would appear that Android Studio is only looking in jitpack.io.
Whenever I try to minify my project that makes use of the parceler library, I cannot build a release apk because of a lot of warnings from proguard. For example:
Warning:org.parceler.transfuse.gen.FilerResourceWriter: can't find referenced class javax.tools.FileObject
I don't even make use of most of the libraries reported in this messages. What I'd like to know is if someone has encountered this problem and managed to solve it.
I tried to use -dontwarn to suppress all messages, but it does not seems correct, and besides it makes my app crash in rare cases (which makes me thing that some of the warning messages are indeed correct, but I'd like the library to keep the needed classes automatically).
My gradle script is as follows:
apply plugin: 'com.android.application'
...
dependencies {
...
compile 'org.parceler:parceler:1.0.3'
}
You are seeing this error from Proguard because you've included Parceler as a runtime dependency. Parceler was designed to be included into your project as two separate libraries; the annotation processor and the api. If you're running Gradle your build script should look like the following:
compile "org.parceler:parceler-api:1.0.3"
apt "org.parceler:parceler:1.0.3"
See Getting Parceler.
where apt is the android-apt plugin. Secondarily, it can also be run under the provided scope.
Your build script will look like the following in the end:
buildscript {
repositories {
mavenCentral()
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:1.3.0'
// the latest version of the android-apt plugin
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
...
dependencies {
...
compile "org.parceler:parceler-api:1.0.3"
apt "org.parceler:parceler:1.0.3"
}