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"
}
Related
Sporadically, my Gradle syncs will fail. I'll be given the unhelpful message that "a 3rd party Gradle plugin" may be the cause. If I open up the Event Log, I'll see the message:
Outdated Kotlin Runtime
Your version of Kotlin runtime in 'Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.2.10#jar' library is 1.2.10-release-109 (1.2.10), while plugin version is 1.2.51-release-Studio3.1-1.
Runtime library should be updated to avoid compatibility problems.
The mismatched number is neither the Kotlin version in my Gradle files, or the version of my Kotlin plugin in Android Studio.
After running a Gradle dependency tree, I found the culprit:
+--- io.realm:realm-android-kotlin-extensions:5.1.0
| \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.10 -> 1.2.51
I'm not including any realm-android-kotlin-extensions library. I'm assuming that it's added by classpath "io.realm:realm-gradle-plugin:5.1.0" and apply plugin: "realm-android"
This makes matters difficult. If it were a regular dependency, I could try something like
implementation "io.realm:realm-android-kotlin-extensions:5.1.0" {
transitive = false
}
or
implementation "io.realm:realm-android-kotlin-extensions:5.1.0" {
exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib-jdk7"
}
Theoretically that would probably work. It would be forced to use the newer version of Kotlin, the error would go away, and hopefully Gradle syncs would work and all would be well with the world. But if I try this approach my Gradle sync fails and I get this error in the Event Log:
Gradle sync failed: Could not find method io.realm:realm-android-kotlin-extensions:5.1.0() for arguments [build_2krw7i3nwfkd5lrq1ly9b8huw$_run_closure3$_closure29#7b5b2081] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I'm assuming that's because this isn't a dependency I added (perhaps not a public dependency?), that it fails because the dependency is added via the plugin instead of directly in my Gradle file.
So how do I fix this? Perhaps there's a line I can add to tell the Realm plugin to exclude the obsolete dependency? Or am I completely barking up the wrong tree and the solution for my Kotlin version clash issue is something else entirely?
(BTW, if you're wondering why I'm using Realm 5.1.0, 5.3.1 causes some weird bugs in our app, so we're waiting for a later version to be released in the hope that will no longer cause the issues.)
One of the things on my personal "I wish I had known this a year ago" list is that you can manually add what Realm adds to your project instead of relying on the Gradle plugin.
buildscript {
ext.kotlin_version = '1.2.51'
ext.realm_version = '5.3.1'
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "io.realm:realm-transformer:5.1.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
import io.realm.transformer.RealmTransformer
android.registerTransform(new RealmTransformer(project))
dependencies {
implementation "io.realm:realm-annotations:$realm_version"
implementation "io.realm:realm-android-library:$realm_version"
implementation "io.realm:realm-android-kotlin-extensions:$realm_version" {
exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib-jdk7"
}
kapt "io.realm:realm-annotations-processor:$realm_version"
}
As per docs.
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.
While setting up realm in project by following this documentation.
below is my project level gradle :
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// Realm
classpath "io.realm:realm-gradle-plugin:1.2.0"
}
app level gradle :
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
dependencies {
final DAGGER_VERSION = '2.7'
....
def daggerCompiler = "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
annotationProcessor daggerCompiler
testAnnotationProcessor daggerCompiler
androidTestAnnotationProcessor daggerCompiler
compile "com.google.dagger:dagger:$DAGGER_VERSION"
provided 'org.glassfish:javax.annotation:10.0-b28' //Required by Dagger2
}
This is one of the most serious downsides of Dagger 2 - its error reporting is terrible. I regularly observe these kind of errors, and you can't understand a thing from that message.
The problem is that Dagger 2 pre-processor runs before javac compilation, and if the code couldn't be processed, then pre-processor fails without generating components implementations. To my best knowledge, the pre-processor doesn't report what error caused the failure. Then, when javac compilation executed it fails because it can't find the generated file, but it doesn't proceed to compilation of other files, therefore the only error you see is about missing Dagger component.
What I do in such cases is three stepped solution:
Review VCS history and visit all changed files. Since IDE compiles each file upon visit, I will see if any of them has compilation errors.
If #1 didn't help, I would try to incrementally remove Dagger 2 code from the project (commit beforehand!) and try to recompile on the way. When Dagger 2 is removed from problematic region, Dagger components will be generated and javac comilation will show you the actual errors.
If nothing else helps, I'm visiting all project files one-by-one. Have done it twice already, and it is a nightmare.
I know nothing about Realm, but since I see it uses its own plugin, you could start by changing the order of plugins appliance in build.gradle. Switch these lines:
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
This answer is based off of Vasiliy's previous answer. I'm promoting my comments to his/her answer to make the solution that worked for me more visible.
As Vasiliy suggested, reversing these lines:
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
to
apply plugin: 'realm-android'
apply plugin: 'com.neenbedankt.android-apt'
allowed the reporting of an underlying Realm error that was preventing Dagger from generating my application component class (in my case, a breaking change introduced in Realm 2.x).
After addressing this issue, with the reordered apply plugin lines I received this error:
java.lang.IllegalArgumentException: XXX is not part of the schema for this Realm
By reordering the plugins, Realm annotations are not being processed as needed. So the plugin lines must then be restored to:
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
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.
My Android app is based on Gradle and it just takes ages to build every time. This is due to the number of modules I have. Even if there are no changes in submodules, it keeps rebuilding every sources.
I was wondering if there is any way to convert these modules to local snapshot dependencies as I'm not updating them often?
I'm pretty sure it's possible but I have a very basic experience with gradle and maven so I can't figure out a simple way to do that.
Basically right now I'm listing my dependencies like that:
dependencies {
compile project(':Library:lib1')
compile project(':Library:lib2')
compile project(':Library:lib3')
}
and I'd like to use something like that:
repositories {
local()
}
dependencies {
compile 'com.lib1:lib:SNAPSHOT-1.0')
compile 'com.lib2:lib:SNAPSHOT-1.0')
compile 'com.lib3:lib:SNAPSHOT-1.0')
}
To use local snapshots use the maven-publish plugin. If you use SNAPSHOT in the version (e.g. 0.0.1-SNAPSHOT) you will publish snapshots to your local repository. For the build.gradle for lib1 you should do something like this:
apply plugin: 'java'
apply plugin: 'maven-publish'
project.version=0.0.1-SNAPSHOT
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
}
and run the :publishMavenPublicationToMavenLocal target.
In you gradle build file for projects using the library use:
repositories {
local()
}
dependencies {
compile group: 'com.lib1', name: 'lib', version: 'SNAPSHOT-0.0.1', changing: true
}
The 'changing' attribute indicates that not a cached version is used (normally updated once every 24hrs) but always checks for the latest.