Cordova Android 构建错误:“:app:processReleaseGoogleServices'(类型'GoogleServicesTask')”

问题描述 投票:0回答:4

当前行为

尝试构建适用于 Android 的 Ionic Cordova 应用程序时,出现以下错误:

构建命令:

ionic cordova build android --prod --release

    Task :app:processReleaseGoogleServices FAILED
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Some problems were found with the configuration of task ':app:processReleaseGoogleServices' (type 'GoogleServicesTask').
      - In plugin 'com.google.gms.googleservices.GoogleServicesPlugin' type 'com.google.gms.googleservices.GoogleServicesTask' field 'intermediateDir' without corresponding getter has been annotated with @OutputDirectory.
        
        Reason: Annotations on fields are only used if there's a corresponding getter for the field.
        
        Possible solutions:
          1. Add a getter for field 'intermediateDir'.
          2. Remove the annotations on 'intermediateDir'.
        
        Please refer to https://docs.gradle.org/7.1.1/userguide/validation_problems.html#ignored_annotations_on_field for more details about this problem.
      - In plugin 'com.google.gms.googleservices.GoogleServicesPlugin' type 'com.google.gms.googleservices.GoogleServicesTask' field 'packageNameXOR1' without corresponding getter has been annotated with @Input.
        
        Reason: Annotations on fields are only used if there's a corresponding getter for the field.
        
        Possible solutions:
          1. Add a getter for field 'packageNameXOR1'.
          2. Remove the annotations on 'packageNameXOR1'.
        
        Please refer to https://docs.gradle.org/7.1.1/userguide/validation_problems.html#ignored_annotations_on_field for more details about this problem.
      - In plugin 'com.google.gms.googleservices.GoogleServicesPlugin' type 'com.google.gms.googleservices.GoogleServicesTask' field 'packageNameXOR2' without corresponding getter has been annotated with @Input.
        
        Reason: Annotations on fields are only used if there's a corresponding getter for the field.
        
        Possible solutions:
          1. Add a getter for field 'packageNameXOR2'.
          2. Remove the annotations on 'packageNameXOR2'.
        
        Please refer to https://docs.gradle.org/7.1.1/userguide/validation_problems.html#ignored_annotations_on_field for more details about this problem.
      - In plugin 'com.google.gms.googleservices.GoogleServicesPlugin' type 'com.google.gms.googleservices.GoogleServicesTask' field 'quickstartFile' without corresponding getter has been annotated with @InputFile, @Optional.
        
        Reason: Annotations on fields are only used if there's a corresponding getter for the field.
        
        Possible solutions:
          1. Add a getter for field 'quickstartFile'.
          2. Remove the annotations on 'quickstartFile'.
        
        Please refer to https://docs.gradle.org/7.1.1/userguide/validation_problems.html#ignored_annotations_on_field for more details about this problem.
      - In plugin 'com.google.gms.googleservices.GoogleServicesPlugin' type 'com.google.gms.googleservices.GoogleServicesTask' field 'searchedLocation' without corresponding getter has been annotated with @Input.
        
        Reason: Annotations on fields are only used if there's a corresponding getter for the field.
        
        Possible solutions:
          1. Add a getter for field 'searchedLocation'.
          2. Remove the annotations on 'searchedLocation'.
        
        Please refer to https://docs.gradle.org/7.1.1/userguide/validation_problems.html#ignored_annotations_on_field for more details about this problem.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    
    Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
    
    You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
    
    See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec:command_line_warnings
    
    BUILD FAILED in 6s
    4 actionable tasks: 2 executed, 2 up-to-date
    Command failed with exit code 1: /Users/derekmiller/Zogo/Zogo-Frontend/platforms/android/gradlew :app:bundleRelease -b /Users/derekmiller/Zogo/Zogo-Frontend/platforms/android/build.gradle
    [ERROR] An error occurred while running subprocess cordova.
            
            cordova build android --release exited with exit code 1.

从 cordova-android

8.1.1
升级到
10.1.1
后开始出现此构建错误。我们被迫进行此更改,以便我们可以针对 Android API 30。

预期行为

应用程序构建成功

我尝试了什么

  • 大多数遇到此错误的人表示,可以通过确保谷歌服务版本为
    4.3.8
  • 来解决这个问题
  • 我们尝试通过直接在
    classpath com.google.gms:google-services:4.3.8
     中设置 
    build.gradle
  • 来做到这一点
  • 我们还尝试通过将以下内容添加到
    config.xml
    来做到这一点:

   <preference name="GradlePluginGoogleServicesEnabled" value="true" />
   
   <preference name="GradlePluginGoogleServicesVersion" value="4.3.8" />

  • 这两项更改后错误仍然存在

  • 在我的

    <preference name="AndroidXEnabled" value="true" />
    中设置
    config.xml

技术细节

  • 离子 CLI:5.4.16

  • 科尔多瓦 CLI:9.0.0

  • 科尔多瓦安卓:10.1.1

  • Android SDK 工具:26.1.1

  • 操作系统:macOS Big Sur

  • 项目.属性:


    target=android-30
    
    android.library.reference.1=CordovaLib
    android.library.reference.2=app
    cordova.gradle.include.1=branch-cordova-sdk/child-rules.gradle
    cordova.system.library.1=com.google.android.play:core:1.8.0
    cordova.gradle.include.2=cordova-plugin-fcm-with-dependecy-updated/child-FCMPlugin.gradle
    cordova.system.library.2=com.google.firebase:firebase-core:16.0.9
    cordova.system.library.3=com.google.firebase:firebase-messaging:18.0.0
    cordova.gradle.include.3=cordova-plugin-ionic/child-cordovapluginionic.gradle
    cordova.system.library.4=com.google.android.gms:play-services-analytics:11.0.1
    cordova.system.library.5=androidx.annotation:annotation:1.1.0
    cordova.system.library.6=com.mixpanel.android:mixpanel-android:5.9.1
    cordova.system.library.7=com.google.android.gms:play-services-base:16.+
    cordova.system.library.8=com.google.firebase:firebase-messaging:16.+
    cordova.system.library.9=androidx.legacy:legacy-support-v4:1.0.0

android cordova gradle ionic-framework build
4个回答
1
投票

如果您使用的是phonegap-plugin-push,则会导致此错误,因为它引用了过时版本的Google服务。可以更换:

cordova plugin remove phonegap-plugin-push
cordova plugin add @havesource/cordova-plugin-push

任何对phonegap-plugin-push 的引用也需要更新。


0
投票

我只是想问你是否尝试过按照以下方式进行操作而不更改构建文件本身,如果没有,请尝试并重建它,让我知道

升级:

cordova platform remove android
cordova platform add [email protected]

0
投票

我通过在根目录中设置全局谷歌服务版本解决了这个问题

build.gradle


    allprojects {
        // other settings
    
        ext {
            GOOGLE_SERVICES_VERSION = '4.3.10'
        }
    }

我尝试设置谷歌服务版本的其他方法不起作用,因为有一些其他插件试图使用不同版本的谷歌服务。我相信以这种方式设置版本可以确保它们都使用相同的版本。


0
投票

@havesource
上的问题所示,覆盖Google服务版本的更可持续的解决方案是将以下内容添加到
config.xml
(而不是像OP的答案所建议的那样编辑生成的文件):

<platform name="android">
  <!-- ... -->
  <!-- this next tag doesn't seem necessary in my scenario, but it's cited in many places; YMMV -->
  <!-- preference name="GradlePluginGoogleServicesEnabled" value="true" /-->
  <preference name="GradlePluginGoogleServicesVersion" value="4.3.15" />
</platform>

注意:许多版本都报告修复了该问题,例如4.3.8(链接问题)、4.3.10(OP)和4.3.15(me);再次,YMMV。

© www.soinside.com 2019 - 2024. All rights reserved.