IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM

痞子三分冷 提交于 2019-11-26 14:28:13
stegranet

I used the gradle dependency tree to solve this error for me.

Just run gradle -q app:dependencies --configuration compile and check the output for entries like this:

+--- com.mcxiaoke.viewpagerindicator:library:2.4.1
|    \--- com.android.support:support-v4:+ -> 24.0.0-beta1 (*)

As Diego Giorgini said this version is too high (>=24). So update the dependencies in build.gradle like

compile('com.mcxiaoke.viewpagerindicator:library:2.4.1') {
    exclude module: 'support-v4';
}
compile 'com.android.support:support-v4:23.4.0'

update may 27:

we just released an update (version 9.0.1) to fix the incompatibility I mentioned in my first edit.
Please update your dependencies and let us know if this is still an issue.

Thanks!


original answer May 20:

The issue you are experiencing is due to an incompatibility between
play-services / firebase sdk v9.0.0 and com.android.support:appcompat-v7 >= 24
(the version released with android-N sdk)

You should be able to fix it by targeting an earlier version of the support library. Like:

compile 'com.android.support:appcompat-v7:23.4.0'

mine worked by with the following:

app level gradle

dependencies {
 compile 'com.android.support:appcompat-v7:23.4.0'
 compile 'com.android.support:design:23.4.0'
 compile 'com.google.android.gms:play-services:9.0.0'
}

root level gradle

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

I've updated the play-services dependencies in build.gradle

dependencies {
    compile 'com.google.android.gms:play-services:9.0.0'
}

To fix the version conflict either by updating the version of the google-services plugin - I had to update the google-services in the build.gradle under the project's root folder

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

You can get the latest update of the google-services here.

Though its not avoiding the exception but its not crashing the application anymore in my side.

Update

I could avoid the crash by updating the Android studio from Beta Channel. Then update your platform/build-tools inside SDK.

synatest

Updating to the latest google play services version fixed the issue for me.

apply plugin: 'com.google.gms.google-services' at the bottom ...

dependencies {
    compile 'com.google.android.gms:play-services:9.0.0'
}

https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project

Happened to me because of facebook updating it sdk and I had

compile 'com.facebook.android:facebook-android-sdk:4.+'

replacing it to

compile 'com.facebook.android:facebook-android-sdk:4.15.0'

solved my issuee.

Ref: https://developers.facebook.com/docs/android/change-log-4.x

By including all the play services' packages

dependencies {
  compile 'com.google.android.gms:play-services:9.0.0'
}

you supress the error, but the end result is, that the GCM token retrieval is not working nor we can get an instance of the GCM. So this is not a solution in my books. If anyone has any idea what is going on please enlighten us.

EDIT:

I replaced GCM with firebase, updated android studio from 2.1 to 2.2 to fix the instant run issue with firebase analytics, updated build tools to 24-rc4 and platform tools to 24-rc3, and kept my support libs' version to 23.4.0. Everything seems to be working good now.

I had the same problem and reverting from Android Support Repository 32.0.0 to Android Support Repository 31.0.0 solved it.

For Android push notification with GCM 2016 :

1) in Android SDK-> SDK Tools check Google Play services

2) in gradle add in dependencies just one line :

compile 'com.google.android.gms:play-services-gcm:9.4.0'

(there is no specific classpath and it works for me)

3) you must create 3 class (GCMPushReceiverService, GCMRegistrationIntentService, GCMTokenRefreshListenerService)

4.1) code for GCMTokenRefreshListenerService :

package com.myapp.android;

/**
 * Created by skygirl on 02/08/2016.
 */
import android.content.Intent;
import com.google.android.gms.iid.InstanceIDListenerService;

public class GCMTokenRefreshListenerService extends InstanceIDListenerService {

    //If the token is changed registering the device again
    @Override
    public void onTokenRefresh() {
        Intent intent = new Intent(this, GCMRegistrationIntentService.class);
        startService(intent);
    }
}

4.2) Code for GCMRegistrationIntentService (change authorizedEntity with your project number) :

package com.myapp.android;

/**
 * Created by Skygirl on 02/08/2016.
 */
import android.app.IntentService;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.android.gms.iid.InstanceID;

public class GCMRegistrationIntentService extends IntentService {
    //Constants for success and errors
    public static final String REGISTRATION_SUCCESS = "RegistrationSuccess";
    public static final String REGISTRATION_ERROR = "RegistrationError";

    //Class constructor
    public GCMRegistrationIntentService() {
        super("");
    }


    @Override
    protected void onHandleIntent(Intent intent) {
        //Registering gcm to the device
        registerGCM();
    }

    private void registerGCM() {
        //Registration complete intent initially null
        Intent registrationComplete = null;

        //Register token is also null
        //we will get the token on successfull registration
        String token = null;
        try {
            //Creating an instanceid
            InstanceID instanceID = InstanceID.getInstance(this);
            String authorizedEntity = "XXXXXXXXXX"; //  your project number

            //Getting the token from the instance id
            token = instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

            //Displaying the token in the log so that we can copy it to send push notification
            //You can also extend the app by storing the token in to your server
            Log.w("GCMRegIntentService", "token:" + token);

            //on registration complete creating intent with success
            registrationComplete = new Intent(REGISTRATION_SUCCESS);

            //Putting the token to the intent
            registrationComplete.putExtra("token", token);
        } catch (Exception e) {
            //If any error occurred
            Log.w("GCMRegIntentService", "Registration error");
            registrationComplete = new Intent(REGISTRATION_ERROR);
        }

        //Sending the broadcast that registration is completed
        LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
    }
}

4.3) Code for GCMPushReceiverService :

package com.myapp.android;

/**
 * Created by Skygirl on 02/08/2016.
 */
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;

import com.google.android.gms.gcm.GcmListenerService;

//Class is extending GcmListenerService
public class GCMPushReceiverService extends GcmListenerService {

    //This method will be called on every new message received
    @Override
    public void onMessageReceived(String from, Bundle data) {
        //Getting the message from the bundle
        String message = data.getString("message");
        //Displaying a notiffication with the message
        sendNotification(message);
    }

    //This method is generating a notification and displaying the notification
    private void sendNotification(String message) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        int requestCode = 0;
        PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.your_logo)
                .setContentTitle("Your Amazing Title")
                .setContentText(message)
                .setPriority(Notification.PRIORITY_MAX)
                .setContentIntent(pendingIntent);
        noBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

        NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, noBuilder.build()); //0 = ID of notification
    }
}

5) Don't forget to change package name

6) In your mainActivity paste this code :

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Setup view
        setContentView(R.layout.main);
    mRegistrationBroadcastReceiver = new BroadcastReceiver() {

        //When the broadcast received
        //We are sending the broadcast from GCMRegistrationIntentService

        public void onReceive(Context context, Intent intent) {
            //If the broadcast has received with success
            //that means device is registered successfully
            if(intent.getAction().equals(GCMRegistrationIntentService.REGISTRATION_SUCCESS)){
                //Getting the registration token from the intent
                String token = intent.getStringExtra("token");
                //Displaying the token as toast
                Toast.makeText(getApplicationContext(), "Registration token:" + token, Toast.LENGTH_LONG).show();

                //if the intent is not with success then displaying error messages
            } else if(intent.getAction().equals(GCMRegistrationIntentService.REGISTRATION_ERROR)){
                Toast.makeText(getApplicationContext(), "GCM registration error!", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(getApplicationContext(), "Error occurred", Toast.LENGTH_LONG).show();
            }
        }
    };

    //Checking play service is available or not
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

    //if play service is not available
    if(ConnectionResult.SUCCESS != resultCode) {
        //If play service is supported but not installed
        if(GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
            //Displaying message that play service is not installed
            Toast.makeText(getApplicationContext(), "Google Play Service is not install/enabled in this device!", Toast.LENGTH_LONG).show();
            GooglePlayServicesUtil.showErrorNotification(resultCode, getApplicationContext());

            //If play service is not supported
            //Displaying an error message
        } else {
            Toast.makeText(getApplicationContext(), "This device does not support for Google Play Service!", Toast.LENGTH_LONG).show();
        }

        //If play service is available
    } else {
        //Starting intent to register device
        Intent itent = new Intent(this, GCMRegistrationIntentService.class);
        startService(itent);
    }
}

//Unregistering receiver on activity paused
@Override
public void onPause() {
    super.onPause();
    Log.w("MainActivity", "onPause");
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver);
}



    @Override
    public void onResume() {
 super.onResume();
        Log.w("MainActivity", "onResume");
        LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
                new IntentFilter(GCMRegistrationIntentService.REGISTRATION_SUCCESS));
        LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
                new IntentFilter(GCMRegistrationIntentService.REGISTRATION_ERROR));
    }

7) In your AndroidManifest.xml add following lines :

<uses-permission android:name="android.permission.INTERNET" />

8) in your console logcat copy your token and paste on this site add your project number, your token and a message. It's work fine for me :)

After a full day on this, I can confirm 100% that the Optimizely library is also clashing in some way and causing this error. To be specific, I am using Optimizely via Fabric. It is impossible to get Firebase to initialize whilst using Optimizely in this way (maybe in all ways?).

I have posted on their github about it and will contact them directly ...

https://github.com/optimizely/Optimizely-Android-SDK/issues/11

I had the same problem. I updated SDK tools to 25.1.7 rc1, then the problem was gone.

updated SDK tools to 25.1.7 and fixed this issue.

Jayground

Well, I am just beginner of using Android. I wanted to test creating users in Firebase following instructions which is provided in the Firebase website.

I added those lines in indicated places.

classpath 'com.google.gms:google-services:3.0.0'

compile 'com.google.firebase:firebase-auth:9.2.0'

apply plugin: 'com.google.gms.google-services'

But createUserWithEmailAndPassword Method kept showing failure in creating users. That's why I visited this question to figure out my problem. I read all and applied each advice. but IT kept showing failure. But When I upgrade Android Studio from 2.1.1 to 2.1.2, I could create users successfully.

But when I checked logcat, it first showed "Firebase API initialization failure" and then showed "FirebaseApp initialization successful".

07-09 18:53:37.012 13352-13352/jayground.firebasetest A/FirebaseApp: Firebase API initialization failure. How can I solve

this? java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.google.firebase.FirebaseApp.zza(Unknown Source) at com.google.firebase.FirebaseApp.initializeApp(Unknown Source) at com.google.firebase.FirebaseApp.initializeApp(Unknown Source) at com.google.firebase.FirebaseApp.zzeh(Unknown Source) at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source) at android.content.ContentProvider.attachInfo(ContentProvider.java:1591) at android.content.ContentProvider.attachInfo(ContentProvider.java:1562) at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source) at android.app.ActivityThread.installProvider(ActivityThread.java:5118) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4713) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4596) at android.app.ActivityThread.access$1600(ActivityThread.java:169) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5487) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NoSuchMethodError: com.google.android.gms.common.internal.zzaa.zzz at com.google.android.gms.measurement.internal.zzx.zzbd(Unknown Source) at com.google.android.gms.measurement.AppMeasurement.getInstance(Unknown Source) at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.google.firebase.FirebaseApp.zza(Unknown Source)  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)  at com.google.firebase.FirebaseApp.zzeh(Unknown Source)  at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)  at android.content.ContentProvider.attachInfo(ContentProvider.java:1591)  at android.content.ContentProvider.attachInfo(ContentProvider.java:1562)  at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)  at android.app.ActivityThread.installProvider(ActivityThread.java:5118)  at android.app.ActivityThread.installContentProviders(ActivityThread.java:4713)  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4596)  at android.app.ActivityThread.access$1600(ActivityThread.java:169)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:146)  at android.app.ActivityThread.main(ActivityThread.java:5487)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)  at dalvik.system.NativeStart.main(Native Method)  07-09 18:53:37.022 13352-13352/jayground.firebasetest I/FirebaseInitProvider: FirebaseApp initialization successful

Ankur

I have faced this problem, and i change my app gradle version from 1.5.0 to 2.0.0.

change classpath

com.android.tools.build:gradle:1.5.0

to

classpath 'com.android.tools.build:gradle:2.0.0

Tho Pham

Solution 1:

dependencies {
 compile `com.android.support:appcompat-v7:23.4.0`
 compile `com.android.support:support-v4:23.4.0`
 compile `com.android.support:design:23.4.0`
 compile `com.google.android.gms:play-services:9.0.0`
}

Solution 2: detect incompatible on folder .idie/libraries/ .some time you declare play-services-ads:8.4.0 concurrent with play-services-gcm:9.0.0 .you must override on build.grade incompatible libraries you detected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!