FirebaseRecyclerAdapter cannot be implemented when I use it, as shown below:
import androidx.recyclerview.widget.RecyclerView;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
public class AddClassAdapter extends FirebaseRecylerAdapter{
}
Image of Error
Even though I've implemented these things on build.gradle module
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.firebase:firebase-auth:21.1.0'
implementation 'com.google.firebase:firebase-firestore:24.4.1'
implementation 'com.google.firebase:firebase-database:20.1.0'
implementation 'com.google.firebase:firebase-storage:20.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
implementation platform('com.google.firebase:firebase-bom:31.1.0')
implementation 'com.google.firebase:firebase-database'
implementation'com.squareup.picasso:picasso:2.71828'
implementation 'io.github.muddz:styleabletoast:2.4.0'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.firebaseui:firebase-ui-database:0.4.0'
Related
How do I mock firebase_auth methods in my integration tests?
I am getting the following error:
MissingPluginException(No implementation found for method Auth#registerIdTokenListener on channel plugins.flutter.io/firebase_auth)
The integration test currenlty doesn't do much:
void main() async {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
setupFirebaseAuthMocks();
await Firebase.initializeApp();
MockFirebaseAuth(signedIn: false);
app.main();
}
setupFirebaseAuthMocks(); method I got form this solution: https://stackoverflow.com/a/64730015/6266336
It helped to overcome similiar issue but with Firebase#initializeCore method.
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.Getmapping;
#Controller
public class HomeController {
#GetMapping("/")
public String home(){
return "hone";
}
}
I just can't import org.springframework.web so that I can't use #GetMapping.
How to solve this problem?
Should I add more dependencies?
Add spring-web module to your classpath.
Gradle
compile group: 'org.springframework', name: 'spring-web', version: '5.2.6.RELEASE'
Maven
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.6.RELEASE</version>
</dependency>
In build.gradle, under dependencies, add:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
// TODO: Add this implementation
implementation 'org.springframework:spring-web:5.3.15'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Then, as shown below, be sure to 'Reload All Gradle Projects'.
For additional context, consult the docs on Maven Repository.
Essentially, we have to specify this source for our import to know from where to import.
It's not clear to me why this isn't part of the offerings whenever we use the Spring Intializr. 🤷🏾♂️
I'm trying to implement Firebase Cloud messaging on my App, using Kotlin.
In MyFirebaseMessagingService.kt I get the message "MyFirebaseMessagingService is not registered in the manifest,
Also, my app keeps stopping when built.
I have spend whole day searching for solution but haven't found one yet.
I tried adding several services but with no success.
(like: "MyFirebaseMessagingService"
".MyFirebaseMessagingService"
".java.MyFirebaseMessagingService"
".firebase.MyFirebaseMessagingService"
AndroidManifest.xml
<service
android:name="MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>`
MyFirebaseMessagingService.kt
import android.annotation.SuppressLint
import android.util.Log
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import android.app.NotificationManager
import android.media.RingtoneManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import com.example.recapp.MainActivity
import com.example.recapp.R
import com.google.firebase.iid.InstanceIdResult
import com.google.android.gms.tasks.OnSuccessListener
import com.google.firebase.iid.FirebaseInstanceId
class MyFirebaseMessagingService : FirebaseMessagingService(){
val TAG = "FirebaseMessagingService"
override fun onNewToken(token: String) {
Log.d("New_Token", token)
}
#SuppressLint("LongLogTag")
override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
Log.d(TAG, "Poruka: ${remoteMessage.from}")
if (remoteMessage.notification != null) {
Log.d(TAG, "Sadrzaj: ${remoteMessage.notification?.body}")
sendNotification(remoteMessage)
}
}
private fun sendNotification(remoteMessage: RemoteMessage) {
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntent = PendingIntent.getActivity(this#MyFirebaseMessagingService, 0, intent, PendingIntent.FLAG_ONE_SHOT)
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this#MyFirebaseMessagingService, "Notification")
.setSmallIcon(com.example.recapp.R.mipmap.ic_launcher)
.setContentTitle("Poruka")
.setContentText(remoteMessage.notification?.body)
.setAutoCancel(true)
.setSound(soundUri)
.setContentIntent(pendingIntent)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(0, notificationBuilder.build())
}
}
App builds with no errors, but keeps stopping when built.
Build gradle (myApp) is ok?:
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.google.gms:google-services:4.3.0'
Build gradle (app) is ok?:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
apply plugin: 'com.google.gms.google-services'
You have to declare the full name of your service. For example, if your service is in package com.example then it will be com.example.MyFirebaseMessagingService
<service
android:name="com.example.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
this is my firebase depedencies in build.gradle level app :
implementation 'com.google.firebase:firebase-analytics:17.4.3'
implementation 'com.google.firebase:firebase-core:17.4.3'
implementation 'com.google.firebase:firebase-iid:20.2.1'
implementation 'com.google.firebase:firebase-messaging:20.2.1'
and in Manifest
<service
android:name = "com.aplikasipdam.lampupanggungcirebon.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
Expected
The Kotlin app running in IntelliJ has been migrated from a 2009 MacBook Pro to a 2019 MacBook Pro. Provided the same credentials, the project is expected to run identical code accessing both a Firestore database and Firestore Storage.
Observed
The code will not run on the new machine due to oauth errors.
Errors
com.google.api.gax.grpc.InstantiatingGrpcChannelProvider does not define or inherit an implementation of the resolved method abstract needsCredentials()
Failed to detect whether we are running on Google Compute Engine.
Log
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Jul 07, 2019 11:45:41 AM com.google.auth.oauth2.ComputeEngineCredentials runningOnComputeEngine
INFO: Failed to detect whether we are running on Google Compute Engine.
Exception in thread "Timer-0" java.lang.AbstractMethodError: Receiver class com.google.api.gax.grpc.InstantiatingGrpcChannelProvider does not define or inherit an implementation of the resolved method abstract needsCredentials()Z of interface com.google.api.gax.rpc.TransportChannelProvider.
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:157)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:122)
at com.google.cloud.firestore.spi.v1beta1.GrpcFirestoreRpc.<init>(GrpcFirestoreRpc.java:121)
at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:80)
at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:72)
at com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:510)
at com.google.cloud.firestore.FirestoreOptions.getFirestoreRpc(FirestoreOptions.java:315)
at com.google.cloud.firestore.FirestoreImpl.<init>(FirestoreImpl.java:76)
at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:63)
at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:56)
at com.google.cloud.ServiceOptions.getService(ServiceOptions.java:498)
at com.google.firebase.cloud.FirestoreClient.<init>(FirestoreClient.java:51)
at com.google.firebase.cloud.FirestoreClient.<init>(FirestoreClient.java:29)
at com.google.firebase.cloud.FirestoreClient$FirestoreClientService.<init>(FirestoreClient.java:95)
at com.google.firebase.cloud.FirestoreClient.getInstance(FirestoreClient.java:85)
at com.google.firebase.cloud.FirestoreClient.getFirestore(FirestoreClient.java:78)
at com.google.firebase.cloud.FirestoreClient.getFirestore(FirestoreClient.java:64)
at utils.FirebaseClient.<clinit>(FirebaseClient.kt:10)
at utils.FirestoreCollectionsKt.<clinit>(FirestoreCollections.kt:5)
at content.ContentTasks.getExistingContentSet(ContentTasks.kt:89)
at content.ContentTasks.run(ContentTasks.kt:39)
at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
at java.base/java.util.TimerThread.run(Timer.java:506)
Process finished with exit code 0
Existing Code for Authentication
Initialization.kt
object Initialization {
#JvmStatic
fun main(args: Array<String>) {
set(Enums.EnvironmentType.STAGING)
initializeFirestore()
getContent()
}
private fun initializeFirestore() {
FirebaseApp.initializeApp(FirebaseOptions.Builder()
.setCredentials(fromStream(Gson().toJson(getFirebaseCredentials()).byteInputStream()))
.setFirestoreOptions(FirestoreOptions.newBuilder().setTimestampsInSnapshotsEnabled(true).build())
.build())
}
}
CredentialsHelper.kt
fun getFirebaseCredentials() =
if (environmentType == PRODUCTION) FirebaseCredentials(
"service_account",
"[projectId]",
"[privateKeyId]",
"[privateKey]",
"[clientEmail]",
"[clientId]",
"https://accounts.google.com/o/oauth2/auth",
"https://accounts.google.com/o/oauth2/token",
"https://www.googleapis.com/oauth2/v1/certs",
"https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-0z4rn%40carpecoin-media-211903.iam.gserviceaccount.com")
else FirebaseCredentials(
"service_account",
"[projectId]",
"[privateKeyId]",
"[privateKey]",
"[clientEmail]",
"[clientId]",
"https://accounts.google.com/o/oauth2/auth",
"https://accounts.google.com/o/oauth2/token",
"https://www.googleapis.com/oauth2/v1/certs",
"https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-dhr30%40coinverse-media-staging.iam.gserviceaccount.com")
Attempted Solution
Updating library versions in build.gradle in case the issue is due to a dependency conflict.
build.gradle
buildscript {
ext.kotlin_version = '1.3.41'
ext.junitJupiterVersion = '5.5.0'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.3'
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.2.51'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation group: 'junit', name: 'junit', version: '5.3.2'
// JUnit Jupiter API and TestEngine implementation
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
testImplementation "org.assertj:assertj-core:3.12.2"
// To avoid compiler warnings about #API annotations in JUnit code
testCompileOnly 'org.apiguardian:apiguardian-api:1.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.6.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
implementation 'com.google.firebase:firebase-admin:6.8.1'
implementation 'com.google.cloud:google-cloud-storage:1.79.0'
implementation 'com.google.apis:google-api-services-youtube:v3-rev212-1.25.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
This is because that a "gax" on which "firebase-admin" depends via "gax-grpc" is old so a newer "gax" which other library, perhaps "google-cloud-storage" in your case, introduces is selected by Gradle, resulting in compatibility issue.
In my case, forcing Gradle to use the latest "gax-grpc" like the following got the problem fixed. I hope this helps you as well.
implementation group: 'com.google.api', name: 'gax-grpc', version: '1.47.1'
Building library module. And in the sample application which is using the library module it has
#GlideModule
class DPAppGlideModule : AppGlideModule() {
override fun isManifestParsingEnabled(): Boolean {
return false
}
}
and in the library module has:
#GlideModule
public final class LibGlideModule extends LibraryGlideModule {
}
and in the library module it is using the GlideApp the generated api
fun ImageView.loadImg(imageUrl: String) {
var requestOptions : RequestOptions = RequestOptions()
requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL)
if (!TextUtils.isEmpty(imageUrl)) {
GlideApp.with(this.context)
.setDefaultRequestOptions(requestOptions)
.load(imageUrl)
.into(this)
}
}
But since this is the library module and cannot have decency on the application module, so it cannot compile
How to use the GlideApp generated api in the library module?
ref — https://bumptech.github.io/glide/doc/configuration.html
Just add
annotationProcessor com.github.bumptech.glide:compiler:4.8.0
dependency in your module gradle file. sync project then clean and rebuild it.
If your module using kotlin. change "annotationProcessor" to "kapt".
Be careful if you have others module dependency,make sure you use the right GlideApp Object. Maybe others module have it own GlideApp object