Unresolved reference: navigation: androidx.navigation.ui.AppBarConfiguration - androidx

In Android Studio 3.4.
in gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
in app/build.gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
In activity:
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.ui.AppBarConfiguration
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val appBarConfiguration = AppBarConfiguration(navController.graph)
}
}
but I get compile error in this line:
import androidx.navigation.ui.AppBarConfiguration
error message:
Unresolved reference: navigation

I believe you are missing:
implementation "androidx.navigation:navigation-fragment-ktx:2.1.0-alpha05"
implementation "androidx.navigation:navigation-ui-ktx:2.1.0-alpha05"

Add
import androidx.navigation.ui.NavigationUI
in MainActivity.kt file with rest of imports

Related

Default FirebaseApp is not initialized in this process com.example.example. Make sure to call FirebaseApp.initializeApp(Context) first

My problem is that when i want to press the button it should show the image from firebase. But every time the app crashes with this error "Default FirebaseApp is not initialized in this process com.example.example. Make sure to call FirebaseApp.initializeApp(Context) first."
Her's my Main Activity
package com.nktschmitt.trailercheck
import android.app.Application
import android.content.Context
import android.graphics.BitmapFactory
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.Toast
import com.google.firebase.FirebaseApp
import com.google.firebase.ktx.Firebase
import com.google.firebase.storage.FirebaseStorage
import java.io.File
import com.google.firebase.FirebaseApp.initializeApp as initializeApp1
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val button: Button = findViewById(R.id.button)
button.setOnClickListener {
val image: ImageView = findViewById(R.id.rImage)
val storageRef = FirebaseStorage.getInstance().reference.child("image/a.jpg")
val localfile = File.createTempFile("tempImage", "jpg")
storageRef.getFile(localfile).addOnSuccessListener {
val bitmap = BitmapFactory.decodeFile(localfile.absolutePath)
image.setImageBitmap(bitmap)
}.addOnFailureListener {
Toast.makeText(this, "Failed", Toast.LENGTH_SHORT).show()
}
}
}
}
Her's my Project Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.21"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.9'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Her's my App Gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.nktschmitt.trailercheck"
minSdkVersion 18
targetSdkVersion 30
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 "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'com.google.firebase:firebase-storage-ktx:20.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Google services plugin v4.3.9 has this bug. A newer plugin version is available with the fix. Please manually upgrade classpath 'com.google.gms:google-services:4.3.9' to classpath 'com.google.gms:google-services:4.3.10' in your project-level build.gradle file.
i think still have bug 4.3.8, 4.3.9 , 4.3.10.
recommend downgrade 4.3.7

Error migrating to new jetpack compose version

I'm trying to update my app to a new compose version but it gave me an error that I don't know how to fix. when I run the error persists in my run. my old project works normally but mine what I want is to change versions follow my error if anyone can help me i would appreciate it a lot
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.quitanda, PID: 10390
java.lang.AbstractMethodError: abstract method "void androidx.lifecycle.DefaultLifecycleObserver.onCreate(androidx.lifecycle.LifecycleOwner)"
at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:36)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:196)
at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:808)
at android.view.View.dispatchAttachedToWindow(View.java:18355)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3399)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3406)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3406)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3406)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3406)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1796)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1494)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7288)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
build.gradle(Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
task clean(type: Delete) {
delete rootProject.buildDir
}
buildscript {
ext {
compose_version = '1.0.0-rc01'
}
}
build.gradle(Module)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
apply plugin:'kotlin-parcelize'
android {
compileSdk 30
defaultConfig {
applicationId "com.example.quitanda"
minSdk 21
targetSdk 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
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 {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
}
dependencies {
def appcompat_version = "1.3.0"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha02'
implementation 'androidx.core:core-ktx:1.6.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.0-rc01'
implementation "androidx.appcompat:appcompat:$appcompat_version"
// For loading and tinting drawables on older versions of the platform
implementation "androidx.appcompat:appcompat-resources:$appcompat_version"
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
// implementation "com.google.accompanist:accompanist-coil:0.7.1"
implementation "io.coil-kt:coil-compose:1.3.0"
implementation "androidx.navigation:navigation-compose:2.4.0-alpha05"
implementation "com.google.accompanist:accompanist-swiperefresh:0.8.0"
implementation "com.google.accompanist:accompanist-pager:0.8.1"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-moshi:2.9.0"
implementation "androidx.paging:paging-compose:1.0.0-alpha08"
}
It is an error with the AGP. Change the minSDKVersion to 24 for now
As described in the documentation:
If you are using Android Studio Bumblebee Canary 4 or AGP 7.1.0-alpha04/7.1.0-alpha05, you may hit the following crash:
java.lang.AbstractMethodError: abstract method "void androidx.lifecycle.DefaultLifecycleObserver.onCreate(androidx.lifecycle.LifecycleOwner)"
To fix, temporarily increase your minSdkVersion to 24+ in your build.gradle file. This issue will be fixed in the next version of Android Studio Bumblebee and AGP 7.1.

Failed to resolve: com.google.firebase:firebase-core-ktx:

Image link containing screenshot of the error
I am using Kotlin for my android app. I am unable to finish my Gradle Build due to this error :
Failed to resolve: com.google.firebase:firebase-core-ktx:
I tried all possible solutions available on stackoverflow. I have already downloaded the latest google play services from the SDK manager. I placed maven{url...} in my all repositories, yet can't fix this error. Even tried adding version specification in my implementations. Please help me with this!!
This below is my build.gradle file :-
buildscript {
ext.kotlin_version = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
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
}
}
allprojects {
repositories {
jcenter()
maven { url "https://maven.google.com" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
These are the dependencies added to the code :-
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.navigation:navigation-fragment:2.3.2'
implementation 'androidx.navigation:navigation-ui:2.3.2'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation platform('com.google.firebase:firebase-bom:26.2.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-core-ktx'
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-database-ktx:19.6.0'
implementation 'com.google.firebase:firebase-storage-ktx'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Try this:
implementation 'com.google.firebase:firebase-core:16.0.1'
Also you can try this, if you are using the bom library.
implementation 'com.google.firebase:firebase-core'

firebase authentication error while i try to sign up with email and password

i trying to authentication with firebase but i face to some problem
this is my problem ...i trying to sign up with email and password
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.ybq:Android-SpinKit:1.2.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-database:16.0.5'
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
}
this is my dependencies\
tnks a lot!

FCM - Getting push notification data twice

I've been struggling with this issue for a long time so I decided to ask you.
I'm developing a chat app and for push notifications I'm using Firebase Functions. I'm getting always the data from onMessageReceived twice. For some people the solution was removing de gcm dependencies and use only the firebase ones but i think is not my case. Anyway I'm showing you all the code:
This is my index.js:
exports.notifications = functions.database.ref('chats/{chatUid}/messages/{pushId}').onWrite( (change, context) => {
var valueObject = change.after.val();
var chatUid = change.after.ref.parent.parent.key;
var data = {
'data' : {
'conversation_id' : chatUid,
'message_key' : change.after.key,
'message_title' : valueObject.title,
'message_body' : valueObject.message,
'userFrom' : valueObject.userFrom.toString()
}
};
const options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
return admin.messaging().sendToTopic(chatUid, data, options)
});
My gradle settings:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 27
defaultConfig {
applicationId "xxx"
minSdkVersion 21
targetSdkVersion 27
versionCode xxx
versionName "x.x.x"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.3'
productFlavors {
}
}
ext {
support_version = '27.1.1'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:design:$support_version"
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:customtabs:$support_version"
implementation "com.android.support:support-v4:$support_version"
implementation "com.android.support:cardview-v7:$support_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation "com.android.support:percent:$support_version"
implementation "com.android.support:recyclerview-v7:$support_version"
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation('com.squareup.retrofit2:retrofit:2.3.0') {
exclude module: 'okhttp'
}
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.okhttp3:okhttp:3.9.0'
implementation 'com.squareup.retrofit2:converter-jackson:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.facebook.android:facebook-android-sdk:4.18.0'
implementation 'com.google.firebase:firebase-analytics:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.firebase:firebase-config:16.0.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.firebaseui:firebase-ui-database:3.3.1'
implementation 'com.firebaseui:firebase-ui-storage:3.3.1'
implementation 'commons-codec:commons-codec:1.11'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'}
Thank you for your time :D
I'm stupid.
It was my fault in android code, nothing to do with firebase functions:
I was using onWrite(index.js) and in my android code I was writting twice in firebase database, one for writing the message_key(push()) and other for setting the properties(setValue()):
finalReference.push().apply {
val map2 = HashMap<String, Any?>()
val dateFormat = SimpleDateFormat(DATE_FORMAT, Locale.getDefault())
dateFormat.timeZone = TimeZone.getTimeZone("UTC")
map2[FB.DATE] = dateFormat.format(Date())
map2[FB.MESSAGE] = entryText.text.toString()
map2[FB.READ] = false
map2[FB.RECEIVED] = false
map2[FB.TITLE] = fbUser.displayName
map2[FB.USER_FROM] = fbUser.uid.toLong()
map2[FB.USER_TO] = conversation_data!!.users_id.find { it != fbUser.uid }?.toLong()
setValue(map2).addOnSuccessListener {
child(FB.RECEIVED).setValue(true)
}
entryText.setText("")
}
So the solution was to change onWrite for onCreate on index.js.
Hope it helps anybody.

Resources