Onesignal-flutter-sdk: Build fails with error GeneratedPluginRegistrant.java:19: error: cannot access InAppMessageClickHandler

Created on 16 Aug 2019  路  18Comments  路  Source: OneSignal/OneSignal-Flutter-SDK

Hello,

I have been trying to build the project on Android but I can't manage to make it work with any version that I've tried. This is the error I keep receiving:

Initializing gradle... 7.0s
Resolving dependencies... 4.3s
/Users/xxx/AndroidProject/sline/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java:19: error: cannot access InAppMessageClickHandler
OneSignalPlugin.registerWith(registry.registrarFor("com.onesignal.flutter.OneSignalPlugin"));
^
class file for com.onesignal.OneSignal$InAppMessageClickHandler not found
1 error

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:compileDebugJavaWithJavac'.

    Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 31s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 32.6s
Gradle task assembleDebug failed with exit code 1

Help Wanted Need More Information

Most helpful comment

experienced the same error, what worked was simply updating to the latest version (3.12.7 as of now):

dependencies {
   // ...
    implementation 'com.onesignal:OneSignal:3.12.7'
   // ...
}

All 18 comments

@SlineApp It seems like native OneSignal-Android-SDK is behind the OneSignal Flutter SDK wrapper Java code in your project or in the pub-cache.

Can you update to 2.0.2 of this plugin?

If that does not work can you check the following file?
~/.pub-cache/hosted/pub.dartlang.org/onesignal_flutter-2.0.2/android/build.gradle
It should have the following version.

dependencies {
    compile('com.onesignal:OneSignal:3.11.2')
}

I've tried updating to 2.0.2. Still the same error. Also, checked the file and it has the dependencies

@SlineApp Can you double check you don't still have the old 1.x onesignal SDK under dependencies: in your pubspec.yaml? It sounds like you may have two copies of OneSignal in your project.

Next I recommend trying to remove and re-add the OneSignal SDK to your project.

  1. Remove onesignal_flutter from your pubspec.yaml
  2. Run flutter packages get
  3. Add back onesignal_flutter.
  4. Run flutter packages get again.

If that does not help open GeneratedPluginRegistrant.java in Android Studio from your project and control + click on OneSignalPlugin. Take note of the file location at the top in Android Studio, it might be point to an old copy.

@SlineApp It seems that your issues are related specifically to your project where parts of your project are stuck on an old version of OneSignal. I recommend trying our example project or a new project to see if you still have the issue. If so then it could be something with your pub-cache and you might need to clear it.
Lastly make sure you have the latest version of Flutter installed.

I tried removing the reference and re-add it several times. I've tried clearing the pub-cache and still it doesn't work, updated flutter to the last version as well and created 2 new projects and still the same error.

Howdy,
We have identified the issue and will be resolving in the coming weeks. Please ignore the errors for now while we implement the fix

SlineApp,
Try placing the line of code at the end of the file. This worked for me.

// android/app/build.gradle
...
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    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'
}

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin' // <<< put at the end of the file 

I am also experienced this issue, I have following the installation documentation, but when I start the application I have gradle build failed. It said the failure because AndroidX incompatibility.

This is my ./andorid/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]'
    }
}

/// ...

dependencies {
    // ...
    implementation 'com.onesignal:OneSignal:[3.11.2, 3.99.99]'
}

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

And this is the errors:

D8: Program type already present: android.support.v4.os.ResultReceiver$1

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: ...

Is there any solution please?

Sorry, I have solved my problem by adding resolution strategy, this is my ./android/build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
    configurations {
        all {
            resolutionStrategy {
                force "androidx.arch.core:core-runtime:2.0.0"
                force "androidx.slidingpanelayout:slidingpanelayout:1.0.0"
                force "androidx.documentfile:documentfile:1.0.0"
                force "androidx.fragment:fragment:1.0.0"
                force "androidx.core:core:1.0.0"
            }
        }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

@rgomezp Still Waiting for official solution

Hello,
We are working to release this as soon as possible. Thanks for your patience

Hi Rodrigo. Any update in this? Our whole build for android is broken for weeks now because of this :/ @rgomezp

We're considering switching all of our push notifications to Firebase because of this. It's been almost 2 months since the issue has been open and it has been an absolute show stopper....

This github thread has different Android issues mixed in;

Missing InAppMessageClickHandler

  • @SlineApp original issue

    • class file for com.onesignal.OneSignal$InAppMessageClickHandler not found ':app:compileDebugJavaWithJavac'.

    • This seems to be related to an old version of OneSignal-Android-SDK being used with a newer version of the flutter wrapper.



      • We are not able to reproduce this specific issue and have reviewed our code to ensure their isn't an old reference. Closing this issue due to this, however we can reopen if there is a reproducible case.



Duplicated android.support classes

  • Build issue related to duplicated android.support.* java classes D8: Program type already present: android.support.v4.os.ResultReceiver$1

    • This is due to Jetifier not being enabled.

    • Please follow Migrating to AndroidX guide to upgrade.

    • If you continue to see an issue please open a new issue as this isn't related to the first issue. Provide exact details on reproducing the issue from a new project.

But what happened to the official solution @rgomezp was working on?

I was able to duplicate this (class file for com.onesignal.OneSignal$InAppMessageClickHandler not found ':app:compileDebugJavaWithJavac'.) issue - if you do not have the following line in the dependencies section of ./android/app.build.gradle:
implementation 'com.onesignal:OneSignal:[3.11.2, 3.99.99]'
I get this error. Adding this line seems to fix it. This possibly appears to be a difference from 1.x to 2.x OneSignal?

SlineApp,
Try placing the line of code at the end of the file. This worked for me.

// android/app/build.gradle
...
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    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'
}

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin' // <<< put at the end of the file 

this, work for me. Thanks

experienced the same error, what worked was simply updating to the latest version (3.12.7 as of now):

dependencies {
   // ...
    implementation 'com.onesignal:OneSignal:3.12.7'
   // ...
}

experienced the same error, what worked was simply updating to the latest version (3.12.7 as of now):

dependencies {
   // ...
    implementation 'com.onesignal:OneSignal:3.12.7'
   // ...
}

can you tell me where to put this exactly? I'm confused.
Okay I figured that out, its in dependencies section at the bottom of the file and not in the onesignal one.

Was this page helpful?
0 / 5 - 0 ratings