Crashlytics发现一个无效的API密钥 [英] Crashlytics found an invalid API key

查看:2510
本文介绍了Crashlytics发现一个无效的API密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图用的元数据标记作为一个字符串引用建设项目,crashlytics失败有以下错误:

  Crashlytics发现一个无效的API密钥:@字符串/ crashlytics。
检查Crashlytics插件,以确保应用程序已被成功添加!
联系support@crashlytics.com寻求帮助。
 

不工作

 <元数据
    机器人:名称=com.crashlytics.ApiKey
    机器人:值=@字符串/ crashlytics/>
 

作品

 <元数据
    机器人:名称=com.crashlytics.ApiKey
    机器人:值=1234567890 ....../>
 

我要为不同的 productFlavors 我的Andr​​oid项目的定义里面 string.xml 不同的密钥。

更新

写crashlytics支持后:

  

目前,我们只能够评价的Andr​​oidManifest.xml在制作的时候,所以我们不看任何字符串资源,所以我们只支持硬codeD字符串。我肯定会跟你有兴趣,所以我们可以考虑在以后的版本支持这个团队分享。

解决方案
  

编辑:只接受的工作,如果你正在使用Crashlytics的旧版本(我是用v1.1.11)的解决方案。如果您使用的是面料SDK,你会发现   该插件的任务已经大大改变,下面的脚本   不管用。另外,API秘密不再需要,因此,   你可以使用<元> 在清单来随着你的气息中定义的清单占位符指定的API密钥:

     
      
  • build.gradle

         

      flavor1 {
        ...
        manifestPlaceholders = [crashlyticsApiKey:CRASHLYTICS_API_SECRET_HERE]
        ...
    }
     

      

  •   
  • AndroidManifest.xml中

         

      ...
    &所述;元数据
        机器人:名称=com.crashlytics.ApiKey
        机器人:值=$ {crashlyticsApiKey}/>
    ...
     

      

  •   

还有另无证方式以指定Crashlytics键此处指出,它是使用 crashlytics.properties (在你的项目的根目录下),以随着API的秘密指定的值:

  apiKey = YOUR_API_KEY
apiSecret = YOUR_API_SECRET
 

Unfortuntately这会不会让你只需指定一个不同的 crashlytics.properties 针对每种口味,因为它需要在你的项目的根目录下才能被挑正确地由摇篮插件。这意味着你需要为生成文件动态。 我们的想法是添加键/值的秘诀在你的口味为自定​​义属性,并生成 crashlytics.properties 在生成时,从目前的味用值来填充文件

build.gradle 在你的Andr​​oid模块应该是这样的:

  ...
productFlavors {

    flavor1 {
        ...
        设置(crashlyticsApiKey,CRASHLYTICS_API_KEY_HERE)
        设置(crashlyticsApiSecret,CRASHLYTICS_API_SECRET_HERE)
        ...
    }
    ...
}

文件crashlyticsProperties =新的文件($ {project.projectDir.absolutePath} /crashlytics.properties)
applicationVariants.all {变种 - >
    variant.productFlavors.each {味 - >
        高清variantSuffix = variant.name.capitalize()
        高清generateResourcesTask = project.tasks.getByName(crashlyticsGenerateResources $ {variantSuffix})
        高清generatePropertiesTask =任务(crashlyticsGenerateProperties $ {variantSuffix})<< {
            属性属性=新的属性()
            的println......复制apiSecret为$ {variant.name}
            properties.put(apiSecret,flavor.crashlyticsApiSecret)
            的println......复制apiKey为$ {variant.name}
            properties.put(apiKey,flavor.crashlyticsApiKey)
            properties.store(新的FileWriter(crashlyticsProperties),)
        }
        generateResourcesTask.dependsOn generatePropertiesTask
        高清cleanResourcesTask = project.tasks.getByName(crashlyticsCleanu presourcesAfterUpload $ {variantSuffix})
        cleanResourcesTask.doLast {
            的println......除去crashlytics.properties
            crashlyticsProperties.delete()
        }
    }
}
...
 

基本上在建设过程中的脚本挂钩,并生成/填充属性文件的Crashlytics摇篮插件做它的魔力之前。

When I am trying to build project with value of meta-data tag as a string reference, crashlytics fail with following error:

Crashlytics found an invalid API key: @string/crashlytics. 
Check the Crashlytics plugin to make sure that the application has been added successfully! 
Contact support@crashlytics.com for assistance.

Doesn't work

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

Works

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

I am want to define different keys inside string.xml for different productFlavors of my android project.

Update

After writing to crashlytics support:

Currently we only are able to evaluate the AndroidManifest.xml at build time so we don't look at any strings resources so we only support a hard coded string. I'll definitely share this with the team that you're interested so we can look into supporting this in a future release.

解决方案

Edit: The solution accepted is working only if you are using an old version of Crashlytics (I was using v1.1.11). If you are using Fabric SDK you will notice the tasks of the plugin have changed considerably and the script below will not work. Also the API secret is not needed anymore, therefore you can just use the <meta> in the manifest to specify the API key along with a manifest placeholder defined in your flavor:

  • in build.gradle:

    flavor1 {
        ...
        manifestPlaceholders = [crashlyticsApiKey: CRASHLYTICS_API_SECRET_HERE]
        ...
    }
    

  • in AndroidManifest.xml:

    ...
    <meta-data
        android:name="com.crashlytics.ApiKey"
        android:value="${crashlyticsApiKey}" />
    ...
    

There is another undocumented way to specify the Crashlytics key as noted here, and it is to use the crashlytics.properties (in the root of your project) to specify that value along with the API secret:

apiKey=YOUR_API_KEY
apiSecret=YOUR_API_SECRET

Unfortuntately this will not allow you to simply specify a different crashlytics.properties for each flavor, because it needs to be in the root of your project in order to be picked correctly by the gradle plugin. That means you need to generate that file dynamically. The idea is to add the key/secret values in your flavor as custom properties, and generate the crashlytics.properties at buildtime, using the values from the current flavor to fill the file.

The build.gradle inside your android module should look like this:

...
productFlavors {

    flavor1 {
        ...
        set("crashlyticsApiKey", CRASHLYTICS_API_KEY_HERE)
        set("crashlyticsApiSecret", CRASHLYTICS_API_SECRET_HERE)
        ...
    }
    ...
}

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 apiSecret for ${variant.name}"
            properties.put("apiSecret", flavor.crashlyticsApiSecret)
            println "...copying apiKey for ${variant.name}"
            properties.put("apiKey", flavor.crashlyticsApiKey)
            properties.store(new FileWriter(crashlyticsProperties), "")
        }
        generateResourcesTask.dependsOn generatePropertiesTask
        def cleanResourcesTask = project.tasks.getByName("crashlyticsCleanupResourcesAfterUpload${variantSuffix}")
        cleanResourcesTask.doLast {
            println "...removing crashlytics.properties"
            crashlyticsProperties.delete()
        }
    }
}
...

Basically the script hooks in the building process and generates/fills the properties file just before the Crashlytics gradle plugin does its magic.

这篇关于Crashlytics发现一个无效的API密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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