Problem after updating to latest kotlin version - android

I updated my kotlin version to 1.4.20 in project build.gradle file in Android Studio. But, i am not able sync my project. I am getting this error:
A problem occurred configuring root project 'Modules'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find kotlin-scripting-compiler-embeddable-1.4.20.jar (org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.4.20).
Searched in the following locations:
https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-scripting-compiler-embeddable/1.4.20/kotlin-scripting-compiler-embeddable-1.4.20.jar
> Could not find kotlin-stdlib-common-1.4.20.jar (org.jetbrains.kotlin:kotlin-stdlib-common:1.4.20).
Searched in the following locations:
https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-common/1.4.20/kotlin-stdlib-common-1.4.20.jar
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
I also went to Tools->Kotlin->Configure Kotlin Plugin Updates and installed the latest kotlin. Still i am getting this error.
So, What could be the reason?
build.gradle (Modules)
buildscript {
ext {
kotlinVersion = "1.4.20"
gradleVersion = '4.0.0'
}
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:${gradleVersion}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
classpath "org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
build.gradle (:app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply from: "$rootDir/gradle/local-aar.gradle"
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "com.google.gms:google-services:${gmsLibVersion}"
}
}
apply plugin: 'com.google.gms.google-services'
//Rest of the code

Related

Android: Default FirebaseApp is not initialized in this process error with AGP 3.3.0

I recently updated to Gradle Plugin 3.3.0 with Android Studio 3.3 and I'm getting this error:
io.reactivex.exceptions.OnErrorNotImplementedException: Default FirebaseApp is not initialized in this process <package-name>. Make sure to call FirebaseApp.initializeApp(Context) first.
at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
However, it was working fine with AGP 3.2.0
Rest of my configuration is as follows:
Top level build.gradle file:
buildscript {
...
ext.kotlin_version = '1.3.11'
ext.firebase_core = "16.0.6"
ext.firebase_messaging = "17.3.4"
ext.google_services_plugin_version = "4.1.0"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
...
classpath "com.google.gms:google-services:$google_services_plugin_version" // google-services plugin
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
...
}
...
App build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: "androidx.navigation.safeargs"
android {
...
}
configurations {
...
}
dependencies {
...
//firebase
implementation "com.google.firebase:firebase-core:$firebase_core"
implementation "com.google.firebase:firebase-messaging:$firebase_messaging"
...
}
apply plugin: 'com.google.gms.google-services'
It seems AGP 3.3.0 is incompatible with these Firebase versions. What can I do to resolve this issue? I updated AGP 3.3.0 because I want to use R8 to resolve an proguard issue.

How to apply the com.android.application plugin using the new plugins DSL?

I have a project configured through the triple of:
Declare repository in top-level build.gradle:
buildscript { repositories { google() }}
allprojects { repositories { google() }}
Declare classpath dependency, so plugin artifact gets downloaded from the appropriate repository, in top-level build.gradle
buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.1.3' }}
Then, in the app build.gradle file, apply the plugin:
apply plugin: 'com.android.application'
I want to migrate this to use the new plugins DSL as enabled by the PluginsDependenciesSpec.
I then:
Declared the repository in settings.gradle:
pluginManagement { repositories { google() }}
Declared the plugin dependency in the app build.gradle:
plugins { id "com.android.application" version "3.1.3" }
But this fails to resolve:
FAILURE: Build failed with an exception.
Where: Build file '…/build.gradle' line: 2
What went wrong: Plugin [id: 'com.android.application', version: '3.1.3'] was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'com.android.library:com.android.library.gradle.plugin:3.1.3')
Searched in the following repositories:
Google
BintrayJCenter
maven(https://maven.fabric.io/public)
Gradle Central Plugin Repository
What am I missing to get Gradle to connect the dots here, so that it can connect the plugin.id to the appropriate JAR fetched from the appropriate repository?
Within the pluginManagement you can use resolutionStrategy and force usage of specific artifact from the google() repository.
pluginManagement {
repositories {
google()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id in ['com.android.application', 'com.android.library']) {
useModule("com.android.tools.build:gradle:${getProperty('version.plugin.android')}")
}
}
}
}
Then you can apply android plugins with using new plugins DSL:
plugins {
id 'com.android.application'
}
or
plugins {
id 'com.android.library'
}
Here is the documentation.

“Plugin with id 'com.android.application' not found”

I am getting “Plugin with id 'com.android.application' not found”. I have updated the gradle distribution version in gradle wrapper properties but to no avail. Do I need to write the build gradle dependencies somewhere?
You have to add in your top level file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}

unknown property 'LibraryVariants' in build.gradle

I have the error below in build.gradle at this line:
apply plugin: 'com.google.gms.google-services'
Error:(56, 0) Could not get unknown property 'LibraryVariants' for object of type com.android.build.gradle.LibraryExtension.
It happened after I installed Firebase.
How to solve this?
The error message, Error: Could not get unknown property 'LibraryVariants' for object of type com.android.build.gradle.LibraryExtension, indicates that this plugin needs to be applied to a module which uses the com.android.application plugin.
So, the simple solution is to only include the google-services plugin in your application module and not your library module:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
I had the same problem and solved it updating gradle and google-services versions.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Add the following to the #project level gradle file:
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:3.0.0'
Add the following to the #app level gradle file:
// Dependency for Google Sign-In
compile 'com.google.android.gms:play-services-auth:9.4.0'
Apply plugin
apply plugin: 'com.google.gms.google-services'

How add mavenCentral to gradle in dev of nativescript plugin

I am writing a plugin for NativeScript but I have troubles with the gradle file,
how can I add the mavencentral() to the repositories tag in buildScript and an "apply instruction" ? example:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:2.1.2"
classpath 'com.google.gms:google-services:3.0.0'
}
}
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
I tried to add this to the include.gradle for my plugin but when I add this plugin in my app project, the build process fails.

Categories

Resources