Android studio updated and code too large now

There is no need to pass the remoteMessageMap to another class. The source of the problem is the limitation in the java method size. Here is a piece of the official documentation of oracle which is related to this problem:

The value of the code_length item gives the number of bytes in the code array for this method.
The value of code_length must be greater than zero (as the code array must not be empty) and less than 65536.

The point is that your onMessageReceived method is too long, which is bigger than 64KB of compiled code. It is weird why it was compiled fine in previous versions of Android Studio 🙂

Anyway, the solution is to break the method into smaller fragments. My suggestion is fragmentation by some message types. For example:

private static final String COMMAND_1 = "COMMAND_1";
private static final String COMMAND_2 = "COMMAND_2";

public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.e(TAG, "remoteMessage.getData() = " + remoteMessage.getData());

    Map remoteMessageMap = remoteMessage.getData();

    String message = (String) remoteMessageMap.get("message");
    String type = extrated_from_received_message;

    switch (type) {
        case COMMAND_1:
        case COMMAND_2:

        // more commands ...

            // ...

private void handleCommand1(Map remoteMessageMap){
    // do whatever related to command 1

private void handleCommand2(Map remoteMessageMap){
    // do whatever related to command 2

In this way, the method size would be optimized and the performance of calling it will be far improved.

Leave a Comment