All environment specific keys like server URL and SDK keys are currently kept in the build.gradle
file. The purpose of this is to easily switch between developing and production environments using buildTypes
.
I added Google Analytics to the app, which is configured via a res/xml/app_tracker.xml
file that contains the tracker ID:
<string name="ga_trackingId" translatable="false">UA-12345678-9</string>
How can the tracker ID be moved into the build.gradle
file's buildTypes
to define a different GA tracker ID for each environment?
Edit
I tried this in build.gradle
:
buildTypes {
release {
resValue "string", "GOOGLE_ANALYTICS_TRACKER_ID", "UA-12345678-9"
}
}
Which auto-generates an xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Automatically generated file. DO NOT MODIFY -->
<!-- Values from build type: debug -->
<string name="GOOGLE_ANALYTICS_TRACKER_ID" translatable="false">UA-12345678-9</string>
</resources>
But this does not seem to work in the app_tracker.xml
file:
<string name="ga_trackingId" translatable="false">@string/GOOGLE_ANALYTICS_TRACKER_ID</string>