Unable to receive moengage push notifications - flutter

I have go through the documentation of moengage flutter but unable to receive the notifications
i have added fcm keys in dashboard also. Below in my implementation
When i am sending notification through fcm are working fine
basically we have 2 modes of flutter apk prod and debug and i am working on debug i have added debug package name in moengage dashboard.
when i create campaign and send a push to android all users its not working. Please help here
Application.kt class
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.GeneratedPluginRegistrant
import com.moengage.core.LogLevel
import com.moengage.core.MoEngage
import com.moengage.core.MoEngage.Builder
import com.moengage.core.config.FcmConfig
import com.moengage.core.config.LogConfig
import com.moengage.core.config.MiPushConfig
import com.moengage.core.config.PushKitConfig
import com.moengage.core.config.NotificationConfig
import com.moengage.flutter.MoEInitializer
import com.moengage.pushbase.MoEPushHelper
import io.flutter.app.FlutterApplication
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
val moEngage = MoEngage.Builder(this, "hereIHaveAddedTheKey")
.build()
MoEngage.initialise(moEngage)
}
override fun registerWith(registry: PluginRegistry?) {
if (registry == null) return
}
}
Build.gradle dependency
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.android.support:multidex:1.0.3'
/// ---- moengage sdk start----
implementation("com.moengage:moe-android-sdk:11.2.00")
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation("com.google.firebase:firebase-messaging:20.3.0")
implementation("androidx.lifecycle:lifecycle-process:2.2.0")
implementation("com.moengage:hms-pushkit:2.0.01")
implementation("com.moengage:rich-notification:2.2.00")
implementation("androidx.core:core:1.3.1")
implementation("androidx.appcompat:appcompat:1.2.0")
/// --- end ----
}
app-> build.gradle
buildscript {
ext.kotlin_version = '1.5.21'
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is flutter moengage initialization
final MoEngageFlutter _moengagePlugin = MoEngageFlutter();
void initialise() {
_moengagePlugin.initialise();
}
void initState() {
super.initState();
initialise();
}
mainefestFile
<service android:name="com.moengage.firebase.MoEFireBaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

You to add the required metadata for showing push notification and also pass the payload to the SDK using provided API. Refer to the documentation here - https://docs.moengage.com/docs/push-configuration

Related

Application.kt in flutter project giving error - Cannot access 'com.google.firebase.messaging.zzf'

My application.kt file is as below:
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry?) {
io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}
error I am getting:
Cannot access 'com.google.firebase.messaging.zzf' which is a supertype
of 'io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService'.
Check your module classpath for missing or conflicting dependencies
the line where the error is FlutterFirebaseMessagingService.setPluginRegistrant(this).
my android/build.gradle file have below code for the implementation:
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms:google-services:4.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
I have tried to search a lot but still stuck with this issue. whats wrong here ?
Try this
In android/build.gradle add classpath 'com.google.gms:google-services:4.3.3'
In android/app/build.gradle add implementation "com.google.firebase:firebase-messaging:20.1.0"
OR
Try this
override fun registerWith(registry: PluginRegistry?) {
registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin");
}

Starting a Springboot application in Eclipse on Tomcat

I am trying to run a springboot application on embedded Tomcat server in Eclipse. The project is added successfully to the server but it never starts.
My application code is below:
import java.util.Properties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
import org.springframework.boot.Banner;
#SpringBootApplication
#ImportResource("classpath:simple-camel.xml")
public class CamelApplication {
private static final String DEFAULT_XML_ROUTE_CONFIG_FILES = "classpath:/routes/*.xml";
public static void main(String[] args) {
System.out.println("********************* inside the project ******************");
SpringApplication app = new SpringApplication(CamelApplication.class);
app.setDefaultProperties(getDefaultProperties());
app.run(args);
}
private static Properties getDefaultProperties() {
Properties props = new Properties();
props.setProperty("camel.springboot.main-run-controller", "true");
return props;
}
}
My build.gradle is below:
plugins {
id 'groovy'
id 'java'
id "org.springframework.boot" version "2.2.6.RELEASE"
}
group 'com.firas'
version '1.0-SNAPSHOT'
apply plugin: "org.springframework.boot"
apply plugin: "java"
repositories {
mavenCentral()
}
dependencies {
compile "org.apache.camel:camel-bom:2.25.0"
compile "org.apache.camel:camel-core:2.25.0"
compile "org.apache.camel:camel-spring-boot-dependencies:2.25.0"
compile "org.apache.camel:camel-spring-boot-starter:2.25.0"
compile "org.springframework:spring-aop:4.0.4.RELEASE"
compile "org.springframework:spring-context:4.0.4.RELEASE"
compile "org.springframework:spring-tx:4.0.4.RELEASE"
compile "org.apache.camel.springboot:camel-timer-starter:2.25.0"
compile "org.springframework.boot:spring-boot-starter-tomcat:2.2.6.RELEASE"
testCompile group: 'junit', name: 'junit', version: '4.13'
}
springBoot {
mainClassName = 'CamelApplication'
}
bootJar {
mainClassName = 'CamelApplication'
manifest {
attributes 'Start-Class': 'CamelApplication'
}
}
and below is a screen shot of my Deployment Assembly configuration:
Any hints or guidance on how to fix it? I am not seeing any errors in the log so I am flying blind here.

Dagger 2 with Instant App

I've been working on instant app for a few days. I didn't get it compiled yet due to Dagger issue.
The project is split into base, export, preview as features.
In export module
#ExportScope
#Component(
modules = [DrawExportModule::class],
dependencies = [AppComponent::class])
interface DrawExportComponent: AndroidInjector<LiveDrawingExportActivity> {
#Component.Builder
abstract class Builder : AndroidInjector.Builder<LiveDrawingExportActivity>(){
abstract fun plus(component: AppComponent): Builder
}
}
AppComponent.kt
#Singleton
#Component(modules = [
AndroidInjectionModule::class,
AppModule::class,
ActivityBindingModule::class,
ServiceBindingModule::class])
interface AppComponent {
#Component.Builder
interface Builder {
#BindsInstance
fun application(context: Context): Builder
fun build(): AppComponent
}
fun inject(app: LiveMessageApplication)
}
AppModule.kt
#Module(includes = [(DataModule::class)])
class AppModule {
#Singleton
#Provides
fun provideStateManager(): StateManager {
return StateManager.getInstance()
}
}
Compile error log
/Users/*/features/export/build/tmp/kapt3/stubs/debug/*/ui/draw/di/DrawExportComponent.java:8:
error: [Dagger/MissingBinding] [dagger.android.AndroidInjector.inject(T)] *.ui.StateManager cannot be provided without an #Inject constructor or an #Provides-annotated method.
public abstract interface DrawExportComponent extends dagger.android.AndroidInjector<com.ctech.livemessage.ui.draw.LiveDrawingExportActivity> {
^
*.ui.StateManager is injected at
*.LiveDrawingExportActivity.stateManager
*.LiveDrawingExportActivity is injected at
dagger.android.AndroidInjector.inject(T)
It seems to me dependency component doesn't work in this case. I have no clue to go forward.
More information
base/build.gradle
apply plugin: 'com.android.feature'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion deps.build.compileSdkVersion
baseFeature = true
defaultConfig {
minSdkVersion deps.build.minSdkVersion
targetSdkVersion deps.build.targetSdkVersion
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
dependencies {
application project(":installed")
feature project(":features:export")
feature project(":features:preview")
}
export/build.gradle
apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion deps.build.compileSdkVersion
defaultConfig {
minSdkVersion deps.build.minSdkVersion
targetSdkVersion deps.build.targetSdkVersion
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../../proguard.pro'
signingConfig signingConfigs.debug
}
}
sourceSets {
main {
jniLibs.srcDirs 'libs'
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
dependencies {
implementation project(':features:base')
kapt deps.dagger.compiler
kapt deps.dagger.androidCompiler
}
The issue is that DrawExportComponent doesn't see StateManager, because the latter is part of AppComponent.
Unlike subcomponents, with component dependencies, dependent components don't get access to all of parent component. You have to explicitly specify what's shared, by adding:
fun stateManager(): StateManager
to your AppComponent.
More info in official documentation

Spring Boot Gradle setup

I tried to setup gradle in eclipse Luna for a simple spring boot application, but none of the jars are downloaded. Can anyone give me an idea of what I'm missing ?
I ran gradle clean build in the command line and it compiles successfully:
This is the content of my build.gradle file :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
jar {
baseName = 'sample'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
}
This is the content of the class with the controller:
package sample;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class SampleController {
#RequestMapping("/sample")
public String sampleIt(){
return "Hello! Welcome to Spring Boot Sample. ";
}
}
This is the class with the main function :
package sample;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
#SpringBootApplication
public class SampleApplication {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(SampleApplication.class, args);
System.out.println(ctx.getDisplayName());
System.out.println("This is my first Spring Boot Example");
}
}
Answer from the comment:
It is necessary to install the gradle plugin and import the gradle project afterwards. (Don't forget to click the 'Build Model' button)

How to iterate gradle dependencies in custom gradle plugin?

I have followed this guide:
http://www.gradle.org/docs/current/userguide/custom_plugins.html
to create a standalone gradle plugin with the following structure/files:
my-gradle-plugin
> src
> main
> java
> com
> mygroup
> MyGradlePlugin.groovy
> build.gradle
> settings.gradle
build.gradle :
apply plugin: 'groovy'
dependencies {
compile gradleApi()
groovy localGroovy()
}
apply plugin: 'maven'
repositories {
mavenCentral()
}
group = 'com.mygroup'
version = '1.0.0-SNAPSHOT'
MyGradlePlugin.groovy :
package com.mygroup
import org.gradle.api.*
class MyGradlePlugin implements Plugin<Project> {
void apply(Project project) {
print " project.name " + project.name + "\n"
print " project.dependencies " + project.dependencies + "\n"
// How do we iterate each dependency and print artifactId, group, version??
// project.dependencies.each {
// compile(it) {
// print it.next()
// print it.name
// }
// }
project.configurations.each {
print it.dump()
}
}
}
In another project I use/apply this plugin:
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
repositories {
mavenLocal()
}
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath group: 'com.mygroup', name: 'my-gradle-plugin', version: '1.0.0-SNAPSHOT'
}
}
dependencies {
compile group: 'commons-codec', name: 'commons-codec', version: '1.4'
compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.7.0'
}
install.doLast {
apply plugin: 'my-gradle-plugin'
}
But how do I iterate the commons dependencies from the apply method in MyGradlePlugin.groovy and print their coordinates (artifactId, groupId, version)?
I know this is an old question but since there is not a selected answer I'll throw in an example that I have used. This is based on the example in section 49.8.2.2 of the gradle docs.
I'm using it to do custom dependency resolution, but you can do whatever you'd like inside the dependency iteration. Note that this works because its passing a closure that is executed after the configuration phase.
Plugin code:
package com.overtherainbow
import org.gradle.api.Project
import org.gradle.api.Plugin
import org.gradle.api.artifacts.DependencyResolveDetails
class DefaultVersionPlugin implements Plugin<Project> {
// This is where dependency versions are defined
def defaultVersionsMap = [
'javax.servlet:servlet-api' : '2.5',
'log4j:log4j' : '1.2.16']
void apply(Project project) {
project.configurations.all {
resolutionStrategy.eachDependency {
DependencyResolveDetails details -> resolveDependencyVersion(project, details)
}
}
}
def resolveDependencyVersion(Project project, DependencyResolveDetails details) {
if (details.requested.version == 'default') {
def version = resolveDefaultVersion(project, details.requested.group, details.requested.name)
details.useVersion version
}
}
def resolveDefaultVersion(Project project, String group, String name) {
project.logger.debug("Resolving default dependency for $group:$name")
println "Resolving default dependency for $group:$name"
defaultVersionsMap["$group:$name"]
}
}
The problem is that dependency graph is only available after project is fully evaluated. That's why you can't rely on that directly in the apply method. You have to postpone the execution using the afterEvaluate method. The following code will do the trick:
class MyGradlePlugin implements Plugin<Project> {
void apply(Project project) {
project.afterEvaluate {
println " Project:" + project.name
project.configurations.each { conf ->
println " Configuration: ${conf.name}"
conf.allDependencies.each { dep ->
println " ${dep.group}:${dep.name}:${dep.version}"
}
}
}
}
}
UPDATE: Following question updates and discussions in the comments and chat you can also do the following:
class MyGradlePlugin implements Plugin<Project> {
void apply(Project project) {
project.tasks.findByName('install')?.doLast {
...
}
}
}