From 89129cd4c3aac0750f88a3411c85f9041be559c7 Mon Sep 17 00:00:00 2001 From: ndesai-newrelic Date: Fri, 15 Sep 2023 11:14:05 -0500 Subject: [PATCH] fix: fix no class found error for harecordHandledException method fix #129 --- android/build.gradle | 5 ++--- .../com/NewRelic/NRMModularAgentModule.java | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 76a6cc5..eeee1b2 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -51,11 +51,10 @@ if (findProject(':@newrelic-react-native-agent')) { android { namespace "com.NewRelic" - compileSdkVersion 31 defaultConfig { minSdkVersion 21 - targetSdkVersion 31 + targetSdkVersion 33 versionCode 1 versionName version } @@ -76,7 +75,7 @@ repositories { } dependencies { - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13.2' compileOnly 'com.facebook.react:react-native:+' implementation "com.newrelic.agent.android:android-agent:${ReactNative.ext.getVersion("newrelic", "android")}" implementation "com.newrelic.agent.android:agent-ndk:${ReactNative.ext.getVersion("newrelic", "ndk")}" diff --git a/android/src/main/java/com/NewRelic/NRMModularAgentModule.java b/android/src/main/java/com/NewRelic/NRMModularAgentModule.java index e950a0a..b282f25 100644 --- a/android/src/main/java/com/NewRelic/NRMModularAgentModule.java +++ b/android/src/main/java/com/NewRelic/NRMModularAgentModule.java @@ -441,8 +441,22 @@ private StackTraceElement[] generateStackTraceElements(Map stack List stackTraceList = new ArrayList<>(); for(int i = 0; i < stackFrameMap.size(); ++i) { Map element = (Map) stackFrameMap.get(Integer.toString(i)); - String methodName = (String) element.getOrDefault("methodName", ""); - String fileName = (String) element.getOrDefault("file", ""); + String methodName = null; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { + methodName = (String) element.getOrDefault("methodName", ""); + } else { + if (element.containsKey("methodName")) { + methodName = (String)element.get("methodName"); + } + } + String fileName = null; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { + fileName = (String) element.getOrDefault("file", ""); + } else { + if (element.containsKey("file")) { + fileName = (String)element.get("file"); + } + } int lineNumber = element.get("lineNumber") != null ? ((Double) element.get("lineNumber")).intValue() : 1; StackTraceElement stackTraceElement = new StackTraceElement(" ", methodName, fileName, lineNumber); stackTraceList.add(stackTraceElement);