I want to use Firebase and Play services libraries. As far as I understand it is ok to depend on this library and use it's functionality if it's already present on the device or require to download it, but due to the licensing I can not distribute this libraries bundled with my application.
My question:
How do I declare dependency and have 100% certainty that it is not bundled but will be provided on the phone?
Before this way of adding classpath dependency in buildscript was sufficient for me and added dependencies only during compilation:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
But unfortunately now it has to be added to the application dependencies in that way (adding do buildscript doesn't work):
dependencies {
implementation platform('com.google.firebase:firebase-bom:31.1.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore'
}
I'm new to android development, but as explained here, when we use different gradle dependency declarations we get:
implementation
Gradle adds the dependency to the compile classpath and packages the dependency to the build output.
api
Gradle adds the dependency to the compile classpath and build output.
compileOnly
Gradle adds the dependency to the compile classpath only (that is, it is not added to the build output). This is useful when you're creating an Android module and you need the dependency during compilation, but it's optional to have it present at runtime.
runtimeOnly
Gradle adds the dependency to the build output only, for use during runtime. That is, it is not added to the compile classpath.
Does api dependency solve my problem, as the description doesn't use the word packages ?
A project has multiple modules, two of which are named :app and :prefs.
The project build.gradle,
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21"
and :app build.gradle,
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3"
...
implementation project(":prefs")
work fine. However, the :prefs library requires the latest coroutine features,
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0"
but the following error occurs:
jetified-kotlinx-coroutines-android-1.6.0.jar!/META-INF/kotlinx-coroutines-android.kotlin_module:
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.13.
Is it possible to have separate versions of the same dependency ... one in each module?
I tried using
./gradlew androidDependencies
but that shows all dependencies. I just want to see only module dependencies, e.g. as defined in all build.gradles
dependencies {
implementation project(':moduleA')
implementation project(':moduleB')
implementation project(':moduleC')
}
You mean like
gradle moduleA:dependencies
This should show the dependencies related to moduleA
For the whole dependencies Tree with no module selected
gradle dependencies
https://github.com/vanniktech/gradle-dependency-graph-generator-plugin
You can use this plugin to create "your project module dependency graph"
./gradlew generateProjectDependencyGraph
or "whole dependency graph".
./gradlew generateDependencyGraph
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 used Firebase Cloud Message Service in my project. I read Firebase documentation for Integrate in android and see this line to add in build.gradle of project.
classpath 'com.google.gms:google-services:3.0.0'
My question is:
Why we have to use google-service version 3.0.0 ? Instead latest is 9.4.0.
Edition : Tnx Gabriele. As per #Gabriele its a plugin not library. So what is difference between Plugin and Library. What is different between DSL and API? Is API is depends on DSL or DSL is depends on API?
Don't confuse the buildscript dependencies with the library dependencies:
In your buildscript dependencies you are going to define the plugins used by your script. In this case you are adding the google-services plugin
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
In the dependencies section you are going to define the libraries used.
dependencies {
compile 'com.android.support:support-v4:24.1.1'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-messaging:9.4.0'
}