0

I did an android client application using Firebase, it's working well. I want to do an admit application, but I got an issue. it looks like there are threads with the same issue, but the solution did not work for me.

I'm following the doc: https://firebase.google.com/docs/admin/setup

Then I created a brand new project (this project do not have client library and won't have). I added

compile 'com.google.firebase:firebase-admin:4.1.3'

First, I got this error

Error:Conflict with dependency 'com.google.code.findbugs:jsr305' in project ':app'. Resolved versions for app (1.3.9) and test app (2.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

After investigation, I found

Error:Conflict with dependency 'com.google.code.findbugs:jsr305'.

The solution is to add

 configurations.all {
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}

It's working, but I still got some warning.

Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160212 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160212 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160212 is ignored for release as it may be conflicting with the internal version provided by Android.

I can live with that, then I continue.

I create my admin key and downloaded the file. In the doc, they ask us to do this code:

FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");

But I did not found where to put the file to make it work (obviously with the right folder name and file name). After some investigation, I found I can place the file in

res/raw/serviceAccountKey.json

and creating a FileInputStream like this

InputStream serviceAccount = getResources().openRawResource(R.raw.serviceAccountKey);

Perfect. Seems to work, then the code look like this

    InputStream serviceAccount = getResources().openRawResource(R.raw.serviceAccountKey);
    FirebaseOptions options = new FirebaseOptions.Builder()
            .setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
            .setDatabaseUrl("https://" + m_databaseName + ".firebaseio.com/")
            .build();
    FirebaseApp.initializeApp(options);

For now, I don't have any error. then I do the next step

    ref.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            System.out.println("The read succeed");
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            System.out.println("The read failed: " + databaseError.getCode());
        }
    });

But, onDataChange and onCancelled are never called. I don't see any error.

After investigation, I found others with the same issue

Firebase Admin Java SDK not doing any operation

But the solution did not work.

have Anyone an idea? Thanks

Community
  • 1
  • 1
qqchose
  • 7
  • 3
  • 1
    Firebase engineers advise against using the Admin SDK in an Android app. See here: http://stackoverflow.com/a/42103063/4815718 – Bob Snyder Mar 19 '17 at 03:11
  • This Answer is "You can't use the Firebase Admin SDK in an Android app alongside the Firebase Android client libraries." But this is not my case. I'm not adding Admin sdk in a client app. I'm creating a brand new app with only the admit sdk – qqchose Mar 19 '17 at 11:58
  • Ok, I found this too http://stackoverflow.com/questions/42163212/firebase-admin-sdk-causes-gradle-dependency-error?noredirect=1&lq=1 Look like you are right and I cannot do an admin app in android. Ok, then I'm trying eclipse to do an admin app. but I do no find any Build.Gradle file in my eclipse project to add the compile 'com.google.firebase:firebase-admin:4.1.3' Where am I supposed to add this in my eclipse project if I only see the build.gradle in my android project – qqchose Mar 19 '17 at 14:44

1 Answers1

0

After some research I found the problem. Like "qbix" comment, Firebase admin can not be done in android.

I usually work in c++ and java/gradle/android is totally new to me. I did not know "gradle" was not just a file in Android studio.

Then if you are like me and you are new in android/firebase/java and did the same mistake than I did, there is a to make it work.

Installed Eclipse IDE for Java EE Developers https://eclipse.org/downloads/eclipse-packages/

add Gradle support to eclipse http://www.vogella.com/tutorials/EclipseGradle/article.html

Create a new project. (Use tutorial from Eclipse)

Redo the firebase tutorial for firebase from firebase tutorial

and now I finally reach my breakpoint in onDataChange and the data seems right

qqchose
  • 7
  • 3