I have set up a firebase database and connected to that with the following details, but setValue method is not writing anything. onComplete event is not not even called. What is the reason?
Android Manifest:
<uses-permission android:name="android.permission.INTERNET"/>
Code base:
mFirebaseInstance = FirebaseDatabase.getInstance();
mFirebaseDatabase = FirebaseDatabase.getInstance().getReference("users");
User user = new User("A","B","C");
mFirebaseDatabase.child(usr.getUsername()).setValue(usr);
build.gradle script:
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:4.1.0'
And the main thing which gradle does not accept 11.8.0 which firebase assistant suggests . mine is :
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
implementation 'com.google.firebase:firebase-auth:9.6.1'
implementation 'com.google.firebase:firebase-core:9.6.1'
implementation 'com.google.firebase:firebase-database:9.6.1'
implementation project(':andengine:AndEngine-GLES2-AnchorCenter')
and the database rules are :
"rules": {
".read": true,
".write": true
}
Are there any settings in Firebase or Android studio?
I found finally the answer. Everything was OK except on my country's IP. My country is under sanction and by VPN it solved. but when disconnecing VPN it is not workinf even after compile.
Related
I'm trying to connect to Firebase realtime DB from android.
SDK Version 29
public void init(Context context)
{
FirebaseApp.initializeApp(context);
mDatabase = FirebaseDatabase.getInstance("https://xxxx.europe-west1.firebasedatabase.app/").getReference();
I get the error:
Default FirebaseApp is not initialized in this process com.xxx.xxxx. Make sure to call FirebaseApp.initializeApp(Context) first.
firebase.json is
{
"database": {
"rules": "secrules.json"
}
}
secrules.json is
{
"rules": {
".read": "now < 1619046000000", // 2021-4-22
".write": "now < 1619046000000", // 2021-4-22
}
}
build gradle module app level is
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:26.8.0')
// Declare the dependency for the Realtime Database library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-database'
build gradle project level is
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
I've tried to follow latest guidelines and a few suggestions in stack overflow with no difference.
Project was initialised from the firebase console. I'm not using an emulator database.
The primary firebase projects and related assets including database are initialized automatically, no need to specify anything, just add google services json to project. If for some reason you need to initialize it, best place is the class extending Application.
public ZAONE extends Application {
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
database = FirebaseDatabase.getInstance();
}}
And then add that class to the manifest. A good resource is here, documentation on setting up on Android
I'm new to android and using firebase for an android app.
I have added the firebase realtime database by using the firebase assistant provided by android studio.
When I try proceeding with adding firebase code, android studio shows the error "cannot resolve..." with anything firebase related.
DatabaseReference myRef = database.getReference("message");
myRef.setValue("Hello, World!");
I have looked for a solution everywhere, re-added firebase multiple times and it still won't work. Of course, I have checked for the correct dependencies in the gradle scripts.
This is what it looks like currently:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-database:19.2.0'
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-firestore:21.3.1'
I would really appreciate some help. I might have missed something small due to being a beginner.
I have only three line of code to send msg to firebase and when I run app it automatically terminated. I added firebase through Tools menu.
I have tried internet permission to manifest file but didn't work.
var firebaseDatabase = FirebaseDatabase.getInstance()
var databaseRef = firebaseDatabase.reference
databaseRef.setValue("Hello There")
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.core:core-ktx:1.2.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
implementation 'com.google.android.material:material:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-database:16.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.1.0'
}
}
"I/FirebaseInitProvider: FirebaseApp initialization unsuccessful"
"Unable to start activity ComponentInfo{.MainActivity}:
java.lang.IllegalStateException: Default FirebaseApp is not
initialized in this process ... Make sure to call
FirebaseApp.initializeApp(Context) first."
As the error says, you need to init the FirebaseApp instance before calling its methods. This it the line:
FirebaseApp.initializeApp(this); // "this" is a context
A common way to do it - to add this line to onCreate() method of your custom Application class.
And here, on Codepath you can find how to create your custom Application class to put that line in.
Update
This will work after you configure the Firebase App project in Firebase Console as well. Don't forget to do the steps from here, Firebase docs
I have already referred to other answers like this, but still getting the following exception :
E/UncaughtException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/volley/toolbox/Volley;
Here are the dependencies :
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.google.android.gms:play-services-base:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation "com.google.firebase:firebase-messaging:15.0.0"
implementation 'com.google.firebase:firebase-core:12.0.1'
implementation 'com.android.volley:volley:1.1.0'
apply plugin: 'maven'
}
As a matter of fact, when I try adding Volley as a dependency, it is never shown in the list of dependencies. Whereas other google libraries are displayed.
Note : I have already checked other StackOverFlow links, so please, only if you are absolute sure that an answer is correctly working for this, feel free to mark this a duplicate.
Open Command prompt and redirect to your project directory and type this
If you are a Windows user: gradlew.bat clean
if you are a mac user type: ./gradlew clean
If your targetSdkVersion is between 26 and 28, try adding uses-library android:name="org.apache.http.legacy" android:required="false" in application tag in AndroidManifest. The second approach is: import volley.jar into your app/lids directory and instead of fetching it from gradle, use your local jar as implementation files('libs/volley.jar') in build.gradle in app module
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.augmentedreality.projectar. Make sure to call FirebaseApp.initializeApp(Context) first.
For the past 48 hours I've been stuck at this Exception, and so far has no clue what's possibly causing this, I've referred all these answers:
Default FirebaseApp is not initialized
Getting “Default FirebaseApp is not initialized in this process” despite initializing FirebaseApp while using FirebaseStorage
FirebaseApp not initializing despite FirebaseApp.initializeApp() being called in Application class
How can I solve the Android Firebase error “Default FirebaseApp is not initialised in this process”?
And yet the problem persists. I am using Firebase Storage as well as Firebase Database. I use Firebase storage to download image using a Service. The Service is same as the Firebase quick start example from Github[here].
Now, the exception is thrown at this line :
mStorageRef = FirebaseStorage.getInstance().getReferenceFromUrl("https://firebasestorage.googleapis.com/v0/b/xxxxxxx-xx-xxxxxx.appspot.com/o/Coca-Cola.jpg?alt=media&token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
Based on the answers mentioned in the aforementioned questions, I've made the following changes:
1)AppMain.java
public class AppMain extends Application {
#Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
Firebase.setAndroidContext(this);
//if(!FirebaseApp.getApps(this).isEmpty()) {
// FirebaseDatabase.getInstance().setPersistenceEnabled(true);
//}
}
}
2) Dependencies
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-database:9.6.1'
compile 'com.firebase:firebase-client-android:2.5.2+'
compile 'com.google.firebase:firebase-storage:9.6.1'
compile 'com.google.android.gms:play-services:10.0.0'
}
Question: How to fix this issue?
Remove
FirebaseApp.initializeApp(this);
Firebase.setAndroidContext(this);
compile 'com.firebase:firebase-client-android:2.5.2+'
you dont need them..
use
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.google.firebase:firebase-storage:10.0.1'
compile 'com.google.android.gms:play-services:10.0.1'
private DatabaseReference mDatabase;
// ...
mDatabase = FirebaseDatabase.getInstance().getReference();
instead,
for full instructions -
Firebase Docs
Instead of modifying this code,
You should update the Android studio version. May be your problem will be solved.