I'm trying to save data to my realtime database using the setValue() methods but it's not saving my object.
I tried with a simple String and still didn't worked.
My code :
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference ref = db.getReference();
ref.setValue("user");
Toast.makeText(RegisterApp.this, "Passe tranquille #1! Ref = " + ref.toString() + " | Db = " + db.toString(), Toast.LENGTH_LONG).show();
The makeText is called and show me good information which (should) show that it's connected to the database?
But still my realtime db shown null instead of string "user".
build.graddle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.4.32'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.google.gms:google-services:4.3.8'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
}
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.graddle with version set by myself
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.projetl3"
minSdkVersion 26
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
configurations {
compile.exclude group: "guava", module: "guava"
implementation.exclude module:'proto-google-common-protos'
implementation.exclude module:'protolite-well-known-types'
implementation.exclude module:'guava'
implementation.exclude module:'protobuf-lite'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/DEPENDENCIES'
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.firebase:firebase-database:20.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// CameraX core library using camera2 implementation
implementation "androidx.camera:camera-camera2:1.1.0-alpha04"
// CameraX Lifecycle Library
implementation "androidx.camera:camera-lifecycle:1.1.0-alpha04"
// CameraX View class
implementation "androidx.camera:camera-view:1.0.0-alpha24"
implementation 'com.google.android.gms:play-services-vision:20.1.3'
implementation platform('com.google.cloud:libraries-bom:20.2.0')
implementation 'com.google.cloud:google-cloud-vision'
implementation 'com.google.api-client:google-api-client-android:1.22.0'
implementation 'com.google.apis:google-api-services-vision:v1-rev357-1.22.0'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:28.0.1')
// Add the dependency for the Firebase SDK for Google Analytics
// When using the BoM, don't specify versions in Firebase dependencies
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-database:20.0.0'
}
app/build.graddle with bom version :
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.projetl3"
minSdkVersion 26
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
configurations {
compile.exclude group: "guava", module: "guava"
implementation.exclude module:'proto-google-common-protos'
implementation.exclude module:'protolite-well-known-types'
implementation.exclude module:'guava'
implementation.exclude module:'protobuf-lite'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/DEPENDENCIES'
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// CameraX core library using camera2 implementation
implementation "androidx.camera:camera-camera2:1.1.0-alpha04"
// CameraX Lifecycle Library
implementation "androidx.camera:camera-lifecycle:1.1.0-alpha04"
// CameraX View class
implementation "androidx.camera:camera-view:1.0.0-alpha24"
implementation 'com.google.android.gms:play-services-vision:20.1.3'
implementation platform('com.google.cloud:libraries-bom:20.2.0')
implementation 'com.google.cloud:google-cloud-vision'
implementation 'com.google.api-client:google-api-client-android:1.22.0'
implementation 'com.google.apis:google-api-services-vision:v1-rev357-1.22.0'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:28.0.1')
// Add the dependency for the Firebase SDK for Google Analytics
// When using the BoM, don't specify versions in Firebase dependencies
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-database'
}
My rules : ( I even tried to put them to true, or even "true")
{
"rules": {
".read": "now < 1623794400000", // 2021-6-16
".write": "now < 1623794400000", // 2021-6-16
}
}