Onesignal-flutter-sdk: Error java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/ads/identifier/AdvertisingIdClient when I open a notification

Created on 15 Feb 2019  路  15Comments  路  Source: OneSignal/OneSignal-Flutter-SDK

Description:
I implemented this plugin and it works, but in the debug console I get this error when I open a notification:

Error getting Google Ad id:
I/OneSignal(17403): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/ads/identifier/AdvertisingIdClient;
I/OneSignal(17403):     at com.onesignal.AdvertisingIdProviderGPS.getIdentifier(AdvertisingIdProviderGPS.java:45)
I/OneSignal(17403):     at com.onesignal.OneSignal.registerUserTask(OneSignal.java:1223)
I/OneSignal(17403):     at com.onesignal.OneSignal.access$2300(OneSignal.java:80)
I/OneSignal(17403):     at com.onesignal.OneSignal$7.run(OneSignal.java:1206)
I/OneSignal(17403):     at java.lang.Thread.run(Thread.java:762)
I/OneSignal(17403): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.identifier.AdvertisingIdClient" on path: DexPathList[[zip file "/data/app/com.example-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example-2/lib/arm, /data/app/com.example-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
I/OneSignal(17403):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
I/OneSignal(17403):     at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
I/OneSignal(17403):     at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

The notification is opened correctly, but I do not know what this error means or if its serious.

Steps to Reproduce Issue:

  1. Install the OneSignal Flutter SDK using pub into your project
  2. Initialize the SDK using OneSignal.shared.init(your_app_id)
  3. Attempt to receive a push notification
Help Wanted

Most helpful comment

@SiebeVE This error is different than the NoClassDefFoundError error originally posted. In your case it looks like you called OneSignal.shared.consentGranted() before calling OneSignal.shared.init(). Make sure you all init before any other OneSignal method.

All 15 comments

I am not familiar with this error.

I'm receiving the error as well. Downgrading to for now 1.0.3 does the trick for me.

@rgomezp

I am not familiar with this error. The error mentions Google Ad id. Is this something you are using in your project?

No, thats the problem

@SiebeVE I will try to downgrade and I'll let you know. Thanks.

Nothing, I tried with 1.0.3, 1.0.4 and I get same error.

@SiebeVE @GiacomoK Can you try to reproduce this issue in a different project? Feel free to include your gradle file. It's possible this could be arising from a conflict with another plugin. Our SDK is not the root of the issue, but the fact our SDK cannot find the class is probably an indication of a larger problem with the Google Play Services library in your project (you may have messed up your dependencies)

These are my configs. I will try to reproduce it in a new project.

Thanks!

pubspec.yaml

name: myApp
description: MyApp
version: 1.0.0+1
environment:
  sdk: ">=2.0.0-dev.68.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  google_maps_flutter: any
  shared_preferences: ^0.4.3
  url_launcher: ^4.0.1
  geolocator: ^2.1.1
  onesignal: 1.0.3
  http: ^0.12.0+1
  connectivity: ^0.4.0+1
  intl: ^0.15.7
  cached_network_image: ^0.5.1
  permission_handler: 2.1.2
  device_info: ^0.4.0+1
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_launcher_icons: ^0.7.0

flutter_icons:
  android: "launcher_icon"
  ios: true
  image_path: "assets/images/icon.png"

flutter:
  uses-material-design: true
  assets:
    - assets/images/
    - assets/images/border/
  fonts:
    - family: Branding
      fonts:
       - asset: assets/fonts/leafy.woff
    - family: IconFont
      fonts:
       - asset: assets/fonts/icon-font.ttf

android/app/build.gradle

buildscript {
    repositories {
        // ...
        maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
    }
    dependencies {
        // ...
        // OneSignal-Gradle-Plugin
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.10.2, 0.99.99]'
    }
}

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "***"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 6
        versionName "0.4.0-beta"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            useProguard false

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Updating my other dependecies and graddle no longer produces the error.
Currently working on master because of #61.
Other then that, it works fine!

@GiacomoK I think you may have forgotten the step on adding the OneSignal-Gradle-Plugin to the top of your android/app/build.gradle.

buildscript {
    repositories {
        // ...
        maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
    }
    dependencies {
        // ...
        // OneSignal-Gradle-Plugin
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.10.2, 0.99.99]'
    }
}

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

It is possible this file got rebuild so please double check it.

@SiebeVE We released update 1.10 so you can now switch back to a normal setup.

Unfortunately it is still throwing the same exception (didn't test it properly...)

Maybe it is connected to an error thrown before:

W/OneSignal(18501): OneSignal.appContext null, could not read OneSignal from getSharedPreferences.
W/OneSignal(18501): java.lang.Throwable
W/OneSignal(18501):     at com.onesignal.OneSignalPrefs.getSharedPrefsByName(OneSignalPrefs.java:232)
W/OneSignal(18501):     at com.onesignal.OneSignalPrefs.get(OneSignalPrefs.java:210)
W/OneSignal(18501):     at com.onesignal.OneSignalPrefs.getBool(OneSignalPrefs.java:186)
W/OneSignal(18501):     at com.onesignal.OneSignal.getSavedUserConsentStatus(OneSignal.java:2063)
W/OneSignal(18501):     at com.onesignal.OneSignal.userProvidedPrivacyConsent(OneSignal.java:906)
W/OneSignal(18501):     at com.onesignal.OneSignal.provideUserConsent(OneSignal.java:910)
W/OneSignal(18501):     at com.onesignal.flutter.OneSignalPlugin.consentGranted(OneSignalPlugin.java:137)
W/OneSignal(18501):     at com.onesignal.flutter.OneSignalPlugin.onMethodCall(OneSignalPlugin.java:68)
W/OneSignal(18501):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:201)
W/OneSignal(18501):     at io.flutter.view.FlutterNativeView$PlatformMessageHandlerImpl.handleMessageFromDart(FlutterNativeView.java:188)
W/OneSignal(18501):     at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:202)
W/OneSignal(18501):     at android.os.MessageQueue.nativePollOnce(Native Method)
W/OneSignal(18501):     at android.os.MessageQueue.next(MessageQueue.java:323)
W/OneSignal(18501):     at android.os.Looper.loop(Looper.java:135)
W/OneSignal(18501):     at android.app.ActivityThread.main(ActivityThread.java:5539)
W/OneSignal(18501):     at java.lang.reflect.Method.invoke(Native Method)
W/OneSignal(18501):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/OneSignal(18501):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
V/OneSignal(18501): Initializing the OneSignal Flutter SDK (0.1.0)

@SiebeVE This error is different than the NoClassDefFoundError error originally posted. In your case it looks like you called OneSignal.shared.consentGranted() before calling OneSignal.shared.init(). Make sure you all init before any other OneSignal method.

Thanks @jkasten2 That was indeed the problem for the shared storage.
I'm still receiving the java.lang.NoClassDefFoundError, but only when I set OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none);. Other then the author, I'm receiving the error not when I receive a notification, but rather after the first initialisation.

Hello,
Sorry for the delay. Are you still seeing the issue @SiebeVE ?

Thanks for the follow up!
Unfortunately, last time I tried, I still received the error.
But due to the problem with building on iOS, I have migrated to FCM.

Ok! I'm going to close the issue for now. Feel free to @ me if you would like me to reopen

i have solved it,
1.add com.google.android.gms:play-services-ads in android/app/build.gradle
dependencies {
...
implementation 'com.google.android.gms:play-services-ads:7.5.0'
}
2.add multidex in android/app/build.gradle
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
}

defaultConfig {
...
multiDexEnabled true
...
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rgbinnovation picture rgbinnovation  路  7Comments

Galahand picture Galahand  路  3Comments

royibernthal picture royibernthal  路  3Comments

Bwolfs2 picture Bwolfs2  路  5Comments

bhoominn picture bhoominn  路  3Comments