OneSignal / OneSignal-Android-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your native Android or Amazon app with OneSignal. https://onesignal.com
Other
604 stars 368 forks source link

Failed resolution of: Lcom/onesignal/OneSignal; #249

Closed polyak01 closed 7 years ago

polyak01 commented 7 years ago

Hi. Some time ago I integrated OneSignal to some projects and all was fine. At the new one something goes wrong.

After integrated at the start of running I have a error msg:

 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/onesignal/OneSignal;
                  at ****.onCreate(ApplicationClass.java:90)

also:

 Caused by: java.lang.ClassNotFoundException: 
Didn't find class "com.onesignal.OneSignal" on path: 
DexPathList[[zip file "/data/app/MY_PACKAGE/base.apk"],
nativeLibraryDirectories=[/data/app/nMY_PACKAGE-2/lib/arm,
 /vendor/lib, /system/lib]]

How can I resolve the problem?

OS in Application class:

OneSignal.startInit(this) 
                .setNotificationOpenedHandler(new CustomOneSignalReceiver())
                .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
                .init();

Manifest: <meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE"/>

Gradle:

apply plugin: 'com.android.application'
......
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "MY_PACKAGE"
        minSdkVersion 21
        vectorDrawables.useSupportLibrary = true
        targetSdkVersion 23
        multiDexEnabled true
        manifestPlaceholders = [onesignal_app_id               : "e*******-***-****-****-****************",
                                // Project number pulled from dashboard, local value is ignored.
                                onesignal_google_project_number: "REMOTE"]
    }
......
}
dependencies {
    compile 'com.android.support:multidex:1.0.1'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile rootProject.ext.supportDesignLibrary

    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.squareup.retrofit2:retrofit:2.2.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.2.0'
    compile 'com.squareup.retrofit2:converter-gson:2.2.0'
    compile 'com.squareup.okhttp3:okhttp:3.0.0-RC1'
    compile 'io.reactivex:rxandroid:1.2.0'
    compile 'io.reactivex:rxjava:1.1.5'
    compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
    compile 'com.jakewharton.rxbinding:rxbinding-recyclerview-v7:0.4.0'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'com.orhanobut:hawk:2.0.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'uk.co.chrisjenx:calligraphy:2.2.0'
    compile 'com.google.android.gms:play-services:10.2.0'
    compile 'com.jakewharton.timber:timber:4.5.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    compile 'com.google.android.gms:play-services-maps:10.2.0'
    compile 'com.yarolegovich:discrete-scrollview:1.2.0'

    compile 'com.onesignal:OneSignal:3.+@aar'

    compile "com.google.android.gms:play-services-location:10.2.0"

    compile 'com.google.firebase:firebase-crash:10.2.0'

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

    compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
        transitive = true;
    }

    compile('com.twitter.sdk.android:twitter:2.3.2@aar') {
        transitive = true;
    }
}
//Add the Google Services plugin (Google+ SDK)
// Do not touch !!! It is magic ;)
apply plugin: 'com.google.gms.google-services'
polyak01 commented 7 years ago

I not sure, but maybe it happens by: https://github.com/OneSignal/OneSignal-Android-SDK/blob/master/OneSignalSDK/app/build.gradle/#L21

polyak01 commented 7 years ago

I did some research. It happens only on low performance Chinese devices (Huawei, BlackView) with Android 5.0-5.1. On the Nexus 5, 5X with Android 7.0 and Samsung with Android 6.0 all is fine.

From time to time crashed showed error on different lines with liraries on Application class. From OneSignal to Twitter, Facebook, Hawk, calligraphy. But when I delete all OneSignal Dependencies and code from the project - all is fine. It is very strange.

So, I tried:

I'll be very grateful if you help to resolve this problem. If you need some testing or helping - you can to send me a msg.

polyak01 commented 7 years ago

A moment ago I tested it on Samsung Galaxy S4 with Android 5.0.1 and it also crashed. So, it is 21-22 API problem.

polyak01 commented 7 years ago

We did a lot of work with Gradle, Application class, multidex and after a lot of trying we fixed it. If in the future you need a solution for this case - you can to send me a msg. Thanks a lot for wonderful library!))

jkasten2 commented 7 years ago

@polyak01 Good to hear you got it working! It sounds like it was a problem with multidex based on the error changing about each class was not defined. What was the last thing you changed that fixed it for you?

ps-jimmy commented 7 years ago

//This worked for me. place this in your default application File and make sure you enabled multidex in your gradle file. Compile this also : compile 'com.android.support:multidex:1.0.1'

@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); }