扩展cordova gradle文件以包括Google服务 [英] Extending the cordova gradle file to include google services
问题描述
我正在尝试将com.google.gms:google-services:3.0.0
包含在我的cordova插件中,而不必将其入侵到主build.gradle
文件中.我已将以下文件添加到我的应用程序中:
I'm trying to include com.google.gms:google-services:3.0.0
into my cordova plugin without having to hack it into the main build.gradle
file. I have added the following file to my application:
build-extras.gradle
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
}
}
apply plugin: 'com.google.gms.google-services'
尝试构建应用程序时出现以下错误:
I get the following error when trying to build the application:
* Where:
Script 'platforms/android/build-extras.gradle' line: 11
* What went wrong:
A problem occurred evaluating script.
> Plugin with id 'com.google.gms.google-services' not found.
我尝试使用<framework src="src/android/build-extras.gradle" custom="true" type="gradleReference" />
包含build-extras.gradle
,并且还手动将其复制到platforms/android
.
I have attempted including build-extras.gradle
using <framework src="src/android/build-extras.gradle" custom="true" type="gradleReference" />
and also manually copying it into platforms/android
.
科尔多瓦参考资料: https://cordova.apache.org/docs/zh_CN/latest/guide/platforms/android/#extending-buildgradle
Cordova Reference: https://cordova.apache.org/docs/en/latest/guide/platforms/android/#extending-buildgradle
Google参考: https://developers.google.com/identity/sign-in/android/start-integrating
Google Reference: https://developers.google.com/identity/sign-in/android/start-integrating
如果我从build-extras.gradle
中获取相同的代码,然后直接附加到build.gradle
的末尾,那似乎就可以了.关于如何使它在我的build-extras.gradle
文件中起作用的任何想法?
If I take that same code from build-extras.gradle
and directly append then to the end of build.gradle
it seems to work. Any thoughts on how I can get this to work in my build-extras.gradle
file?
推荐答案
您必须用
ext.postBuildExtras = { //... your gradle supplement }
以下是您的 build-extras.gradle 文件的示例:
Here is an example of your build-extras.gradle file:
ext.postBuildExtras = {
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
dependencies {
compile files('libs/httpclient-4.5.4.jar', 'libs/httpcore-4.4.7.jar')
}
}
并将其放置在与 build.gradle 文件相同的文件夹下. 在Cordova Android v7.0.0之后,您应该将其放置为:
and place it under the same folder as build.gradle file. After Cordova Android v7.0.0, you should place it like this:
$PROJECT_PATH/platforms/android/app/build.gradle
$PROJECT_PATH/platforms/android/app/build-extras.gradle
这篇关于扩展cordova gradle文件以包括Google服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!