You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

更新OneSignal Gradle插件时遭遇依赖无法解析错误

解决OneSignal Gradle插件版本更新后的依赖解析错误

你在升级OneSignal Gradle插件到[0.9.0, 0.99.99]范围后遇到的依赖解析问题,主要是因为0.9.x版本的插件对Gradle构建工具、Google Services插件的版本有更高要求,再加上配置里存在不符合标准的地方导致的。下面是具体的解决步骤:

1. 升级Project级Gradle的核心依赖版本

你当前Project级Gradle里的Android Gradle插件和Google Services插件版本过低,无法兼容OneSignal 0.9.x插件。修改后的配置如下:

buildscript {
    repositories {
        google() // 优先从Google仓库获取依赖,减少解析失败概率
        jcenter()
    }
    dependencies {
        // 升级到兼容compileSdk 27的稳定版Gradle插件
        classpath 'com.android.tools.build:gradle:3.5.4'
        // 升级到适配旧版本Firebase/Google服务的Google Services插件
        classpath 'com.google.gms:google-services:4.3.10'
        // 将OneSignal插件依赖移到这里(标准配置位置)
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.9.0, 0.99.99]'
    }
}

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

2. 修正App级Gradle的配置

你当前App级Gradle里额外添加了buildscript块引入OneSignal插件,这不符合标准配置(插件依赖应统一放在Project级)。修改后的配置如下:

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

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 16
        targetSdkVersion 25
        manifestPlaceholders = [
                manifestApplicationId: "${applicationId}",
                onesignal_app_id: "xxxxxxxxxxxx",
                onesignal_google_project_number: "REMOTE"
        ]
        multiDexEnabled true
        resConfigs "en","ta"
    }

    buildTypes {
        debug{
            debuggable true
            minifyEnabled false
        }
        release {
            debuggable false
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    repositories {
        google()
        jcenter()
        // 可移除下面这行,因为google()仓库已包含该地址
        // maven { url 'https://maven.google.com' }
    }
}

dependencies {
    ext {
        support_library_version = '27.1.1'
        google_play_services_version = '15.0.1'
    }

    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:preference-v7:27.1.1'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.android.gms:play-services-analytics:15.0.2'
    implementation 'com.google.firebase:firebase-ads:15.0.0'
    implementation 'com.google.firebase:firebase-messaging:15.0.2'
    implementation 'com.google.firebase:firebase-core:15.0.2'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.google.firebase:firebase-auth:15.1.0'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.google.android.gms:play-services-basement:15.0.1'
    implementation 'com.google.firebase:firebase-database:15.0.0'
    implementation 'com.google.android.gms:play-services-places:15.0.1'
}

apply plugin: 'com.google.gms.google-services'

3. 匹配Gradle wrapper版本

Android Gradle插件3.5.4需要配合Gradle 5.4.1及以上版本使用,修改gradle/wrapper/gradle-wrapper.properties中的distributionUrl:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

4. 清理缓存并重新构建

执行以下命令清理旧缓存,强制重新下载依赖:

./gradlew clean build --refresh-dependencies

完成以上修改后,OneSignal 0.9.x插件的依赖应该就能正常解析了。

内容的提问来源于stack exchange,提问作者Sarath Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:31:13