Android Studio Bumblebee Navigation can't access FragmentDirections for action - android

I create such action before Android Studio bumblebee update and it was working fine.
fragment_button.setOnClickListener{
val action = FeedFragmentDirections.actionFeedFragmentToCountryFragment()
Navigation.findNavController(it).navigate(action)
}
But currently FragmentDirections are not accessible.I don't know where the problem comes from, I guess I can't manage to add navigation.
My build.gradle:
buildscript {
dependencies {
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0")
}
}
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'androidx.navigation.safeargs.kotlin' version '2.4.0' apply false
id 'com.google.gms.google-services' version '4.3.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My build.gradle App
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'kotlin-android-extensions'
}
android {
dataBinding {
enabled = true
}
dependencies {
def navVersion = '2.4.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "androidx.navigation:navigation-fragment-ktx:$navVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navVersion"
}

I am retracting my previous answer!
After a bit of research, I realized the plugin block in your project-level build.gradle has the purpose of assigning dependencies that can be used by subprojects!
https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl
Instead of declaring:
plugins {
...
id 'androidx.navigation.safeargs.kotlin' version '2.4.0' apply false
...
}
You want to add id 'androidx.navigation.safeargs.kotlin' to the app-level plugins block so it can be used directly in your project.

Have you tried cleaning and re-building your project?
This may be a similar case to: Safeargs library doesnt generate direction class
If not, given that you are having trouble accessing the FragmentDirections class, it may be due to the default addition of the non-transitive R class property in the Bumblebee update.
In the gradle.properties[app] file you will find:
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
A good summation of the change and solutions to migrating R classes can be found here:
https://blog.blundellapps.co.uk/speed-up-your-build-non-transitive-r-files/
Best of luck!

I solved my problem by cleaning my project and rebuilding and adding.
Thank you very much for your support
Build.gradle
id ("androidx.navigation.safeargs")
build
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
def nav_version = "2.3.0"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'com.google.gms.google-services' version '4.3.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}

okay so after bumblebee update gradle structure is changed.
but as mentioned above you can still add
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.1")
}
}
before the plugins{} in project level gradle.
but the better alternative is to just use
id 'androidx.navigation.safeargs.kotlin' version '2.4.1' apply false
in plugins{} at project level gradle
both of above will cover first step you still need to add
id 'androidx.navigation.safeargs.kotlin'
in plugins{} at app level gradle
**if you had already added these but now they are not resolving or cannot access fragment direction the reason might be because you have update you gradle to 7.1.0 and safe-args-plugin:2.4.0 is not compatible with that so make sure to use safe-args-plugin:2.4.1 or 2.5.0-alpha01 with gradle 7.1.0

Related

Why Hilt version 2.38.1 not found?

When I am trying to sync my build.gradle file, I am facing some error like this: Plugin [id: 'com.google.dagger.hilt.android', version: '2.38.1', apply: false] was not found in any of the following sources:
I am getting this error only when I am using the Hilt version 2.38.1 which is also currently listed on android official documentation, but when I am using the version '2.41' without changing any other thing, it works! My question is to ask why and how changing the version affects the sync and why version 2.38.1 was not found and 2.41 was.
My guess is something related to repositories kind of thing or the scope where we are looking for these things but I am not sure about any of these, so can anyone explain these?
My project-level build.gradle looks like this:
buildscript {
ext {
compose_ui_version = '1.1.1'
}
}
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'com.google.dagger.hilt.android' version '2.38.1' apply false
}
In my app level build.gradle:
I added these 2 plugins
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
And these dependencies:
implementation "com.google.dagger:hilt-android:2.38.1"
kapt "com.google.dagger:hilt-compiler:2.38.1"

Unable to add Firebase Crashlytics for Gradle version 7.2

Unable to add Firebase Crashlytics dependencies/classpath in Android for Gradle 7.2
Where should I write.
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.0'
I successfully mapped Google services as.
classpath 'com.google.gms:google-services:4.3.10'
//to
id "com.google.gms.google-services" version "4.3.10" apply false
Getting following error if I map Crashlytics classpath
Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.google.firebase.firebase-crashlytics-gradle', version: '2.9.0', apply: false] 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.google.firebase.firebase-crashlytics-gradle:com.google.firebase.firebase-crashlytics-gradle.gradle.plugin:2.9.0')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
MavenRepo
BintrayJCenter
maven(https://jitpack.io)
Project level Gradle
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.5.30' apply false
id "com.google.gms.google-services" version "4.3.10" apply false
// below line has a problem
id 'com.google.firebase.firebase-crashlytics-gradle' version '2.9.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
dependencies {
}
Gradle-wrapper.properties
#Thu May 12 10:12:33 PKT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
settings.gradle
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
}
rootProject.name = "Video Player"
include ':app'
I had searched a lot before posting this question but didn't find something useful.
The documentation is not updated for the new Android project structure yet.
In your project level build.gradle you need to add this:
buildscript {
//other things....
dependencies {
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.0'
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.20' apply false
id "com.google.gms.google-services" version "4.3.10" apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Then in your app level build.gradle at the start you need to add the plugin
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.firebase.crashlytics'
}
and then in the same file add the Crashlytics dependencies to the corresponding block:
dependencies {
//... other dependencies
implementation platform('com.google.firebase:firebase-bom:30.1.0')
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
}
Add this inside Root project build.gradle
plugins {
id 'com.google.gms.google-services' version '4.3.10' apply false
id 'com.google.firebase.crashlytics' version '2.9.1' apply false
.... some others classpath
}
And this inside the App Module build.gradle
plugins {
.... some others plugins
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}
And finally...
implementation platform('com.google.firebase:firebase-bom:30.3.1')
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
So force a crash in your code, something like this
throw RuntimeException("Crashlytics Test")
Now check your Firebase Console
Done!
In your project's build.gradle:
buildscript {
...
ext.crashlytics_version = '2.9.1'
}
plugins {
...
id 'com.google.firebase.crashlytics' version "$crashlytics_version" apply false
}
Then in your app's build.gradle, apply the plugin:
plugins {
...
id 'com.google.firebase.crashlytics'
}
You should use like this
id 'com.google.firebase.crashlytics' version '2.9.2' apply false
Use the Kotlin libraries, even if you're on Java:
...
implementation platform('com.google.firebase:firebase-bom:30.3.1')
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
...

How to Migrate build.gradle from Groovy to Kotlin DSL in Android Studio Bumblebee?

I want to migrate build.gradle file from Groovy to Kotlin, since I updated my Android Studio to Bumblebee, I'm not sure how to do it.
This is how build.gradle looks when I create a new project.
I'm not sure on how to migrate plugins{} part.
buildscript {
ext {
compose_version = '1.0.1'
}
}
plugins {
id 'com.android.application' version '7.1.3' apply false
id 'com.android.library' version '7.1.3' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'org.jetbrains.kotlin.jvm' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I got the answer in the documentation here https://developer.android.com/studio/build#kts.
Here's how it's written in Kotlin.
plugins {
id("com.android.application") version "7.1.0-beta02" apply false
id("com.android.library") version "7.1.0-beta02" apply false
id("org.jetbrains.kotlin.android") version "1.5.30" apply false
}
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
The following steps worked for me.
Step-1: Create the plugins tag and give it the id values. delete the buildscript tag.
Step-2: Open the pluginManagement tag in the settings.gradle file and make some tags and values.
Step-3: In the last step, update the values defined at the top in the build.gradle file as id.
Optional: Since it is in the build.gradle file, it must be deleted.
repositories {
mavenCentral()
}

build.gradle (project) completely different?

I setup a new (Kotlin) project using Android Studio. When I take a look at my build.gradle (Project), I see this content:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
However, other build.gradles seem to be completely different.
I searched all files, but couldn't find any occurrences of the buildscript, dependencies or any other block.
Where are they or how do I add them?
buildscript was used to add the version of dependencies and classpaths. In the newer versions of android studio you have to mention the version directly after the dependency implementations.
So for example, I wanted to add the classpath "androidx.navigation:navigation-safe-args-gradle-plugin" to my build.gradle(Project) for the plugin id "androidx.navigation.safeargs.kotlin" , but in the newer version it has been moved to settings.gradle and is done by adding a resolutionStrategy block just after the repositories block: -
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == 'androidx.navigation.safeargs.kotlin') {
useModule("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.2")
}
}
}
}
after that, you can add the plugin id "androidx.navigation.safeargs.kotlin" in plugin block in the build.gradle(Module) and sync it: -
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
}
Hope this is helpful!!
There are two build.gradle files in android studio i.e. build.gradle(Project) & build.gradle(Module).
Required blocks like buildscript, dependencies are available in build.gradle(Module)
build.gradle(Module) looks like:
Hope this will help :)
Repositories have been moved to settings.gradle and module Gradle has been moved to the app package gradle.

Databinding annotation processor kapt warning

In my app module's build.gradle, I have added
dependencies {
kapt('com.android.databinding:compiler:3.1.2')
...
}
but I'm still receiving the compiler warning for
app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.android.databinding:compiler:3.1.2'.
Everything functions, I just hate having warnings hanging around.
Any help is much appreciated!
I had same warnings until I upgraded to the latest Android Gradle build plugin and Kotlin. Now they are gone. Here is the configuration I use.
project.gradle
buildscript {
dependencies {
classpath "com.android.tools.build:gradle:3.1.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51"
}
}
module.gradle
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
...
dataBinding {
enabled = true
}
}
dependencies {
// no kapt declaration for databinding here
}
Hope it helps.
Add following in you app build.gradle
kapt "com.android.databinding:compiler:$android_plugin_version"
apply plugin: 'kotlin-kapt' // This one at top where plugin belong to
This will do the trick.
$android_plugin_version is version of com.android.tools.build:gradle in application build.gradle
Also, add this to your module build.gradle
android {
/// Existing Code
kapt {
generateStubs = true
}
}
You are missing apply plugin: 'kotlin-kapt' i think.

Categories

Resources