Firebaseui-android: Refactor to AndroidX

Created on 6 Jul 2018  ·  23Comments  ·  Source: firebase/FirebaseUI-Android

AndroidX just hit beta (stable APIs) a few days ago which means we should all get ready to migrate, but the Android team hasn't left us a whole lot of guidance on how we're all supposed to move forward. For public APIs that take in old support components (like our recycler view adapters), they won't compile with the new stuff last time I tried to do so in alpha. That means we have to release a 5.0, I guess? But if we do that, then devs have to upgrade to AndroidX themselves and other libraries might not have upgraded. But if we don't, devs can't upgrade. 😕 Seems like a catch-22 unless I'm missing something.

Anyway, wanted to start this discussion with everyone. @samtstern What are your thoughts?

PS: this comment suggests the public API stuff not compiling was a bug. Will update after I try refactoring again.

refactor

Most helpful comment

Now that AndroidX has reached stable version, this might be really good idea! What do you guys think?

All 23 comments

Update: turns out the Jetifier does work now. 👏 Stuff will compile, it's just IntelliJ that gets mad. 👍

I really love this idea! I've been using AndroidX for most of my projects. And so far, integrating Firebase with my AndroidX-based project turns out to be well.

Looking forward for this feature to be implemented.

@iamyaoxi Funny that you mention it, I'm actually in the middle of the refactor right now. 😁 The tooling is _waaaaaaay_ better than it was back in the early alphas. I'm actually really impressed—haven't had any compile time issues so far. (We'll see about runtime issues 😉)

Anyway, another thought: we'll also want to look into the new com.google.android.material components to see what UI stuff we can spice up.

Yes, that'd be awesome! 👍

And the new Material Components for Android makes it very easy to Theme and Style for even older Android version!

@SUPERCILEX thanks for starting the discussion!

I definitely want to wait until we get to full stable, but good to try and understand what work we will have to do and what work devs will have to do.

Android X is in beta and claims to be stable for production use with minor bugs.

I went ahead and moved to Android X not realizing this would affect firebase ui. I had no problems using a pixel 2 xl and galaxy s8 as test devices.

Some users (about 3 percent from what I saw - could be higher but I had it fixed quickly) could not use the firebase ui sign in. The app would just crash with resource not found - including some users using the same devices I tested on.

I have no idea why this happens but adding my own Google sign in option was my work around for the firebase ui login screen not working.

The recycler adapter appears to work just fine and has for the last two weeks.

@krwilson8 thanks for the field report! Could you file a new issue with the crash that those ~3% of users are getting? Any information you have would be useful (stack trace, device types, OS, dependencies, etc)

Doesn't seem to be a trend in device type or OS version. I've seen it on 5, 6, 7, and 8.

Here's a stack trace from crashlytics.

Fatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{/com.firebase.ui.auth.KickoffActivity}: java.lang.RuntimeException: Cannot create an instance of class com.firebase.ui.auth.data.b.g
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2793)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2864)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1567)
android.os.Handler.dispatchMessage (Handler.java:105)
android.os.Looper.loop (Looper.java:156)
android.app.ActivityThread.main (ActivityThread.java:6523)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:942)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:832)
Caused by java.lang.RuntimeException
Cannot create an instance of class com.firebase.ui.auth.data.b.g
androidx.lifecycle.u$a.a (ViewModelProvider.java:202)
androidx.lifecycle.u.a (ViewModelProvider.java:1135)
com.firebase.ui.auth.KickoffActivity.onCreate (KickoffActivity.java:33)
android.app.Activity.performCreate (Activity.java:6915)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1123)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2746)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2864)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1567)
android.os.Handler.dispatchMessage (Handler.java:105)
android.os.Looper.loop (Looper.java:156)
android.app.ActivityThread.main (ActivityThread.java:6523)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:942)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:832)
Caused by java.lang.NoSuchMethodException
[class android.app.Application]
java.lang.Class.getConstructor0 (Class.java:2204)
java.lang.Class.getConstructor (Class.java:1683)
androidx.lifecycle.u$a.a (ViewModelProvider.java:200)
androidx.lifecycle.u.a (ViewModelProvider.java:1135)
com.firebase.ui.auth.KickoffActivity.onCreate (KickoffActivity.java:33)
android.app.Activity.performCreate (Activity.java:6915)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1123)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2746)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2864)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1567)
android.os.Handler.dispatchMessage (Handler.java:105)
android.os.Looper.loop (Looper.java:156)
android.app.ActivityThread.main (ActivityThread.java:6523)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:942)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:832)

Oh hey, yup. I reported it and the bug will be fixed in rc02: https://issuetracker.google.com/issues/112230489

Good to know, I'll try your work around for pro-guard. Other than that, I haven't had any issues that I can tell with using Android X and Firebase UI.

I'm getting error when extending FirebaseRecyclerAdapter and passing androidx.recyclerview.widget.RecyclerView.ViewHolder as type argument.

class PhotoOnlineAdapter : FirebaseRecyclerAdapter<Photo, RecyclerView.ViewHolder>(...)
Android Studio says:
Type argument is not within its bounds
Expected: android.support.v7.widget.RecyclerView.ViewHolder
Found: androidx.recyclerview.widget.RecyclerView.ViewHolder

I'm using FirestoreRecyclerAdapter. I'm not at my computer so I can't
verify if that's the same or different from what you are doing but you can
try looking into that.

Perhaps the Firebase version uses the concrete class in its template and
the firebase version uses an interface.

On Fri, Aug 17, 2018, 09:09 Stanisław Barański notifications@github.com
wrote:

I'm getting error when extending FirebaseRecyclerAdapter and passing
androidx.recyclerview.widget.RecyclerView.ViewHolder as type argument.

class PhotoOnlineAdapter : FirebaseRecyclerAdapter RecyclerView.ViewHolder>(...)
Android Studio says: Type argument is not within its bounds
Expected: android.support.v7.widget.RecyclerView.ViewHolder
Found: androidx.recyclerview.widget.RecyclerView.ViewHolder


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/firebase/FirebaseUI-Android/issues/1388#issuecomment-413860208,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGTKxMMPWw4L_Dt6_akuKNVWr4ii3-vTks5uRsCggaJpZM4VE6iW
.

Ignore what Studio says, it will compile.

Now that AndroidX has reached stable version, this might be really good idea! What do you guys think?

I'm getting error when extending FirebaseRecyclerAdapter and passing androidx.recyclerview.widget.RecyclerView.ViewHolder as type argument.

class PhotoOnlineAdapter : FirebaseRecyclerAdapter<Photo, RecyclerView.ViewHolder>(...)
Android Studio says:
Type argument is not within its bounds
Expected: android.support.v7.widget.RecyclerView.ViewHolder
Found: androidx.recyclerview.widget.RecyclerView.ViewHolder

Getting the same issue, can't use FirestoreRecyclerAdapter since it uses support.v7 instead of androidx. Did you find any workaround?

I'm getting error when extending FirebaseRecyclerAdapter and passing androidx.recyclerview.widget.RecyclerView.ViewHolder as type argument.

class PhotoOnlineAdapter : FirebaseRecyclerAdapter<Photo, RecyclerView.ViewHolder>(...)
Android Studio says:
Type argument is not within its bounds
Expected: android.support.v7.widget.RecyclerView.ViewHolder
Found: androidx.recyclerview.widget.RecyclerView.ViewHolder

Try setting

android.enableJetifier=true
android.useAndroidX=true

under gradle.properties. This fixed the issue for me.

I'm getting error when extending FirebaseRecyclerAdapter and passing androidx.recyclerview.widget.RecyclerView.ViewHolder as type argument.
class PhotoOnlineAdapter : FirebaseRecyclerAdapter<Photo, RecyclerView.ViewHolder>(...)
Android Studio says:
Type argument is not within its bounds
Expected: android.support.v7.widget.RecyclerView.ViewHolder
Found: androidx.recyclerview.widget.RecyclerView.ViewHolder

Try setting

android.enableJetifier=true
android.useAndroidX=true

under gradle.properties. This fixed the issue for me.

I tried the same two lines of code in gradle.properties but there is no change, error is the same.
Here is my ViewHolder class

public static class FindFriendsViewHolder extends RecyclerView.ViewHolder {

        TextView username, userStatus;
        CircleImageView profileImageView;

        public FindFriendsViewHolder(View itemView) {
            super(itemView);

            username = itemView.findViewById(R.id.tv_username);
            userStatus = itemView.findViewById(R.id.tv_user_status);
            profileImageView = itemView.findViewById(R.id.users_profile_image);
        }
    }

Here is how I'm implementing it

`FirebaseRecyclerOptions<Contacts> options =
            new FirebaseRecyclerOptions.Builder<Contacts>()
                    .setQuery(dbReference, Contacts.class)
                    .build();

    FirebaseRecyclerAdapter<Contacts, FindFriendsViewHolder> adapter =
            new FirebaseRecyclerAdapter<Contacts, FindFriendsViewHolder>(options) {
        @Override
        protected void onBindViewHolder(@NonNull FindFriendsViewHolder holder, int position, @NonNull Contacts model) {
            holder.username.setText(model.getUser_name());
            holder.userStatus.setText(model.getUser_status());
            Picasso.get().load(model.getUser_image())
                    .placeholder(R.drawable.default_user_img)
                    .error(R.drawable.default_user_img)
                    .resize(85,85)
                    .into(holder.profileImageView);
        }

        @NonNull
        @Override
        public FindFriendsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.users_display_layout, parent, false);
            FindFriendsViewHolder viewHolder = new FindFriendsViewHolder(view);

            return viewHolder;
        }
    };
    mRecyclerView.getAdapter(adapter);
    adapter.startListening();`

And here are my imports

    import com.firebase.ui.database.FirebaseRecyclerAdapter;
    import com.firebase.ui.database.FirebaseRecyclerOptions;
    import com.google.firebase.database.DatabaseReference;
    import com.google.firebase.database.FirebaseDatabase;

    import com.squareup.picasso.Picasso;

    import androidx.annotation.NonNull;
    import androidx.fragment.app.Fragment;
    import androidx.recyclerview.widget.LinearLayoutManager;
    import androidx.recyclerview.widget.RecyclerView;
    import de.hdodenhof.circleimageview.CircleImageView;

I'm getting error when extending FirebaseRecyclerAdapter and passing androidx.recyclerview.widget.RecyclerView.ViewHolder as type argument.
class PhotoOnlineAdapter : FirebaseRecyclerAdapter<Photo, RecyclerView.ViewHolder>(...)
Android Studio says:
Type argument is not within its bounds
Expected: android.support.v7.widget.RecyclerView.ViewHolder
Found: androidx.recyclerview.widget.RecyclerView.ViewHolder

Try setting

android.enableJetifier=true
android.useAndroidX=true

under gradle.properties. This fixed the issue for me.

I tried the same two lines of code in gradle.properties but there is no change, error is the same.
Here is my ViewHolder class

public static class FindFriendsViewHolder extends RecyclerView.ViewHolder {

        TextView username, userStatus;
        CircleImageView profileImageView;

        public FindFriendsViewHolder(View itemView) {
            super(itemView);

            username = itemView.findViewById(R.id.tv_username);
            userStatus = itemView.findViewById(R.id.tv_user_status);
            profileImageView = itemView.findViewById(R.id.users_profile_image);
        }
    }

Here is how I'm implementing it

`FirebaseRecyclerOptions<Contacts> options =
            new FirebaseRecyclerOptions.Builder<Contacts>()
                    .setQuery(dbReference, Contacts.class)
                    .build();

    FirebaseRecyclerAdapter<Contacts, FindFriendsViewHolder> adapter =
            new FirebaseRecyclerAdapter<Contacts, FindFriendsViewHolder>(options) {
        @Override
        protected void onBindViewHolder(@NonNull FindFriendsViewHolder holder, int position, @NonNull Contacts model) {
            holder.username.setText(model.getUser_name());
            holder.userStatus.setText(model.getUser_status());
            Picasso.get().load(model.getUser_image())
                    .placeholder(R.drawable.default_user_img)
                    .error(R.drawable.default_user_img)
                    .resize(85,85)
                    .into(holder.profileImageView);
        }

        @NonNull
        @Override
        public FindFriendsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.users_display_layout, parent, false);
            FindFriendsViewHolder viewHolder = new FindFriendsViewHolder(view);

            return viewHolder;
        }
    };
    mRecyclerView.getAdapter(adapter);
    adapter.startListening();`

And here are my imports

    import com.firebase.ui.database.FirebaseRecyclerAdapter;
    import com.firebase.ui.database.FirebaseRecyclerOptions;
    import com.google.firebase.database.DatabaseReference;
    import com.google.firebase.database.FirebaseDatabase;

    import com.squareup.picasso.Picasso;

    import androidx.annotation.NonNull;
    import androidx.fragment.app.Fragment;
    import androidx.recyclerview.widget.LinearLayoutManager;
    import androidx.recyclerview.widget.RecyclerView;
    import de.hdodenhof.circleimageview.CircleImageView;

Did you find any solution to the problem i am also having the same issue

I'm getting error when extending FirebaseRecyclerAdapter and passing androidx.recyclerview.widget.RecyclerView.ViewHolder as type argument.
class PhotoOnlineAdapter : FirebaseRecyclerAdapter<Photo, RecyclerView.ViewHolder>(...)
Android Studio says:
Type argument is not within its bounds
Expected: android.support.v7.widget.RecyclerView.ViewHolder
Found: androidx.recyclerview.widget.RecyclerView.ViewHolder

Try setting

android.enableJetifier=true
android.useAndroidX=true

under gradle.properties. This fixed the issue for me.

I tried the same two lines of code in gradle.properties but there is no change, error is the same.
Here is my ViewHolder class

public static class FindFriendsViewHolder extends RecyclerView.ViewHolder {

        TextView username, userStatus;
        CircleImageView profileImageView;

        public FindFriendsViewHolder(View itemView) {
            super(itemView);

            username = itemView.findViewById(R.id.tv_username);
            userStatus = itemView.findViewById(R.id.tv_user_status);
            profileImageView = itemView.findViewById(R.id.users_profile_image);
        }
    }

Here is how I'm implementing it

`FirebaseRecyclerOptions<Contacts> options =
            new FirebaseRecyclerOptions.Builder<Contacts>()
                    .setQuery(dbReference, Contacts.class)
                    .build();

    FirebaseRecyclerAdapter<Contacts, FindFriendsViewHolder> adapter =
            new FirebaseRecyclerAdapter<Contacts, FindFriendsViewHolder>(options) {
        @Override
        protected void onBindViewHolder(@NonNull FindFriendsViewHolder holder, int position, @NonNull Contacts model) {
            holder.username.setText(model.getUser_name());
            holder.userStatus.setText(model.getUser_status());
            Picasso.get().load(model.getUser_image())
                    .placeholder(R.drawable.default_user_img)
                    .error(R.drawable.default_user_img)
                    .resize(85,85)
                    .into(holder.profileImageView);
        }

        @NonNull
        @Override
        public FindFriendsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.users_display_layout, parent, false);
            FindFriendsViewHolder viewHolder = new FindFriendsViewHolder(view);

            return viewHolder;
        }
    };
    mRecyclerView.getAdapter(adapter);
    adapter.startListening();`

And here are my imports

    import com.firebase.ui.database.FirebaseRecyclerAdapter;
    import com.firebase.ui.database.FirebaseRecyclerOptions;
    import com.google.firebase.database.DatabaseReference;
    import com.google.firebase.database.FirebaseDatabase;

    import com.squareup.picasso.Picasso;

    import androidx.annotation.NonNull;
    import androidx.fragment.app.Fragment;
    import androidx.recyclerview.widget.LinearLayoutManager;
    import androidx.recyclerview.widget.RecyclerView;
    import de.hdodenhof.circleimageview.CircleImageView;

Did you find any solution to the problem i am also having the same issue

I am also facing the same issue, has anybody found the solution?

I'm using AndroidX but facing some error with Firebase Recycler Adapter

I have the same problems. When will we see version that support AndroidX?

Version 6.0.0 with AndroidX support has been released.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akrmn picture akrmn  ·  4Comments

theHilikus picture theHilikus  ·  3Comments

ozican picture ozican  ·  6Comments

avyx7 picture avyx7  ·  3Comments

judeebene picture judeebene  ·  4Comments