getsentry / sentry-java

A Sentry SDK for Java, Android and other JVM languages.
https://docs.sentry.io/
MIT License
1.16k stars 435 forks source link

Support Android Gradle build buildTypes/flavors #437

Closed AndrewJack closed 7 years ago

AndrewJack commented 7 years ago

Could you add the ability to specify a sentry.properties file per buildType/Flavor?

In my case I have separate projects for each build type. e.g. dogfood & release sentry projects

Similar to how Google have implemented their google-services plugin

Build types

app/
    sentry.properties
    src/dogfood/sentry.properties
    src/release/sentry.properties

flavors & build types

app/
    sentry.properties
    src/dogfood/paid/sentry.properties
    src/release/free/sentry.properties

https://developers.google.com/android/guides/google-services-plugin#adding_the_json_file

bretthoerner commented 7 years ago

Oops, good call, thanks for the report.

AndrewJack commented 7 years ago

Using this as a workaround for now

apply from: 'sentry-switch-env.gradle'
def appModuleRootFolder = '.'
def sentryProperties = 'sentry.properties'

task switchToDogfood(type: Copy) {
    def buildType = 'dogfood'
    description = "Switches to $buildType sentry.properties"
    from "$appModuleRootFolder/src/${buildType}"
    include "$sentryProperties"
    into "${rootProject.rootDir}"
}

task switchToRelease(type: Copy) {
    def buildType = 'release'
    description = "Switches to $buildType sentry.properties"
    from "$appModuleRootFolder/src/${buildType}"
    include "$sentryProperties"
    into "${rootProject.rootDir}"
}

afterEvaluate {
    persistSentryProguardUuidsForDogfood.dependsOn switchToDogfood
    persistSentryProguardUuidsForRelease.dependsOn switchToRelease
}
AndrewJack commented 7 years ago

@bretthoerner Do you support apk splits too? My build seems to work with it so far.

https://developer.android.com/studio/build/configure-apk-splits.html

bretthoerner commented 7 years ago

I just did a local test, it seems to me that we already work with splits because it looks like Proguard runs for all source one time, we generate the UUID and drop the sentry-debug-meta.properties file which is included in each .apk. Update: I unpacked my split .apk files and I see the properties file there, so I think we're all good?

Unrelated: have you sent a Sentry event with an .apk built using our wrapper yet? I'm actually trying to debug a Proguard issue in production and I'm curious if it has been working (or not) for you. 😬

AndrewJack commented 7 years ago

@bretthoerner Probably not i'm still setting it all up.

bretthoerner commented 7 years ago

For what it's worth Proguard on Sentry SaaS is working, I'm looking into the build type thing now.