Tôi hiện đang triển khai tập lệnh chuyển đổi Khóa API được đề xuất here, ngoại trừ với các loại xây dựng thay vì hương vị. Build.gradle của tôi trông giống như sau:Crashlytics không tìm thấy Khóa API trong crashlytics.properties khi chạy
...
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()
}
}
}
...
Tệp gradle xây dựng thành công và crashlytics.properties cập nhật thông tin chính xác theo loại bản dựng. Phương pháp sử dụng crashlytics.properties này được đề xuất here và dường như hoạt động mà không có bất kỳ cập nhật nào khác ngoài việc bao gồm các phụ thuộc trong tệp gradle. Tuy nhiên, khi Crashlytics.start(this)
được gọi từ các hoạt động chính, tôi nhận được một ngoại lệ thời gian chạy:
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"/>
Tước nó xuống vào một tập tin crashlytics.properties tĩnh (tức là loại bỏ các script động trong file gradle và chỉ có một apiKey và apiSecret trong crashlytics.properties) tạo ra cùng một lỗi, mặc dù nó xây dựng thành công.
Có thay đổi nào đối với tệp AndroidManifest hoặc tệp build.gradle mà tôi nên thực hiện để trỏ nó tới crashlytics.properties không?
Tắt InstantR un cố định vấn đề cho tôi. Ước gì tôi tìm thấy bài đăng này trước khi dành một giờ thử lời tiên tri. – Soumya