Passing Data Between Fragments Using Safe Args - android

I'm trying to implement data transfer between fragments using Safe Args, but I'm stuck at the moment of setting Gradle.
Project Gradle looks like this
// Top-level build file where you can add configuration options common to all sub-projects/modules.
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
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module Gradle is like this
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.main_fragmentargs"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures{
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
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:2.5.0"
implementation "androidx.navigation:navigation-ui-ktx:2.5.0"
}
Wherever I enter this line, Gradle starts to swear.
apply plugin: "androidx.navigation.safeargs.kotlin"
Similar story with
def nav_version = "2.3.3"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
Please tell me how to connect it.

You have to add the plugin to your plugin closure, like described in the documentation.
Add this to your top level build.gradle:
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.5.0"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
...
and this to your app modules build.gradle:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'androidx.navigation.safeargs.kotlin'
}
...
Also make sure that android.useAndroidX=true is set in your gradle.properties files.

Related

Kotlin error: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1

Seems this has been asked a few times, but the questions with solutions are seemingly outdated.
Here are my build.gradle files... any idea what I'm meant to be changing? (Complete Kotlin novice here, in case that wasn't obvious)
Build.gradle (Module)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.testapp"
minSdk 24
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Build.gradle (Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
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.5.30' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Any help would be greatly appreciated

java.lang.IllegalStateException: Unsupported nesting ANONYMOUS kotlin

I'm trying to update all of my plugins version to the latest one, but I get error :
Execution failed for task ':app:hiltJavaCompileDebug'.
java.lang.IllegalStateException: Unsupported nesting ANONYMOUS
here is my gradle :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
classpath "com.android.tools.build:gradle:7.2.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.43.2"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.5.2"
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
&
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-parcelize'
apply plugin: 'dagger.hilt.android.plugin'
apply plugin: "androidx.navigation.safeargs.kotlin"
apply plugin: 'com.google.firebase.crashlytics'
android {
compileSdk 33
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.project.test"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
setProperty("archivesBaseName", "apps")
}
buildFeatures{
viewBinding = true
dataBinding = true
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
buildTypes {
debug {
debuggable true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField "String", "API_BASE_URL", base_url
}
release {
debuggable false
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField "String", "API_BASE_URL", base_url
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.7.10"
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// hilt
implementation "com.google.dagger:hilt-android:2.43.2"
kapt "com.google.dagger:hilt-android-compiler:2.43.2"
/* hilt viewmodel extension*/
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0"
kapt "androidx.hilt:hilt-compiler:1.0.0"
}
I'm trying to solve the issue but nothing happens. Is there something not compatible with the latest update for the hilt version ? Or do I miss something from my gradle ?
Try downgrading your hilt gradle plugin, it solve my problem.
classpath "com.google.dagger:hilt-android-gradle-plugin:2.38.1"

Could not resolve all files for configuration ':app:debugCompileClasspath'. using Android Studio Chipmunk | 2021.2.1

I have recorded a video using mobile camera but now i want to trim that video using a library, after adding the below dependency for trimming feature.
implementation 'com.github.a914-gowtham:android-video-trimmer:1.7.0'
i am getting this error:
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugCompileClasspath'.
Here is my app level build.gradle code:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.techease.videome"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//trimmer
implementation 'com.github.a914-gowtham:android-video-trimmer:1.7.0'
}
And here is the project level build.gradle:
// Top-level build file where you can add configuration options common to all sub-
projects/modules.
buildscript {
repositories {
maven { url 'https://jitpack.io' }
}
}
plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Anyone having idea what i am missing here?
In the android studio from "File" menu call "Invalidate caches..."
After loading android studio build the project again. Every thing will be correct.

How do I add KSP plugin to android project gradle?

My aim is to add the KSP plugin to gradle as stated in the question heading.
just go through the line below each //from quickstart comments and you'll see all the error origins.
To add the dependencies I referred the Kotlin KSP quickstart documentation.
Now, the code might not be an exact replica of the one from the docs because that didn't work and so, I attempted some failed changes to try and make it work.
build.gradle(app/module) -
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
//from quickstart
id 'org.jetbrains.kotlin.jvm'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.cryptile"
minSdk 26
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
implementation 'com.google.android.material:material:1.5.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
def room_version = "2.4.2"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
//what I want to implement
ksp "androidx.room:room-compiler:$room_version"
//from quickstart
implementation 'com.google.devtools.ksp:symbol-processing-api:1.6.10-1.0.2'
}
build.gradle(project) -
//from quickstart
buildscript {
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
}
}
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
//from quickstart
id 'org.jetbrains.kotlin.jvm' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
settings.gradle -
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "CRYPTILE"
include ':app'
Any help is appriciated.
KSP guides failed to mention where to reference your processor. Use META-INF resource directory to reference your processor processor in your processormodule:
src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider
In this file you reference your ProcessorProvider:
com.my.package.processor.MySymbolProcessorProvider
This is important step in order your processor provider be recognized and later instantiate the actual processor.
If your dependencies setup are not in place please read further here https://medium.com/#nikoladespotoski/hands-on-google-ksp-c0508d623863

Failed to resolve:... Affected module: app

I keep getting the error "Failed to resolve: :unspecified: Affected Modules: app" whenever I sync my gradle. This error is not descriptive and hence hard to figure out what's the exact cause for this.
App build.gradle:
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.firstapp.attendance_system"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'org.naishadhparmar.zcustomcalendar:zcustomcalendar:1.0.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Project build.gradle
// 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
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I am using Android Studio 2021 on Windows 10 PC

Categories

Resources