Crashlytics没有找到在crashlytics.properties在运行时API密钥 [英] Crashlytics not finding API Key in crashlytics.properties at runtime

查看:294
本文介绍了Crashlytics没有找到在crashlytics.properties在运行时API密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在实施的API密钥交换脚本建议这里,除与构建类型,而不是味道。我build.gradle看起来是这样的:

I'm currently implementing the API Key switching script suggested here, except with build types instead of flavors. My build.gradle looks like this:

...
buildTypes {
    debug {
        ...
        set("crashlyticsApiKey", "API_KEY_1")
        set("crashlyticsApiSecret", "API_SECRET_1")
    }
    release {
        ...
        set("crashlyticsApiKey", "API_KEY_2")
        set("crashlyticsApiSecret", "API_SECRET_2")
    }
}
...
productFlavors{...}
...
File crashlyticsProperties = new File("${project.projectDir.absolutePath}/crashlytics.properties")

applicationVariants.all { variant ->
    variant.productFlavors.each { flavor ->
        def variantSuffix = variant.name.capitalize()
        def generateResourcesTask = project.tasks.getByName("crashlyticsGenerateResources${variantSuffix}")
        def generatePropertiesTask = task("crashlyticsGenerateProperties${variantSuffix}") << {
            Properties properties = new Properties()
            println "...copying apiKey for ${variant.name}"
            properties.put("apiKey", variant.buildType.crashlyticsApiKey)
            println "...copying apiSecret for ${variant.name}"
            properties.put("apiSecret", variant.buildType.crashlyticsApiSecret)
            properties.store(new FileWriter(crashlyticsProperties), "")
        }
        generateResourcesTask.dependsOn generatePropertiesTask
        def cleanResourcesTask = project.tasks.getByName("crashlyticsCleanupResourcesAfterUpload${variantSuffix}")
        cleanResourcesTask.doLast {
            println "...removing crashlytics.properties"
            crashlyticsProperties.delete()
        }
    }
}
...

在摇篮文件成功生成,并crashlytics.properties具有根据生成类型的正确的信息更新。使用crashlytics.properties这种方法建议这里,并没有出现比包含以外的任何其他更新工作相关性在摇篮文件。然而,当 Crashlytics.start(本)的主要活动是所谓的,我得到一个运行时异常:

The gradle file builds successfully, and crashlytics.properties updates with the correct information according to the build type. This method of using crashlytics.properties was suggested here, and appears to work without any other updates other than the inclusion of dependencies in the gradle file. However, when Crashlytics.start(this) is called from the main activity, I get a runtime exception:

java.lang.RuntimeException: Unable to create application com.lookout.LookoutApplication: java.lang.IllegalArgumentException: Crashlytics could not be initialized, API key missing from AndroidManifest.xml. Add the following tag to your Application element
<meta-data android:name="com.crashlytics.ApiKey" android:value="YOUR_API_KEY"/>

剥离下来到一个静态crashlytics.properties文件(即去除动态脚本的摇篮文件,只是有一个apiKey和apiSecret在crashlytics.properties)产生了同样的错误,即使它成功生成。

Stripping it down to a static crashlytics.properties file (i.e. removing the dynamic script in the gradle file and just having one apiKey and apiSecret in crashlytics.properties) produces the same error, even though it builds successfully.

有一些变化的Andr​​oidManifest或build.gradle文件,我应该使指向它往crashlytics.properties?

Is there some change to the AndroidManifest or the build.gradle file I should be making to point it towards crashlytics.properties?

推荐答案

您应该定义

<application>    
<meta-data
            android:name="com.crashlytics.ApiKey"
            android:value="YOUR_API_KEY" />
</application>    

在你的AndoidManifest.xml

in your AndoidManifest.xml

对我来说是自动布料插件AndroidStudio( https://dev.twitter.com/)

For me it was generated automatically with fabric plugin for AndroidStudio (https://dev.twitter.com/).

这篇关于Crashlytics没有找到在crashlytics.properties在运行时API密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆