【问题标题】:How to fix Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin']?如何修复无法应用插件 [class 'com.google.gms.googleservices.GoogleServicesPlugin']?
【发布时间】:2018-02-06 09:43:17
【问题描述】:

我是使用 ionic 1 和 cordova 的新手,我尝试安装 cordova-plugin-fcm 使用此评论:

cordova plugin add cordova-plugin-fcm

但是当我构建使用时:

ionic cordova run android

我收到此错误:

脚本 'D:\net\netAppV2\platforms\android\cordova-plugin-fcm\netappv2-FCMPlugin.gradle' 行:13

  • 出了什么问题: 评估脚本时出现问题。 无法应用插件 [class 'com.google.gms.googleservices.GoogleServicesPlugin'] 对于输入字符串:“+”

这是netappv2-FCMPlugin.gradle的内容:

buildscript {
    repositories {
            jcenter()
            mavenLocal()
        }
    dependencies {
        classpath 'com.android.tools.build:gradle:+'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin

请任何人帮我解决这个问题。

谢谢。

【问题讨论】:

  • 而不是“+”符号指定您当前的 gradle 版本,如 classpath 'com.android.tools.build:gradle:3.2.0-alpha01'
  • 我已经尝试过你的建议,但我得到了同样的错误@Gaurav

标签: android cordova ionic-framework


【解决方案1】:

您可以通过以下方式解决:

1.从插件文件夹中打开您的plugin.xml 的cordova-plugin-fcm。

2.找到+,替换版本11.0.1

3.然后删除和添加平台

4.然后构建

【讨论】:

  • 这只是临时修复,用cordova重建后你需要做同样的事情。
【解决方案2】:

我遇到了同样的问题,它是由play-services 版本引起的。 您可以使用@Mani 的临时修复,但如果您需要的不仅仅是临时的,则应该做一些额外的解决方法:

1) 创建带有before_prepare 类型的钩子。也就是JS文件,内容:

// That hook needed for fixing ANDROID Gradle issues with multiple `google.android.gms` services versions
// details:
// https://github.com/phonegap/phonegap-plugin-push/issues/1718

const fs = require('fs');
const path = require('path');

const FCM_VERSION = '11.8.0';

// You can include more of each string if there are naming conflicts,
// but for the GMS libraries each should be unique enough.
// The full list of libraries is here:
// https://developers.google.com/android/guides/setup
const LIBRARIES = [
    'play-services-analytics',
];

const createRegex = (item) => new RegExp(`${item}:.*`, 'ig');
const createReplace = (item) => `${item}:${FCM_VERSION}`;

module.exports = (ctx) => {
    const Q = ctx.requireCordovaModule('q');
    const deferred = Q.defer();

    const gradle = path.join(ctx.opts.projectRoot, 'platforms', 'android', 'project.properties');
    fs.readFile(gradle, 'utf8', (err, data) => {
        if (err) {
            return deferred.reject(err);
        }

        let result = data;
    LIBRARIES.forEach((lib) => {
        result = result.replace(createRegex(lib), createReplace(lib));
})

    return fs.writeFile(gradle, result, 'utf8', (err) => {
        if (err) {
            deferred.reject(err);
        }
    deferred.resolve();
});
});

    return deferred.promise;
};

2) 在您的 Android 平台配置中声明该挂钩

<hook type="before_prepare" src="hooks/google-services-versions-fix.js" />

3) 在android/project.properties 中查找具有+ 并与play-services 相关的所有版本,例如: cordova.system.library.7=com.google.android.gms:play-services-analytics:+

4) 将此类依赖项添加到挂钩到 const LIBRARIES = 部分。

这会将所需的依赖项更新为适当的版本并解决此类问题!

【讨论】:

    猜你喜欢
    • 2019-02-17
    • 2018-12-26
    • 1970-01-01
    • 2018-07-17
    • 2017-12-15
    • 2017-12-03
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多