orhanobut / tracklytics

✔️ Annotation based tracking handler with aspect oriented programming
Apache License 2.0
429 stars 45 forks source link

Enabling different keys for debug and release (Suggestion) #4

Closed ergunkocak closed 7 years ago

ergunkocak commented 8 years ago

In my project we use out source teams and i do not want to share our live API Keys with them so i create 2 different project on Google Console and generate 2 different sets of keys. To enable this with Tracklytics i did this :

  1. Created 2 sets of files
    • for debug which is located under app/src/debug folder
    • for release one level up the git base in a folder named AndroidKeyStore
  2. Generated config files using Google API config file generators and put the files accordingly in these folders
    • "google-services.json"
    • "tracklytics.properties"
  3. In app build.gradle used some tasks and chained them to existing tasks to copy files according to build type to the proper locations.
    • at the end of app build.gradle added
task switchToDebug(type: Copy) {
    description = 'Switches to DEBUG google-services.json'
    from "src/debug"
    include "google-services.json"
    into "."
}

task switchToRelease(type: Copy) {
    description = 'Switches to RELEASE google-services.json'
    from "../.."
    include "google-services.json"
    into "."
}

task prepareTracklyticsDebug(type: Copy) {
    description = 'Copies Tracklytics keys for Debug'
    from "src/debug"
    include "tracklytics.properties"
    into "../"
}

task prepareTracklyticsRelease(type: Copy) {
    description = 'Copies Tracklytics keys for Release'
    from "../../AndroidKeyStore"
    include "tracklytics.properties"
    into "../"
}
afterEvaluate {
    processDebugGoogleServices.dependsOn switchToDebug
    processReleaseGoogleServices.dependsOn switchToRelease

    if (build.properties.debuggable) {
        prepareComOrhanobutTracklyticsTracklyticsRuntime013Library.dependsOn prepareTracklyticsDebug
    } else {
        prepareComOrhanobutTracklyticsTracklyticsRuntime013Library.dependsOn prepareTracklyticsRelease
    }
}

Result :

I used build.properties.debuggable and set it false for release buildType and true for debug buildType because i could not see different tasks for release and debug in build log. It may be good if there are seperate tasks as " processDebugGoogleServices & processReleaseGoogleServices " in addition to / instead of prepareComOrhanobutTracklyticsTracklyticsRuntime013Library . Or they exists and i could not see :(

I am not a master so i am very open to change the way i did it if this is not the way to do these kind of stuff.

orhanobut commented 8 years ago

@ergunkocak very very late reply but I just found some time to spare. I actually designed this library to use for different build types but somehow, gradle didn't work as I expected. I'll definitely make changes for this. Currently I removed tracklytics.properties files and as a practice, public api keys can be actually used through gradle. Build types are quite good for that purpose. Thanks for the detailed feedback

orhanobut commented 8 years ago

@ergunkocak I changed the tracklytics implementation. All tool implementations will be up to the developer from now on. I think that's the best and flexible way. As I suggested above, the best way to differentiate API Keys is using gradle build type or flavor.

orhanobut commented 7 years ago

Closing this issue for now due to pivoted project. @ergunkocak thanks for the suggestions though