OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
615 stars 213 forks source link

Android dependency different version when adding onesignal #160

Closed andydean565 closed 4 years ago

andydean565 commented 4 years ago

Description:

After adding the code to my flutter project to link up oneSignal I keep getting similar dependency errors when I try and run the app and not sure how to fix it.

Android dependency 'com.google.android.gms:play-services-base' has different version for the compile (11.6.2) and runtime (17.0.0) classpath. You should manually set the same version via DependencyResolution

Android dependency 'com.google.android.gms:play-services-basement' has different version for the compile (15.0.1) and runtime (17.0.0) classpath. You should manually set the same version via DependencyResolution

I'm using one signal flutter plugin version 2.1.0 and have been using the code from the one signal docs for flutter projects.

gradle app file

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.12.1, 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 plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.lotcompete"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.onesignal:OneSignal:[3.11.2, 3.99.99]'
    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'
}
royrakesh commented 4 years ago

did you try flutter clean and then flutter run ?

andydean565 commented 4 years ago

I didn't, but have just tried that and still get this error, not a strong java/android so I am unsure how to resolve or change the dependency versions.

Resolving dependencies...                                          10.8s

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'com.google.android.gms:play-services-base' has different version for the compile (15.0.1) and runtime (17.0.0) classpath. You should manually set the same version via DependencyResolution

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

have been using VScode but have opened it up in android studio to see if it could detect any issues but it did not

andydean565 commented 4 years ago

Not sure what the issue is exactly but after setting up a new project from scratch everything is working fine and I can get one signal connected.

ill leave this open in case anyone has any better fixes but mine will be to create a new project and move over my code.

andydean565 commented 4 years ago

Think I tracked down the issue when I moved all my code over to a new project same errors happened again so I started removing other flutter plugins to try and debug the issue.

after removing "flutter_barcode_scanner" the errors went away and I tried to add a different barcode scanner plugin (barcode_scan) which brought the error back

if anyone can replicate this and/or has a workaround, do let me know as I do need both for my project.

andydean565 commented 4 years ago

Migrating to android X solved this issue and there is documentation on the flutter docs on how to do this.