I try to undo a delete operation through the action provided by Snackbar.
Here is the delete operation:
dbRef.child(footballer.getFullName()).removeValue();
When I call the undo operation through the command added below, getting com.google.firebase.database.DatabaseException: Failed to parse node with class exception:
dbRef.setValue(footballer.getFullName(), footballer);
dbRef is assigned to the root of the collection:
DatabaseReference dbRef = database.getReference("footballers");
Here is my Footballer model:
#IgnoreExtraProperties
public class Footballer {
private String fullName;
private String desc;
private String photoUrl;
private String teamUrl;
public Footballer() {
}
public Footballer(String fullName, String desc, String photoUrl, String teamUrl) {
this.fullName = fullName;
this.desc = desc;
this.photoUrl = photoUrl;
this.teamUrl = teamUrl;
}
// getter-setter methods
}
Here is the structure of Firebase database:
footballers
----Cristiano Ronaldo
--------fullName
--------desc
--------photoUrl
--------teamUrl
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.tk"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-database:11.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:recyclerview-v7:26.1.0'
// Support Design Lib
implementation 'com.android.support:design:26.1.0'
// Swipe Action
compile 'co.dift.ui.swipetoaction:library:1.1'
// Facebook Fresco
compile 'com.facebook.fresco:fresco:0.6.1'
}
apply plugin: 'com.google.gms.google-services'
Related
I started to encounter this error when I upgraded the version of the project to androidx. I also upgraded the firebase sdks. I started getting error "Cannot resolve symbol 'FirebaseInstanceId' " . With this method, I was taking the user's token and printing it to the database. How can I solve this problem?
Manifest :
<service
android:name=".MyFirebaseIdService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_SERVICE" />
</intent-filter>
MyFirebaseIdService;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class MyFirebaseIdService extends FirebaseInstanceIdService {
#Override
public void onTokenRefresh() {
super.onTokenRefresh();
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
String refreshToken = FirebaseInstanceId.getInstance().getToken();
if (firebaseUser != null){
updateToken(refreshToken);
}
}
private void updateToken(String refreshToken) {
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Tokens");
Token token = new Token(refreshToken);
reference.child(firebaseUser.getUid()).setValue(token);
}
}
Token ( model class ):
public class Token {
private String token;
public Token(String token) {
this.token = token;
}
public Token() {
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}
I was rewriting the token code every time the user entered the home page.
MainActiviy :
updateToken(FirebaseInstanceId.getInstance().getToken());
private void updateToken(String token){
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Tokens");
Token token1 = new Token(token);
reference.child(fuser.getUid()).setValue(token1);
}
build.gradle ( project )
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle ( module )
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
android {
compileSdkVersion 30
defaultConfig {
applicationId "***"
minSdkVersion 19
targetSdkVersion 30
versionCode 21
versionName "1.1.9"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout: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'
implementation 'com.firebaseui:firebase-ui-database:4.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.github.orangegangsters:swipy:1.2.3#aar'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.firebaseui:firebase-ui-database:4.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-inappmessaging-display:17.0.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation('com.google.apis:google-api-services-people:v1-rev2-1.21.0')
{
exclude module: 'guava-jdk5'
}
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.google.firebase:firebase-ads:15.0.1'
implementation "io.grpc:grpc-okhttp:1.32.2"
implementation 'com.android.billingclient:billing:3.0.0'
implementation platform('com.google.firebase:firebase-bom:29.3.0')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-core:20.1.2'
implementation 'com.google.firebase:firebase-messaging:23.0.2'
implementation 'com.google.firebase:firebase-auth:21.0.3'
}
apply plugin: 'com.google.gms.google-services'
----- UPDATE ---- SOLUTÄ°ON :
FirebaseMessaging.getInstance ().getToken ()
.addOnCompleteListener ( task -> {
if (!task.isSuccessful ()) {
return;
}
if (null != task.getResult ()) {
String firebaseMessagingToken = Objects.requireNonNull ( task.getResult () );
updateToken(firebaseMessagingToken);
}
} );
private void updateToken(String firebaseMessagingToken) {
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Tokens");
Token token = new Token(firebaseMessagingToken);
reference.child(firebaseUser.getUid()).setValue(token);
}
I already was using room database in my application. Now I have migrated my project to androidX, so dependencies are changed.
Now when I am adding a table and trying to run the project, I am getting an error for multiple files:
error: cannot find symbol class BR
Here is my model class:
#Keep
#Entity
public class Notification {
private String title;
private String body;
public Notification(String title, String body) {
this.title = title;
this.body = body;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
}
Here is my NotificationDao Class:
public abstract class NotificationDao {
#Insert(onConflict = REPLACE)
public abstract void insert(Notification notification);
#Query("DELETE FROM Notification")
public abstract void deleteAll();
}
Here is the code written for migration:
static final Migration MIGRATION_1_2 = new Migration(1, 2) {
#Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE IF NOT EXISTS Notification (`title` TEXT, `body` TEXT)");
}
};
I have increased the version from 1 to 2.
I have added this in build as well.
Room.databaseBuilder(
application,
MyDatabase.class,
Configuration.DB_NAME
).addMigrations(MyDatabase.MIGRATION_1_2).build();
app.gradle is:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode 211990017
versionName "2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// Write out the current schema of Room
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString(),]
}
}
vectorDrawables.useSupportLibrary = true
project.archivesBaseName = "xxxx";
multiDexEnabled true
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -fexceptions"
arguments "-DANDROID_TOOLCHAIN=clang",
"-DANDROID_STL=c++_shared",
"-DANDROID_PLATFORM=android-21"
}
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
signingConfigs {
release {
storeFile file("keystores/xxxx")
storePassword "xxxx"
keyAlias "xxxx"
keyPassword "xxxx"
}
}
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 {
release {
minifyEnabled false
shrinkResources false
proguardFiles fileTree(dir: "proguard", include: ["*.pro"]).asList().toArray()
proguardFiles getDefaultProguardFile('proguard-android.txt')
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
shrinkResources false
proguardFiles fileTree(dir: "proguard", include: ["*.pro"]).asList().toArray()
proguardFiles getDefaultProguardFile('proguard-android.txt')
signingConfig signingConfigs.release
}
}
dataBinding {
enabled true
}
buildToolsVersion '28.0.3'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
flavorDimensions "environment"
productFlavors {
development {
applicationId "com.emproto.xxxx"
resValue "string", "content_provider", "com.xxx.xxxx.fileprovider"
}
production {
applicationId "com.xxxx"
resValue "string", "content_provider", "com.xxxx.fileprovider"
}
}
splits {
// Configures multiple APKs based on ABI.
abi {
// Enables building multiple APKs per ABI.
enable true
// By default all ABIs are included, so use reset() and include to specify that we only
// want APKs for x86 and x86_64.
// Resets the list of ABIs that Gradle should create APKs for to none.
reset()
// Specifies a list of ABIs that Gradle should create APKs for.
include "x86", "x86_64", "arm64-v8a", "armeabi-v7a"
// Specifies that we do not want to also generate a universal APK that includes all ABIs.
universalApk true
}
}
}
ext.abiCodes = ['x86': 1, 'x86_64': 2, 'armeabi-v7a': 3, 'arm64-v8a': 4]
import com.android.build.OutputFile
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def baseVersionCode = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
if (baseVersionCode != null) {
output.versionCodeOverride = Integer.valueOf(baseVersionCode + variant.versionCode)
}
}
}
ext {
retrofitVersion = '2.3.0'
daggerVersion = '2.11'
supportLibVersion = '28.0.0'
googleLibVersion = '16.0.1'
frescoLibVersion = '2.0.0'
moEngageVersion = '9.8.02'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.exifinterface:exifinterface:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
/*Dagger 2 is a fully static and compile time dependency injection framework*/
implementation "com.google.dagger:dagger:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
implementation 'javax.annotation:jsr250-api:1.0'
/*LiveData and ViewModel*/
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
/*
annotationProcessor "android.arch.lifecycle:compiler:1.1.0"
*/
/*Room*/
implementation 'androidx.room:room-runtime:2.2.3'
annotationProcessor 'androidx.room:room-compiler:2.2.3'
// Java8 support for Lifecycles
implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0'
/*Retrofit*/
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
/*For loading images from network*/
implementation "com.facebook.fresco:fresco:$frescoLibVersion"
implementation "com.facebook.fresco:imagepipeline-okhttp3:$frescoLibVersion"
/*For the left menu*/
implementation 'com.yarolegovich:sliding-root-nav:1.1.0'
/*For the typing indicator*/
implementation 'com.github.channguyen:adv:1.0.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
/*For Graphs */
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
/*For firebase push notifications */
implementation "com.google.firebase:firebase-messaging:17.3.4"
implementation "com.google.firebase:firebase-core:16.0.6"
/*For Database debugging */
// debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'
/*For S - Health */
implementation files('libs/s-health/samsung-health-data-v1.3.0.jar')
implementation files('libs/s-health/sdk-v1.0.0.jar')
/*For Google-Fit */
implementation "com.google.android.gms:play-services-fitness:$googleLibVersion"
implementation "com.google.android.gms:play-services-auth:$googleLibVersion"
/*Circular floating action bar*/
implementation 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
// For animated GIF support
implementation "com.facebook.fresco:animated-gif:$frescoLibVersion"
/*Circular seekbar - Feelings*/
implementation 'com.github.JesusM:HoloCircleSeekBar:v2.2.2'
/*Circular Layout - Feelings*/
implementation 'com.github.andreilisun:circular-layout:1.0'
/*For offline log synchronization*/
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
/*Wheel picker - RecordCholesterol*/
implementation 'com.weigan:loopView:0.1.2'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.3#aar') {
transitive = true;
}
/*Image Cropper - Profile Fragment*/
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+'
/*PDF Viewer - Prescription/Report */
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
api 'com.thedesigncycle.ui:views:0.3.1'
implementation 'com.ogaclejapan.smarttablayout:library:1.6.1#aar'
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.11.0'
implementation files('libs/omron/jp.co.omron.healthcare.omoron_connect.wrapper-1.3.jar')
implementation 'com.appsee:appsee-android:+'
implementation 'com.github.florent37:viewtooltip:1.1.6'
implementation 'com.asksira.android:cameraviewplus:0.9.5'
implementation 'me.zhanghai.android.materialratingbar:library:1.3.1'
implementation 'com.priyankvex:smarttextview:1.0.1'
implementation 'com.github.flipkart-incubator:android-inline-youtube-view:1.0.3'
implementation 'com.github.varunest:sparkbutton:1.0.6'
implementation 'io.branch.sdk.android:library:3.2.0'
//foo transitions in trel home(doctor names)
implementation "com.andkulikov:transitionseverywhere:1.8.1"
//AppsFlyer
implementation 'com.appsflyer:af-android-sdk:4.10.3'
implementation 'com.android.installreferrer:installreferrer:1.0'
//picasso image loading lib
implementation 'com.squareup.picasso:picasso:2.5.2'
//Facebook analytics dependency
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
//Moengage dependency
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.moengage:moe-android-sdk:$moEngageVersion"
}
apply plugin: 'com.google.gms.google-services'
How can the error be fixed?
Not adding the primary key in model class was causing the problem. I think more specific error messages should be there from android studio's side regarding room database.
I created simple offline database using room but I got this error
Caused by: java.lang.RuntimeException: cannot find implementation for
com.test.test.AppDatabase.SplashScreenActivity_AppDatabase_Impl does
not exist
Code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
AppDatabase appDatabase = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "testDatabase").build();
Categories category = new Categories();
category.setId(0);
category.setId(1);
category.setCategoryName("Te");
category.setCategoryName("Test");
appDatabase.categoriesDao().insertAll(category);
}
#Entity
class Categories {
#PrimaryKey
int id;
#ColumnInfo(name = "category_name")
String categoryName;
void setId(int id) {
this.id = id;
}
void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
}
#Dao
public interface CategoriesDao {
#Insert
void insertAll(Categories... categories);
}
#Database(entities = {Categories.class}, version = 1)
abstract class AppDatabase extends RoomDatabase {
abstract CategoriesDao categoriesDao();
}
Build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.**********"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled 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
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Material Design
implementation 'com.google.android.material:material:1.2.0-alpha01'
//Butter Knife
implementation 'com.jakewharton:butterknife:10.2.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
//Volley
implementation 'com.android.volley:volley:1.1.1'
//Room
implementation "androidx.room:room-runtime:2.2.0"
}
apply plugin: 'com.jakewharton.butterknife'
I found many solutions on this website but all not working with me, Thank you.
First of all you have add annotationProcessor in your build.gradle file
annotationProcessor "androidx.room:room-compiler:2.2.0"
Either make your AppDatabase class static inside SplashScreenActivity like:
#Database(entities = {Categories.class}, version = 1)
abstract static class AppDatabase extends RoomDatabase {
abstract CategoriesDao categoriesDao();
}
Or Create separate file for AppDatabase rather than inner class
I'm trying to import Firebase and FCM into my android app, but I'm getting
Unresolved class for firebase ".MyFirebaseInstanceIDService"
Unresolved package for firebase ".java.MyFirebaseMessagingService"
as an "error." Of course, it isn't stopping my app from running or building, but I cannot call onTokenRefresh in any class at all. So, I believe this problem is preventing me from using Firebase.
here is my app build;
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.northlandcaps.crisis_response"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
android {
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
}
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout: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'
implementation 'com.android.support:mediarouter-v7:28.0.0'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
}
apply plugin: 'com.google.gms.google-services'
Screenshot of problem
This how you two classes should look like:
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
#Override
public void onTokenRefresh() {
super.onTokenRefresh();
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(String token) {
// Add custom implementation, as needed.
}
}
And:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
RemoteMessage.Notification notification = remoteMessage.getNotification();
Map<String, String> data = remoteMessage.getData();
sendNotification(notification, data);
}
private void sendNotification(RemoteMessage.Notification notification, Map<String, String> data) {
//Send notification
}
}
I followed vogella article: http://www.vogella.com/tutorials/Dagger/article.html
I did everything step by step as they suggested. My build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "test.daggertest"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.dagger:dagger:2.15'
implementation 'com.google.dagger:dagger-android:2.15'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.15'
annotationProcessor 'com.google.dagger:dagger-compiler:2.15'
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'
}
MyApplication class:
public class MyApplication extends Application implements HasActivityInjector
{
#Inject
DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
#Override
public void onCreate()
{
super.onCreate();
DaggerMyApplicationComponent.create().inject(this);
}
#Override
public DispatchingAndroidInjector<Activity> activityInjector()
{
return dispatchingAndroidInjector;
}
}
Then I did Rebuild project, and still it throws error DaggerMyApplicationComponent is unresolved.
Am I missing something or their article is outdated? Any ideas?