Skip to content

Commit

Permalink
Merge pull request #182 from breedx-splk/change_version_handling
Browse files Browse the repository at this point in the history
Use the BuildConfig for version property
  • Loading branch information
breedx-splk authored Dec 12, 2023
2 parents cfe22e6 + 76cf177 commit 3353701
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true

# generate the BuildConfig class that contains the app version
android.defaults.buildfeatures.buildconfig=true
android.minSdk=21
android.targetSdk=23
android.compileSdk=34
Expand Down
6 changes: 6 additions & 0 deletions instrumentation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

plugins {
id("otel.android-library-conventions")
id("otel.publish-conventions")
Expand All @@ -14,6 +15,7 @@ android {
defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
buildConfigField("String", "OTEL_ANDROID_VERSION", "\"$version\"")
}

buildTypes {
Expand Down Expand Up @@ -51,6 +53,10 @@ android {
unitTests.isReturnDefaultValues = true
unitTests.isIncludeAndroidResources = true
}

buildFeatures {
buildConfig = true
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static Resource createDefault(Application application) {
Resource.getDefault().toBuilder().put(SERVICE_NAME, appName);

return resourceBuilder
.put(RUM_SDK_VERSION, detectRumVersion(application))
.put(RUM_SDK_VERSION, BuildConfig.OTEL_ANDROID_VERSION)
.put(DEVICE_MODEL_NAME, Build.MODEL)
.put(DEVICE_MODEL_IDENTIFIER, Build.MODEL)
.put(DEVICE_MANUFACTURER, Build.MANUFACTURER)
Expand All @@ -50,19 +50,6 @@ private static String readAppName(Application application) {
"unknown_service:android");
}

private static String detectRumVersion(Application application) {
return trapTo(
() -> {
// TODO: Verify that this will be in the lib/jar at runtime.
// TODO: After donation, package of R file will change
return application
.getApplicationContext()
.getResources()
.getString(R.string.rum_version);
},
"unknown");
}

private static String trapTo(Supplier<String> fn, String defaultValue) {
try {
return fn.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class AndroidResourceTest {

String appName = "robotron";
String rumSdkVersion = "1.2.3";
String rumSdkVersion = BuildConfig.OTEL_ANDROID_VERSION;
String osDescription =
new StringBuilder()
.append("Android Version ")
Expand All @@ -53,8 +53,6 @@ void testFullResource() {

when(app.getApplicationContext().getApplicationInfo()).thenReturn(appInfo);
when(app.getApplicationContext().getString(appInfo.labelRes)).thenReturn(appName);
when(app.getApplicationContext().getResources().getString(R.string.rum_version))
.thenReturn(rumSdkVersion);

Resource expected =
Resource.getDefault()
Expand Down Expand Up @@ -86,7 +84,7 @@ void testProblematicContext() {
.merge(
Resource.builder()
.put(SERVICE_NAME, "unknown_service:android")
.put(RUM_SDK_VERSION, "unknown")
.put(RUM_SDK_VERSION, rumSdkVersion)
.put(DEVICE_MODEL_NAME, Build.MODEL)
.put(DEVICE_MODEL_IDENTIFIER, Build.MODEL)
.put(DEVICE_MANUFACTURER, Build.MANUFACTURER)
Expand Down

0 comments on commit 3353701

Please sign in to comment.