Android Troubleshooting and Help

We are developing our app using native android development. During course of our development, we come across different issues, problems and this page is meant to contain all those stumbling blocks and our resolutions.

Use actionLayout in Menu item

Many times we try to use our custom view in menu. To use this feature we generally create a custom view xml file in layout folder and embed the view in custom menu using

actionLayout

The exact syntax used

android:actionLayout="@layout/settings_layout"

However, when trying to get the view of this item,

RelativeLayout settingsLayout = (RelativeLayout) MenuItemCompat.getActionView(settingsItem);

It always return null. After spending some time, we figure out that we should use app namespace instead of android namespace. The correct declaration is

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item android:id="@+id/ac_search"
        android:title="@string/search"
        android:icon="@android:drawable/ic_menu_search"
        app:showAsAction="collapseActionView|ifRoom"
        app:actionViewClass="android.support.v7.widget.SearchView"/>

    <item android:id="@+id/ac_settings"
        android:title="@string/sync_calendar"
        app:actionLayout="@layout/settings_layout"
        app:showAsAction="always">
    </item>

</menu>

Firebase initialisation issue

( Mar 20, 2017 @ 10:43)

I was trying to develop a demo app to work with Firebase, but I got following errors

Default FirebaseApp is not initialized in this process com.example.app. Make sure to call FirebaseApp.initializeApp(Context) first

Not sure, why I got this error. I checked everything and all looks fine. Finally there needs changes in project and app gradle file to fix this error. Thanks to this stackoveflow post

In project(root level) gradle file, make following changes

buildscript {
    // ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

And in your module (app) gradle file, make following changes

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'