当前位置: 首页 > 知识库问答 >
问题:

Android应用程序因OneSignal推送通知而崩溃

王伯寅
2023-03-14

我开发了一个React Native应用程序,当应用程序处于活动状态时,每次收到来自OneSignal的消息推送时都会崩溃。

错误是java。lang.NoSuchMethodError:没有静态方法zzc

如果我在应用程序处于后台时收到通知,则没有问题。

这是我的身材。gradle文件:

buildscript {
    ext {
        googlePlayServicesLocationVersion = "17.0.0"
        buildToolsVersion = "28.0.3"
        minSdkVersion = 21
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
        appCompatVersion = "1.0.2"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
    }
}

allprojects {
    repositories {

        configurations.all {
            resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            def requested = details.requested
           if (requested.group == 'com.google.android.gms') {
              details.useVersion '17.0.0'
           }
           if (requested.group == 'com.google.firebase') {
              details.useVersion '17.0.0'
             }
           }
         }
        google()
        mavenLocal()

        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }

        maven {
           url "$rootDir/../node_modules/react-native-background-geolocation/android/libs"
        }

            maven {
                url "$rootDir/../node_modules/react-native-background-fetch/android/libs"
            }
    }
}


task wrapper(type: Wrapper) {
    gradleVersion = '4.10'
    distributionUrl = distributionUrl.replace("bin", "all")
}

还有我的应用/构建。gradle文件:

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

apply from: '../../node_modules/react-native-unimodules/gradle.groovy'
apply from: "../../node_modules/react-native/react.gradle"

Project background_geolocation = project(':react-native-background-geolocation')
apply from: "${background_geolocation.projectDir}/app.gradle"


def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "XXX"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 200
        versionName "24.10"
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation project(':@react-native-community_netinfo')
    implementation project(':react-native-fast-image')
    implementation project(':react-native-device-info')
    implementation project(':react-native-orientation-locker')
    implementation project(':@react-native-community_slider')
    implementation project(':react-native-webview')
    implementation project(':react-native-splash-screen')
    implementation project(':@react-native-community_async-storage')
    implementation project(':react-native-sentry')
    implementation project(':react-native-background-fetch')
    implementation project(':react-native-maps')
    implementation project(':react-native-iap')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-background-geolocation')
    implementation project(':react-native-webrtc')
    implementation project(':react-native-svg')
    implementation project(':react-native-onesignal')
    implementation project(':react-native-incall-manager')
    implementation project(':react-native-fs')
    implementation project(':react-native-reanimated')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.facebook.fresco:animated-gif:1.10.0'
    implementation "com.facebook.fresco:animated-base-support:1.3.0"
    addUnimodulesDependencies()
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

// [Added by react-native-background-geolocation] Purge debug sounds from release build.
def purgeBackgroundGeolocationDebugResources(applicationVariants) {
    if ((rootProject.ext.has("removeBackgroundGeolocationDebugSoundsInRelease")) && (rootProject.ext.removeBackgroundGeolocationDebugSoundsInRelease == false)) return
    applicationVariants.all { variant ->
        if (variant.buildType.name == "release") {
            println("[react-native-background-geolocation] Purging debug resources in release build")
            variant.mergeResources.doLast {
                delete(fileTree(dir: variant.mergeResources.outputDir, includes: ["raw_tslocationmanager*"]))
            }
        }
    }
}

你知道问题来自哪里吗?

共有3个答案

梅玉堂
2023-03-14

此错误是由于与one信号sdk中使用的Firebase和google服务冲突而引起的。如果您可以使用16.1.0作为您的googleplay服务版本,com.google.android.gms,如果没有帮助,请尝试降级Firebase。您可以查看https://github.com/OneSignal/OneSignal-Android-SDK/blob/master/OneSignalSDK/onesignal/build.gradle以供参考。请回复。

魏翔
2023-03-14

请在app/build.gradle文件的顶部添加这些代码行

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

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

添加上述代码后,goto命令提示符,导航到react-local项目的android文件夹并运行gradlew清洁。最后运行项目。

如果遇到同样的问题,一定要告诉我。

居星阑
2023-03-14

这可能发生在如果;

  1. 应用程序中的OneSignal SDK版本早于3.6.0

根据你的构建脚本2是好的。你需要在你的项目中应用OneSignal gradle插件。

    buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin: [0.10.1, 0.99.99]'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
 类似资料:
  • 我用Unity3D制作了一个游戏/应用程序,需要设置一个推送通知的OneSignal。它在Android上工作得很好,我已经测试并发布了它。现在,用iOs真实设备测试给了我一个例外,并使我的应用程序崩溃。 我遵循了他们在这里找到的实现步骤:https://documentation.onesignal.com/docs/unity-sdk-setup 我试过在iPhone7 Plus、iPad和模

  • 我已经检查了react native onesignal github README,似乎获得通知的唯一方法是通过onNotificationOpen()回调打开。 他们的文件表明: 当打开或接收到任何通知时,调用回调传递带有通知数据的对象。 但是,显然不起作用。 有没有办法在不打开推送通知或启用应用内警报通知的情况下获取通知?

  • 如果应用程序关闭,我将如何使其发送通知?我正在制作一个从web服务器读取数据的应用程序,只有当该应用程序关闭且web服务器上的值更改时,我才需要向用户发送通知。

  • 当我打开我的android应用程序并测试解析推送通知时,它工作了。但是当我把我的应用程序从多任务中杀死并再次测试时,应用程序崩溃了。 错误日志 08-18 21:16:21.694 244 06-24406/?E/AndroidRuntime:致命异常:main process:com.myatminsoe.mKeyboard,PID:24406 java.lang.runtimeExceptio

  • 我想用Xamarin格式的C#创建一个基于文本的Android游戏。 在故事中,我想设置角色任务,这需要一些时间,例如“我去挖这个洞,完成后给你打电话。” 如何将通知设置为在设置的时间之后显示?例如,上述声明可能需要10分钟,然后用户收到继续游戏的通知? 我一周前才开始做C#,所以如果这是noobish,或者已经被问到了,我道歉。我到处都找过,但有几种类型的通知,当我试图理解它时,似乎我在读法语。