build.gradle (project) in the app. here before new version into
dependencies {
def nav_version = "2.4.0"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"}
-I could add. I can't add with the new update. Also in build.gradle (app)
plugins {id 'androidx.navigation.safeargs'}
I can't add. What should I do to use SafeArgs?
enter image description here
I need to use arguments of navigation. so ı need this library.
It's a known incompatability and there is no stable version of navigation that supports AGP 7.1.0 yet. In the meantime, you can use navigation 2.5.0-alpha01.
Related
I am new to Android Studio and I am trying to use the latest navigation version which I believe is 2.3.0. However, after adding it to the dependencies in the gradle file I still seem to get an error that it could not find the classpath. Any tips? Here are some screenshots:
You are using:
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$nav_version"
It was the 1st release and the latest version is 1.0.0
With androidx migration you have to use:
def nav_version = "2.3.0"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
More info in the official doc.
I need to use, in an Android project using Gradle, a specific artifact of a repositorty.
The artifact is kotlinx-serialization-cbor version 0.20.0 (available in the readme) from the kotlinx serialization GitHub project.
I don't know where and how to add this specific dependencies. (Probably I should add something in "gradle.build" file, the one marked as Project:YourProjectName or the one Module:app
Any help?
The README in the root of the github project explains how to add the plugins to your project. So long as your gradle install is up to date you just need to add a section at the top of your app level build.gradle like this:
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.70' // or any other kotlin plugin
id 'org.jetbrains.kotlin.plugin.serialization' version '1.3.70'
}
In the same file make sure jcenter is included in your repositories:
repositories {
jcenter()
}
Then again in the same file add the basic library, as well as the cbor library to the dependencies:
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // or "kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0" // JVM dependency
implementation "org.jetbrains.kotlinx:kotlinx-serialization-cbor:0.20.0"
}
You should probably look here https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-serialization-cbor/0.20.0 and copy-paste from Gradle/Maven etc (build system of your choice).
When building gradle I'm getting this message:
API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'
I'm using Android Studio 4.1 Canary 10 and gradle:4.1.0-alpha10
It seems like the Navigation Safe Args plugin uses getApplicationIdTextResource(), so it is most likely that the error message is caused by your usage of that plugin.
You'd want to star the existing issue to ask the Safe Args plugin to use the new replacement API.
Changing to androidx.navigation:navigation-*:2.4.0-alpha02 as described here allowed a build of my app under Arctic Fox without getting the getApplicationIdTestResource warning
From the application build.gradle file:
def nav_version = "2.4.0-alpha02"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
And in the build.gradle file:
def nav_version = "2.4.0-alpha02"
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
few days i see the same issue. Then i go to ->
build.gradle file
My Dependencies before update
check the dependencies
I update the dependencies google services to 4.3.4
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.google.gms:google-services:4.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
After update
Now its working fine.
This error was for NavigationComponent for me in Android Studio Cannery 13.
So I changed the nav_version to this and My issue was solved.
ext {
*************** nav_version = "2.4.0-alpha10" ************
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0-alpha13'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
and in app module build.gradle:
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
It will be solved, when 4.2.0 is stable.
From the existing issue:
Android Gradle Plugin deprecated the getApplicationIdTextResource()
API on the class BaseVariant in version 4.1.0 (see bug). The
replacement API (onVariantProperties) did not work properly for
feature libraries, so to avoid the deprecation warning, reflection was
used. That is only a short term solution, and when AGP 4.2.0 is stable
we should update to that version and remove the reflection immediately
So if you need Safe Args and do not need latest features of Gradle, keep Gradle version in Android Gradle Plugin version at 3.6.4. Once stable 4.2.0 released, update to the latest.
This error happened after i updated kotlin version to 1.7.
this was for NavigationComponent in Android Studio
So I changed the nav_version to this and My issue was solved : "2.4.0-beta02"
// Navigation Component
implementation "androidx.navigation:navigation-fragment-ktx:2.4.0-beta02"
implementation "androidx.navigation:navigation-ui-ktx:2.4.0-beta02"
For me it was because of different Kotlin versions between IDE Kotlin plugin and project_name/build.gradle file
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
"Kotlin version that is used for building with Gradle (1.3.72) differs from the one bundled into the IDE plugin (1.4.31) "
Once I made it even it started to compile again.
In my case I was using 2.3.1 version of navigation-fragment.
I just updated it to 2.4.2 and it's helped me
So, What i have done is that I have upgraded all the gradle plugins as well as dependecies versions and then run, It worked for me
I had the same problem and it was solved like this:
So I go to -> build.gradle file
My dependencies before upgrade
check the dependencies
I update Google services dependencies to latest version
dependencies {
classpath 'com.android.tools.build:gradle:(latest version)'
classpath 'com.google.gms:google-services:(latest version)'
}
Android Studio 4.1 giving the following information and It will be removed in version 5.0 of Android Gradle Plugin.
API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'.
It will be removed in version 5.0 of the Android Gradle plugin.
For more information, see TBD.
To determine what is calling BaseVariant.getApplicationIdTextResource, use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
As #ianhanniballake has pointed out, it seems likely that it's caused by the Navigation Safe Args plugin, see the existing issue, also referenced from his answer. The issue was marked as fixed on 9 November.
In terms of fixing the build error, upgrading Android Studio from 4.1.0 to 4.1.1 fixed it for me.
delete the .idea and .gradle files from the project .. it worked with me
I recently updated my Android Studio (and I'm pretty sure the Gradle version), and now I've been getting a bunch of errors when trying to compile my project. Here's the one that is plaguing me at the moment:
Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:26.1.0)
This is followed by lots of similar ones.
I tried removing all uses of com.android.support in favor of androidx (see here for what I was using the replace things), but com.android.support libraries are still being used, even when I delete the libraries (they're just remade once I try to compile again).
Here's a link to the full error I get.
Add these lines to your gradle.properties
android.useAndroidX=true
android.enableJetifier=true
If gradle.properties is absent, create the file in the root directory of your project.
It looks like you have some support relics anywhere in your dependencies, maybe from a lib? To investigate and see the dependencies tree, please run:
./gradlew :yourApp:dependencies
and then you see from where it comes.
In your app build.gradle you are using a mix of old support library and new support library artifacts. Remove one of them from your build.gradle to resolve this issue.
Old artifact: com.android.support:support-compat
Corresponding new artifact: androidx.core:core:1.0.0
See this page for more information on migrating to AndroidX.
Like others says, the solution is to migrating to AndroidX, it works for me. However, it isn´t an easy way and it requires a bit of pacience... These are the steps that I did:
First, is very important that you do all this changes in a different branch or you make a backup of your project.
You need to have the Android Gradle Plugin Version 3.5.1. So, in build.gradle set:
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
}
Migrate to AndroidX using Android Studio Tool : Refactor --> Migrate to AndroidX...
When it finishes, it has done all pertinents modification, but posibly you can´t deploy the project correctly because you find any errors. These are the problems that I found and the solutions:
If you use Kotlin, in build.gradle set:
buildscript {
ext.kotlin_version = '1.3.10'
}
and
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
If you use destination method, add "file" parameter: destination file("$reportsDir/checkstyle/checkstyle.xml")
If you use Butterknife, use 10.0.0 version
Finally, Build --> Clean Project and Build --> Rebuild Project
This solution from here worked the best for me. Migrating to androidX
https://developer.android.com/jetpack/androidx/migrate
With Android Studio 3.2 and higher, you can migrate an existing
project to AndroidX by selecting Refactor > Migrate to AndroidX from
the menu bar.
The refactor command makes use of two flags. By default, both of them
are set to true in your gradle.properties file:
android.useAndroidX=true The Android plugin uses the appropriate
AndroidX library instead of a Support Library.
android.enableJetifier=true The Android plugin automatically migrates
existing third-party libraries to use AndroidX by rewriting their
binaries.
If you face any issue regarding duplicate classes after using Facebook mediation and google ad libraries so follow these steps:
1- Add this in build.gradle(Module) in Top
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.gms.google-services'
2- Add this in build.gradle(Module) -> android
packagingOptions {
exclude "META-INF/DEPENDENCIES"
}
3- Add this in build.gradle(Module) -> dependencies
//firebase bom
implementation platform('com.google.firebase:firebase-bom:29.2.0')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-messaging:23.0.1'
//ADS
def ads_version = "20.6.0"
implementation "com.google.android.gms:play-services-ads:$ads_version"
//facebook ads
implementation 'com.google.ads.mediation:facebook:6.8.0.0'
4- Add this in build.gradle(Project )-> buildscript-> dependencies
classpath "com.android.tools.build:gradle:7.0.4"
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
5- Add this in gradle.wrapper.propertise
#Wed Dec 16 15:32:03 PKT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-7.0.2-bin.zip
I wanted to update the version of my kotlin plugin to 1.3.10. This is what looks like my build.gradle :
buildscript {
ext.kotlin_version = '1.3.10'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Then i want to define a variable for my kotlin-stdlib :
ext.kotlinDependency = "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
But it does not work for this last line, I have always done this way and it worked well for the 1.2.61 version. Should i just wait before updating the version for the last one ?
As the Kotlin 1.3 compatibility guide says,kotlin-stdlib-jre7 is a deprecated artifact name which has been removed in Kotlin 1.3. kotlin-stdlib-jdk7 is the replacement to be used.