3
votes

Hello I hope someone can help me here.

I´m working on an application which uses UrbanAirship to receive PushNotifications.

My Problem is that, since this morning, my app crashes when initializing UrbanAirship with takeOff.

I´m using Android Studio v2.1.1(stable) and updated my Build and Platform-Tools to use the most current version(s). After the crash occurred I tested if it is caused by the new Tools by using an older Version of these Tools and different Android Studio versions (2.0, 1.3 and 1.5). So I´m sure that should not be the Problem.

Here is the Code I´m using and the Stack Trace from my LogCat:

UAirship.takeOff(this, Config.getOptions(), mAirshipReadyCallback);

getOptions returns the following:

public static AirshipConfigOptions getOptions() {
    return new AirshipConfigOptions.Builder()
        .setDevelopmentAppKey("Key")
        .setDevelopmentAppSecret("Secret")
        .setProductionAppKey("Key")
        .setProductionAppSecret("Secret")
        .setInProduction(!BuildConfig.DEBUG)
        .setGcmSender("Sender")
        .setProductionLogLevel(3).build();
}

And my Callback is the following:

private UAirship.OnReadyCallback mAirshipReadyCallback = new UAirship.OnReadyCallback() {
        @Override
        public void onAirshipReady(UAirship uAirship) {
            DefaultNotificationFactory notificationFactory;
            notificationFactory = new DefaultNotificationFactory(getApplicationContext());

            notificationFactory.setSmallIconId(R.drawable.ic_push);
            notificationFactory.setLargeIcon(R.drawable.ic_launcher);
            try {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    notificationFactory.setColor(getColor(R.color.main_list_item_text_enabled));
                } else {
                    notificationFactory.setColor(getResources().getColor(R.color.main_list_item_text_enabled));
                }
            } catch (Resources.NotFoundException ex) {
                Timber.e(ex.getCause(), ex.getMessage());
                notificationFactory.setColor(Color.parseColor("0e457e"));
            }

            // Enable user notifications
            Timber.i("Enable Airship!");
            Timber.i("UAirship ChannelId: " + UAirship.shared().getPushManager().getChannelId());
            uAirship.getPushManager().setNotificationFactory(notificationFactory);
            uAirship.getPushManager().setUserNotificationsEnabled(true);
        }
    };

Finally the StackTrace:

java.lang.IncompatibleClassChangeError: The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)' was expected to be of type virtual but instead was found to be of type direct (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar)
at com.google.android.gms.iid.zzd.zzeb(Unknown Source)
at com.google.android.gms.iid.zzd.<init>(Unknown Source)
at com.google.android.gms.iid.zzd.<init>(Unknown Source)
at com.google.android.gms.iid.InstanceID.zza(Unknown Source)
at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source)
at com.urbanairship.push.GcmRegistrar.register(GcmRegistrar.java:62)
at com.urbanairship.push.ChannelServiceDelegate.onUpdatePushRegistration(ChannelServiceDelegate.java:174)
at com.urbanairship.push.ChannelServiceDelegate.onHandleIntent(ChannelServiceDelegate.java:110)
at com.urbanairship.BaseIntentService.onHandleIntent(BaseIntentService.java:103)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)

Yesterday everything worked fine and I did not update any libraries I´m using.

Thank you in advance, greetings :)

Edit

Here are my gradle dependencies:

dependencies {

compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
repositories {
    mavenCentral()

    flatDir {
        dirs 'libs'
    }

    maven { url 'https://repo.commonsware.com.s3.amazonaws.com' }
    maven { url 'https://urbanairship.bintray.com/android' }
    maven { url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2' }
}

    compile('com.urbanairship.android:urbanairship-sdk:7.1.3') {
    exclude group: 'com.google.android.support', module: 'support-v4'
    exclude group: 'com.google.android.gms', module: 'play-services-gcm'
        transitive = true
}

compile('de.keyboardsurfer.android.widget:crouton:1.8.5@aar') {
    exclude group: 'com.google.android.support', module: 'support-v4'
    transitive = true
}

compile('com.facebook.android:facebook-android-sdk:4.8.1') {
    exclude group: 'com.google.android.support', module: 'support-v4'
}
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.squareup.okhttp:logging-interceptor:2.6.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.jakewharton:butterknife:5.1.1'
compile 'com.jakewharton.timber:timber:4.1.1'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
    transitive = true;
}

compile 'org.xwalk:xwalk_core_library:16.45.421.19'
compile 'com.amplitude:android-sdk:2.5.0'

}

Edit 2

I also tried to use the UrbanAirship-SDK Version 6.4.1 without excluding google.gms and the android support libraries, without any effect.

Furthermore I updated every possible dependency inside my gradle use the newest version (just the changed):

compile'com.urbanairship.android:urbanairship-sdk:7.1.3'
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'

still no change

3
Can you please add your Gradle file. I think you are using old play service library in the dependency section under build.gradle.Nithinjith
@Nithinjith added the gradle dependenciesKoerfer_P
@Nithinjith I updated all dependencies to match the newest versions. So the play service libraries are now v 9.0.0 but the Exception is still thrownKoerfer_P
You should avoid posting your app credentials and sender Id. Please edit your question and remove those.ralepinski
@ralepinski You´re absolutely right. Thank you :)Koerfer_P

3 Answers

24
votes

As @ralepinski pointed out. The sample app of UA was working like expected. So I dug deeper into the usage of libraries and gradle and found out, that this Issue was caused by the internal usage of

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

Some of the used plugins use these libraries as well and the conflict was in the usage of different versions of these libraries. I solved this issue by using the force command inside the gradle (see below):

configurations.all {
    resolutionStrategy {
        force 'com.android.support:design:23.4.0'
        force 'com.android.support:support-v4:23.4.0'
        force 'com.android.support:appcompat-v7:23.4.0'
    }
}

I´d like to thank you all for your help and I upvotet @ralepinskis answer which gave the hint to look at the sample project. I do not have enough reputation now but when I have the upvote should be added automatically.

:)

1
votes

Looks like a breaking change in the support library where an interface is now an abstract class. Make sure 23.3 of the support library and app compat and 8.4 Google place services. Clean and rebuild. You can check the build directory to verify versions. Sometimes other dependencies will pull in newer ones.

0
votes
This what your gradle should look like and Hope you have added permission in manifest for the same:

repositories {
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'http://dl.bintray.com/urbanairship/android' }
}

dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    compile 'com.google.android.gms:play-services-analytics:8.4.0'
    compile 'com.google.android.gms:play-services-identity:8.4.0'
    compile 'com.google.android.gms:play-services-base:8.4.0'
    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
    compile 'com.google.android.gms:play-services-location:8.4.0'
    compile 'com.google.android.gms:play-services-wearable:8.4.0'
    compile 'com.google.android.gms:play-services-ads:8.4.0'
    compile 'com.google.android.gms:play-services-plus:8.4.0'
    compile project(':PlustxtAsSDK')
    compile 'com.urbanairship.android:urbanairship-sdk:6.4.1'
}