OneSignal / OneSignal-Gradle-Plugin

Use with OneSignal-Android-SDK to help integrate it into your Android Studio or Gradle project. https://onesignal.com
Other
64 stars 17 forks source link

(Flutter) App crashes on first launch after install #107

Closed Galahand closed 4 years ago

Galahand commented 5 years ago

Description

I have a flutter project and i'm using the OneSignal SDK, i read that adding 'com.onesignal.androidsdk.onesignal-gradle-plugin' would fix the problem, but the problem is still there for me.

Project Setup

build.gradle

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://plugins.gradle.org/m2/' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.3.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.0"
            }
        }
    }
}

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

app/build.gradle

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.5'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
    maven { url 'https://maven.google.com' }
}

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.")
}

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

def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.rojelui.milagritoapp"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 44
        versionName "1.4.4"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release

            minifyEnabled true
            useProguard true

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

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation "com.google.android.gms:play-services-location:15.0.1"
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.onesignal:OneSignal:3.11.4'
}
apply plugin: 'com.google.gms.google-services'

Full Error

BUILD ERROR
RUNTIME ERROR if not a compiler error
java.lang.IllegalAccessError: Class com.google.firebase.iid.zzb extended by class com.google.firebase.messaging.FirebaseMessagingService is inaccessible (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in base.apk)
        at java.lang.VMClassLoader.findLoadedClass(Native Method)
        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:103)
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:3737)
        at android.app.ActivityThread.access$1400(ActivityThread.java:236)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7037)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

Dependency Tree

Run ./gradlew app:dependencies

releaseRuntimeClasspath - Resolved configuration for runtime for variant: release
+--- com.google.android.gms:play-services-location:15.0.1 -> 16.0.0
|    +--- com.google.android.gms:play-services-base:16.0.1
|    |    +--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0
|    |    |    \--- com.android.support:support-v4:26.1.0 -> 27.1.0
|    |    |         +--- com.android.support:support-compat:27.1.0
|    |    |         |    +--- com.android.support:support-annotations:27.1.0
|    |    |         |    \--- android.arch.lifecycle:runtime:1.1.0
|    |    |         |         +--- android.arch.lifecycle:common:1.1.0
|    |    |         |         \--- android.arch.core:common:1.1.0
|    |    |         +--- com.android.support:support-media-compat:27.1.0
|    |    |         |    +--- com.android.support:support-annotations:27.1.0
|    |    |         |    \--- com.android.support:support-compat:27.1.0 (*)
|    |    |         +--- com.android.support:support-core-utils:27.1.0
|    |    |         |    +--- com.android.support:support-annotations:27.1.0
|    |    |         |    \--- com.android.support:support-compat:27.1.0 (*)
|    |    |         +--- com.android.support:support-core-ui:27.1.0
|    |    |         |    +--- com.android.support:support-annotations:27.1.0
|    |    |         |    +--- com.android.support:support-compat:27.1.0 (*)
|    |    |         |    \--- com.android.support:support-core-utils:27.1.0 (*)
|    |    |         \--- com.android.support:support-fragment:27.1.0
|    |    |              +--- com.android.support:support-compat:27.1.0 (*)
|    |    |              +--- com.android.support:support-core-ui:27.1.0 (*)
|    |    |              +--- com.android.support:support-core-utils:27.1.0 (*)
|    |    |              +--- com.android.support:support-annotations:27.1.0
|    |    |              +--- android.arch.lifecycle:livedata-core:1.1.0
|    |    |              |    +--- android.arch.lifecycle:common:1.1.0
|    |    |              |    +--- android.arch.core:common:1.1.0
|    |    |              |    \--- android.arch.core:runtime:1.1.0
|    |    |              |         \--- android.arch.core:common:1.1.0
|    |    |              \--- android.arch.lifecycle:viewmodel:1.1.0
|    |    \--- com.google.android.gms:play-services-tasks:16.0.1
|    |         \--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    +--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    +--- com.google.android.gms:play-services-places-placereport:16.0.0
|    |    \--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    \--- com.google.android.gms:play-services-tasks:16.0.1 (*)
+--- com.android.support:multidex:1.0.3
+--- com.onesignal:OneSignal:3.11.4
|    +--- com.google.firebase:firebase-messaging:[10.2.1, 12.1.0) -> 15.0.2
|    |    +--- com.google.android.gms:play-services-basement:[15.0.1,16.0.0) -> 16.2.0 (*)
|    |    +--- com.google.android.gms:play-services-tasks:[15.0.1,16.0.0) -> 16.0.1 (*)
|    |    +--- com.google.firebase:firebase-common:[15.0.1,16.0.0) -> 17.0.0
|    |    |    +--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    |    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    |    |    \--- com.google.auto.value:auto-value-annotations:1.6.3
|    |    +--- com.google.firebase:firebase-core:[15.0.2,16.0.0) -> 16.0.9
|    |    |    \--- com.google.firebase:firebase-analytics:16.5.0
|    |    |         +--- com.google.android.gms:play-services-measurement:16.5.0
|    |    |         |    +--- com.google.android.gms:play-services-basement:16.2.0 (*)
|    |    |         |    +--- com.google.android.gms:play-services-measurement-base:[16.5.0] -> 16.5.0
|    |    |         |    |    \--- com.google.android.gms:play-services-basement:16.2.0 (*)
|    |    |         |    +--- com.google.android.gms:play-services-measurement-impl:[16.5.0] -> 16.5.0
|    |    |         |    |    +--- com.google.android.gms:play-services-ads-identifier:16.0.0
|    |    |         |    |    |    \--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    |         |    |    +--- com.google.android.gms:play-services-basement:16.2.0 (*)
|    |    |         |    |    +--- com.google.android.gms:play-services-measurement-base:[16.5.0] -> 16.5.0 (*)
|    |    |         |    |    \--- com.google.android.gms:play-services-stats:16.0.1
|    |    |         |    |         \--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    |         |    \--- com.google.android.gms:play-services-stats:16.0.1 (*)
|    |    |         +--- com.google.android.gms:play-services-measurement-api:16.5.0
|    |    |         |    +--- com.google.android.gms:play-services-basement:16.2.0 (*)
|    |    |         |    +--- com.google.android.gms:play-services-measurement-base:[16.5.0] -> 16.5.0 (*)
|    |    |         |    +--- com.google.android.gms:play-services-measurement-impl:[16.5.0] -> 16.5.0 (*)
|    |    |         |    +--- com.google.android.gms:play-services-measurement-sdk-api:[16.5.0] -> 16.5.0
|    |    |         |    |    +--- com.google.android.gms:play-services-basement:16.2.0 (*)
|    |    |         |    |    \--- com.google.android.gms:play-services-measurement-base:[16.5.0] -> 16.5.0 (*)
|    |    |         |    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    |    |         |    +--- com.google.firebase:firebase-common:16.0.3 -> 17.0.0 (*)
|    |    |         |    +--- com.google.firebase:firebase-iid:17.1.2 -> 18.0.0
|    |    |         |    |    +--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    |         |    |    +--- com.google.android.gms:play-services-stats:16.0.1 (*)
|    |    |         |    |    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    |    |         |    |    +--- com.google.firebase:firebase-common:17.0.0 (*)
|    |    |         |    |    \--- com.google.firebase:firebase-iid-interop:16.0.1
|    |    |         |    |         +--- com.google.android.gms:play-services-base:16.0.1 (*)
|    |    |         |    |         \--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    |         |    \--- com.google.firebase:firebase-measurement-connector:17.0.1
|    |    |         |         \--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    |         \--- com.google.android.gms:play-services-measurement-sdk:16.5.0
|    |    |              +--- com.google.android.gms:play-services-basement:16.2.0 (*)
|    |    |              +--- com.google.android.gms:play-services-measurement-base:[16.5.0] -> 16.5.0 (*)
|    |    |              +--- com.google.android.gms:play-services-measurement-impl:[16.5.0] -> 16.5.0 (*)
|    |    |              \--- com.google.android.gms:play-services-measurement-sdk-api:[16.5.0] -> 16.5.0 (*)
|    |    +--- com.google.firebase:firebase-iid:[15.1.0] -> 18.0.0 (*)
|    |    \--- com.google.firebase:firebase-measurement-connector:[15.0.0,16.0.0) -> 17.0.1 (*)
|    +--- com.android.support:support-v4:[26.0.0, 27.2.0) -> 27.1.0 (*)
|    +--- com.android.support:customtabs:[26.0.0, 27.2.0) -> 27.1.0
|    |    +--- com.android.support:support-compat:27.1.0 (*)
|    |    +--- com.android.support:support-annotations:27.1.0
|    |    +--- com.android.support:support-core-ui:27.1.0 (*)
|    |    \--- com.android.support:appcompat-v7:27.1.0
|    |         +--- com.android.support:support-annotations:27.1.0
|    |         +--- com.android.support:support-core-utils:27.1.0 (*)
|    |         +--- com.android.support:support-fragment:27.1.0 (*)
|    |         +--- com.android.support:support-vector-drawable:27.1.0
|    |         |    +--- com.android.support:support-annotations:27.1.0
|    |         |    \--- com.android.support:support-compat:27.1.0 (*)
|    |         \--- com.android.support:animated-vector-drawable:27.1.0
|    |              +--- com.android.support:support-vector-drawable:27.1.0 (*)
|    |              \--- com.android.support:support-core-ui:27.1.0 (*)
|    +--- com.google.android.gms:play-services-location:[10.2.1, 12.1.0) -> 16.0.0 (*)
|    +--- com.android.support:cardview-v7:[26.0.0, 27.2.0) -> 27.1.0
|    |    \--- com.android.support:support-annotations:27.1.0
|    \--- com.google.android.gms:play-services-base:[10.2.1, 12.1.0) -> 16.0.1 (*)
+--- project :firebase_storage
|    +--- com.google.firebase:firebase-storage:17.0.0
|    |    +--- com.google.android.gms:play-services-base:16.0.1 (*)
|    |    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    |    +--- com.google.firebase:firebase-auth-interop:17.0.0
|    |    |    +--- com.google.android.gms:play-services-base:16.0.1 (*)
|    |    |    +--- com.google.android.gms:play-services-basement:16.1.0 -> 16.2.0 (*)
|    |    |    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    |    |    \--- com.google.firebase:firebase-common:17.0.0 (*)
|    |    \--- com.google.firebase:firebase-common:17.0.0 (*)
|    +--- com.google.firebase:firebase-common:16.1.0 -> 17.0.0 (*)
|    \--- androidx.annotation:annotation:1.0.0
+--- project :sqflite
+--- project :package_info
+--- project :flutter_facebook_login
|    \--- com.facebook.android:facebook-login:4.39.0
|         +--- com.facebook.android:facebook-core:4.39.0
|         |    +--- com.parse.bolts:bolts-android:1.4.0
|         |    |    +--- com.parse.bolts:bolts-tasks:1.4.0
|         |    |    \--- com.parse.bolts:bolts-applinks:1.4.0
|         |    |         \--- com.parse.bolts:bolts-tasks:1.4.0
|         |    +--- com.android.support:support-annotations:27.0.2 -> 27.1.0
|         |    \--- com.android.support:support-core-utils:27.0.2 -> 27.1.0 (*)
|         +--- com.facebook.android:facebook-common:4.39.0
|         |    +--- com.facebook.android:facebook-core:4.39.0 (*)
|         |    +--- com.android.support:support-v4:27.0.2 -> 27.1.0 (*)
|         |    +--- com.android.support:appcompat-v7:27.0.2 -> 27.1.0 (*)
|         |    +--- com.android.support:cardview-v7:27.0.2 -> 27.1.0 (*)
|         |    +--- com.android.support:customtabs:27.0.2 -> 27.1.0 (*)
|         |    \--- com.google.zxing:core:3.3.0
|         \--- com.android.support:appcompat-v7:27.0.2 -> 27.1.0 (*)
+--- project :cloud_functions
|    +--- com.google.firebase:firebase-functions:17.0.0
|    |    +--- com.google.android.gms:play-services-base:16.0.1 (*)
|    |    +--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    |    +--- com.google.firebase:firebase-auth-interop:17.0.0 (*)
|    |    +--- com.google.firebase:firebase-common:17.0.0 (*)
|    |    +--- com.google.firebase:firebase-iid:18.0.0 (*)
|    |    +--- com.google.firebase:firebase-iid-interop:16.0.1 (*)
|    |    \--- com.squareup.okhttp3:okhttp:3.12.1
|    |         \--- com.squareup.okio:okio:1.15.0
|    +--- com.google.firebase:firebase-common:16.1.0 -> 17.0.0 (*)
|    \--- androidx.annotation:annotation:1.0.0
+--- project :onesignal_flutter
|    \--- com.onesignal:OneSignal:3.11.2 -> 3.11.4 (*)
+--- project :url_launcher
+--- project :path_provider
+--- project :cloud_firestore
|    +--- com.google.firebase:firebase-firestore:19.0.0
|    |    +--- com.google.android.gms:play-services-base:16.0.1 (*)
|    |    +--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    |    +--- com.google.firebase:firebase-auth-interop:17.0.0 (*)
|    |    +--- com.google.firebase:firebase-common:17.0.0 (*)
|    |    +--- com.google.firebase:firebase-database-collection:16.0.1
|    |    +--- com.google.firebase:protolite-well-known-types:16.0.1
|    |    |    \--- com.google.protobuf:protobuf-lite:3.0.1
|    |    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|    |    +--- com.squareup.okhttp:okhttp:2.7.5
|    |    |    \--- com.squareup.okio:okio:1.6.0 -> 1.15.0
|    |    +--- io.grpc:grpc-android:1.16.1
|    |    |    \--- io.grpc:grpc-core:[1.16.1] -> 1.16.1
|    |    |         +--- io.grpc:grpc-context:1.16.1
|    |    |         +--- com.google.code.gson:gson:2.7 -> 2.8.5
|    |    |         +--- com.google.errorprone:error_prone_annotations:2.2.0
|    |    |         +--- com.google.code.findbugs:jsr305:3.0.2
|    |    |         +--- org.codehaus.mojo:animal-sniffer-annotations:1.17
|    |    |         +--- com.google.guava:guava:26.0-android
|    |    |         |    +--- org.checkerframework:checker-compat-qual:2.5.2
|    |    |         |    \--- com.google.j2objc:j2objc-annotations:1.1
|    |    |         +--- io.opencensus:opencensus-api:0.12.3
|    |    |         |    \--- com.google.errorprone:error_prone_annotations:2.2.0
|    |    |         \--- io.opencensus:opencensus-contrib-grpc-metrics:0.12.3
|    |    |              +--- com.google.errorprone:error_prone_annotations:2.2.0
|    |    |              \--- io.opencensus:opencensus-api:0.12.3 (*)
|    |    +--- io.grpc:grpc-okhttp:1.16.1
|    |    |    +--- io.grpc:grpc-core:[1.16.1] -> 1.16.1 (*)
|    |    |    +--- com.squareup.okhttp:okhttp:2.5.0 -> 2.7.5 (*)
|    |    |    \--- com.squareup.okio:okio:1.13.0 -> 1.15.0
|    |    +--- io.grpc:grpc-protobuf-lite:1.16.1
|    |    |    +--- io.grpc:grpc-core:1.16.1 (*)
|    |    |    +--- com.google.protobuf:protobuf-lite:3.0.1
|    |    |    \--- com.google.guava:guava:26.0-android (*)
|    |    \--- io.grpc:grpc-stub:1.16.1
|    |         \--- io.grpc:grpc-core:1.16.1 (*)
|    +--- com.google.firebase:firebase-common:16.1.0 -> 17.0.0 (*)
|    \--- androidx.annotation:annotation:1.0.0
+--- project :shared_preferences
+--- project :location
|    \--- com.google.android.gms:play-services-location:16.+ -> 16.0.0 (*)
+--- project :firebase_core
|    +--- com.google.firebase:firebase-core:16.0.9 (*)
|    \--- com.google.firebase:firebase-common:16.1.0 -> 17.0.0 (*)
+--- project :firebase_auth
|    +--- com.google.firebase:firebase-auth:17.0.0
|    |    +--- com.google.android.gms:play-services-base:16.0.1 (*)
|    |    +--- com.google.android.gms:play-services-basement:16.1.0 -> 16.2.0 (*)
|    |    +--- com.google.android.gms:play-services-flags:16.0.1
|    |    |    +--- com.google.android.gms:play-services-base:16.0.1 (*)
|    |    |    \--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    |    +--- com.google.firebase:firebase-auth-interop:17.0.0 (*)
|    |    \--- com.google.firebase:firebase-common:17.0.0 (*)
|    +--- com.google.code.gson:gson:2.8.5
|    +--- androidx.annotation:annotation:1.0.0
|    \--- com.google.firebase:firebase-common:16.1.0 -> 17.0.0 (*)
\--- com.android.support:multidex:1.0.2 -> 1.0.3
jkasten2 commented 5 years ago

@Galahand Can you try removing this section in your root build.gradle?

subprojects {
    project.evaluationDependsOn(':app')
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.0"
            }
        }
    }
}

The project.evaluationDependsOn(':app') line is most likely changing the order for resolution. Also the resolutionStrategy.eachDependency could also be affecting the order. The com.android.support version overriding you have to 27.1.0 can create issues with AndroidX so I also recommend removing it for this reason. This plugin also takes care of the alignment it is trying to do anyway.

The runtime crash is due to firebase-iid being updated to a version newer than firebase-messaging will work with as seen from your log.

+--- com.onesignal:OneSignal:3.11.4
|    +--- com.google.firebase:firebase-messaging:[10.2.1, 12.1.0) -> 15.0.2
...
|    |    |         |    +--- com.google.firebase:firebase-iid:17.1.2 -> 18.0.0

This plugin should take care of this however the subprojects { } block you have above is probably changing the order of resolution.

Since there is a lot of variables here can you attach an example flutter project reproducing the issue?

As a quick work around you can try updating firebase-messaging to match firebase-iid which is 18.0.0. Due note that when OneSignal or other plugins are updated you will most likely have to bump the version as you may see a crash again. To avoid this sending us a project reproducing the issue is going to be key.

jkasten2 commented 4 years ago

Closing due to inactivity