flutter使用firebase_analytics时报错firebase_analytics:uploadArchives解决方法

flutter使用firebase_analytics时报错firebase_analytics:uploadArchives解决方法

项目中使用firebase_analytics库时能正常运行,可是打包aar时就报错了

Note: /Users/home/.pub-cache/hosted/pub.dartlang.org/firebase_core-1.3.0/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebaseCorePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/home/.pub-cache/hosted/pub.dartlang.org/firebase_analytics-8.1.2/android/src/main/java/io/flutter/plugins/firebaseanalytics/FirebaseAnalyticsPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/home/.pub-cache/hosted/pub.dartlang.org/firebase_analytics-8.1.2/android/src/main/java/io/flutter/plugins/firebaseanalytics/FirebaseAnalyticsPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':firebase_analytics:uploadArchives'.
> Could not publish configuration 'archives'
   > Could not write to file '/Users/home/.pub-cache/hosted/pub.dartlang.org/firebase_analytics-8.1.2/android/build/poms/pom-default.xml'.

* 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

BUILD FAILED in 5s


Gradle task assembleAarDebug failed with exit code 0.

奇怪的是在同事电脑上是可以正常打包的,可能的原因是jdk版本等配置环境导致的错误,不过我试过多个版本的jdk设置都还是报错。
最后是根据这个回答: https://github.com/firebase/flutterfire/issues/3978 解决的。
修改flutter的 F:\flutter\flutter\packages\flutter_tools\gradle 目录下的 aar_init_script.gradle 文件,在最后面加上下面这个方法

void overrideDefaultPublishConfig(Project project, variant) {
    String variantName = variant.name.capitalize()
    Task bundle = project.tasks.findByName("bundle${variantName}Aar") // gradle:3.2.0
    if (bundle == null) {
        bundle = project.tasks.findByName("bundle${variantName}") // gradle:3.1.0
    }
    if (bundle == null) {
        throw new GradleException("Can't generate AAR for variant ${variantName}.");
    }
// Clear the current archive artifacts since the artifacts are based on android.defaultPublishConfig.
    project.configurations["archives"].artifacts.clear()
// Add the artifact that will be published.
    project.artifacts.add("archives", bundle)

    def scopeMappings = project.uploadArchives.repositories.mavenDeployer.pom.scopeMappings
// Clear the scope mappings added by AGP since they are based on the current android.defaultPublishConfig.
    scopeMappings.mappings.clear()
// Add the new mappings.
    int priority = 300
    for (Configuration configuration : flattenConfiguration(variant.runtimeConfiguration)) {
//        scopeMappings.addMapping(/* priority = */ 300, configuration, "compile")
        //firebase_analytics库报错,做这个修改
        scopeMappings.addMapping(/* priority = */ priority, configuration, "compile")
        priority = priority + 100
    }
}

我的 aar_init_script.gradle 文件中其实已经有了这个方法,只是最后面做了修改,如果原来文件中有这个方法,注释后直接复制进去就可以了,主要是做了这个修改

    int priority = 300
    for (Configuration configuration : flattenConfiguration(variant.runtimeConfiguration)) {
//        scopeMappings.addMapping(/* priority = */ 300, configuration, "compile")
        //firebase_analytics库报错,做这个修改
        scopeMappings.addMapping(/* priority = */ priority, configuration, "compile")
        priority = priority + 100
    }

保存后重新打包aar就成功了,好像是对映射的优先级进行调整,有兴趣可以看一下原答案

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值