Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOB-12845]: Add passing SDK version to the native SDK support #1022

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ commands:
type: string
default: .
steps:
- node/install:
install-yarn: true
node-version: 'v18.17.0'
- node/install-packages:
pkg-manager: yarn
# Network concurrency is set to 1 for installation from GitHub to work.
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ android/keystores/debug.keystore

# Bundle artifact
*.jsbundle
/examples/default/ios/main.jsbundle.map

# Vscode local history
.history/
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v11.13.0...dev)

### Added

- Add new strings (`StringKey.discardAlertStay` and `StringKey.discardAlertDiscard`) for overriding the discard alert buttons for consistency between iOS and Android ([#1001](https://github.com/Instabug/Instabug-React-Native/pull/1001)).
- Add a new string (`StringKey.reproStepsListItemNumberingTitle`) for overriding the repro steps list item (screen) title for consistency between iOS and Android ([#1002](https://github.com/Instabug/Instabug-React-Native/pull/1002)).
- Add support for RN version 0.73 by updating the `build.gradle` file with the `namespace` ([#1004](https://github.com/Instabug/Instabug-React-Native/pull/1004))
- Add native-side init API which can be used to catch and report startup crashes on android. ([#1012](https://github.com/Instabug/Instabug-React-Native/pull/1012))

### Deprecated

- Deprecate the old `StringKey.discardAlertCancel` and `StringKey.discardAlertAction` string keys for overriding the discard alert buttons as they had incosistent behavior between iOS and Android ([#1001](https://github.com/Instabug/Instabug-React-Native/pull/1001)).
- Deprecate the old `StringKey.reproStepsListItemNumberingTitle` string key for overriding the repro steps list item (screen) title as it had incosistent behavior between iOS and Android ([#1002](https://github.com/Instabug/Instabug-React-Native/pull/1002)).

## [11.13.0](https://github.com/Instabug/Instabug-React-Native/compare/v11.12.0...v11.13.0) (July 10, 2023)

### Changed
Expand Down
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
source "https://rubygems.org"

gem 'danger', '~> 8.6', '>= 8.6.1'
source "https://rubygems.org"
75 changes: 1 addition & 74 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,84 +1,11 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
claide (1.1.0)
claide-plugins (0.9.2)
cork
nap
open4 (~> 1.3)
colored2 (3.1.2)
cork (0.3.0)
colored2 (~> 3.1)
danger (8.6.1)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
cork (~> 0.1)
faraday (>= 0.9.0, < 2.0)
faraday-http-cache (~> 2.0)
git (~> 1.7)
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.0)
no_proxy_fix
octokit (~> 4.7)
terminal-table (>= 1, < 4)
faraday (1.10.2)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-http-cache (2.4.1)
faraday (>= 0.8)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
git (1.12.0)
addressable (~> 2.8)
rchardet (~> 1.8)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
multipart-post (2.2.3)
nap (1.1.0)
no_proxy_fix (0.1.2)
octokit (4.25.1)
faraday (>= 1, < 3)
sawyer (~> 0.9)
open4 (1.3.4)
public_suffix (5.0.0)
rchardet (1.8.0)
rexml (3.2.5)
ruby2_keywords (0.0.5)
sawyer (0.9.2)
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
unicode-display_width (2.3.0)

PLATFORMS
ruby

DEPENDENCIES
danger (~> 8.6, >= 8.6.1)

BUNDLED WITH
1.17.2
2.4.17
35 changes: 33 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,45 @@ apply from: './jacoco.gradle'
apply from: './native.gradle'
apply from: './sourcemaps.gradle'

/* (Preparing to support RN 0.73) Checking APG version to be backward-compatible with RN versions < 0.71 */
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
def shouldUseNameSpace = agpVersion >= 7
def PACKAGE_PROP = "package=\"com.instabug.reactlibrary\""
def manifestOutFile = file("${projectDir}/src/main/AndroidManifest.xml")
def manifestContent = manifestOutFile.getText()
def isManifestContentUpdated = manifestOutFile.getText() != manifestContent
def isPackageNamespaceMissing = !manifestContent.contains("$PACKAGE_PROP")

String getExtOrDefault(String name) {
def defaultPropertyKey = 'InstabugReactNative_' + name
if (rootProject.ext.has(name)) {
return rootProject.ext.get(name)
}
return project.properties['InstabugReactNative_' + name]
return project.properties[defaultPropertyKey]
}

if(shouldUseNameSpace){
manifestContent = manifestContent.replaceAll(
PACKAGE_PROP,
''
)
} else if(isPackageNamespaceMissing) {
manifestContent = manifestContent.replace(
'<manifest',
"<manifest $PACKAGE_PROP "
)
}

manifestContent.replaceAll(" ", " ")

if(isManifestContentUpdated){
manifestOutFile.write(manifestContent)
}

android {
if (shouldUseNameSpace){
namespace = "com.instabug.reactlibrary"
}
compileSdkVersion getExtOrDefault('compileSdkVersion').toInteger()
buildToolsVersion getExtOrDefault('buildToolsVersion')

Expand All @@ -37,7 +68,7 @@ dependencies {
implementation "androidx.multidex:multidex:2.0.1"
implementation 'com.facebook.react:react-native:+'

testImplementation "org.mockito:mockito-inline:3.4.0"
testImplementation "org.mockito:mockito-inline:3.12.1"
testImplementation "org.mockito:mockito-android:3.4.0"
testImplementation 'junit:junit:4.13.2'
}
3 changes: 1 addition & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.instabug.reactlibrary">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>

Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ static Map<String, Object> getAll() {
put("discardAlertMessage", Key.REPORT_DISCARD_DIALOG_BODY);
put("discardAlertCancel", Key.REPORT_DISCARD_DIALOG_NEGATIVE_ACTION);
put("discardAlertAction", Key.REPORT_DISCARD_DIALOG_POSITIVE_ACTION);
put("discardAlertStay", Key.REPORT_DISCARD_DIALOG_NEGATIVE_ACTION);
put("discardAlertDiscard", Key.REPORT_DISCARD_DIALOG_POSITIVE_ACTION);

put("addAttachmentButtonTitleStringName", Key.REPORT_ADD_ATTACHMENT_HEADER);

put("reportReproStepsDisclaimerBody", Key.REPORT_REPRO_STEPS_DISCLAIMER_BODY);
Expand All @@ -243,6 +246,7 @@ static Map<String, Object> getAll() {
put("reproStepsListDescription", Key.REPRO_STEPS_LIST_DESCRIPTION);
put("reproStepsListEmptyStateDescription", Key.REPRO_STEPS_LIST_EMPTY_STATE_DESCRIPTION);
put("reproStepsListItemTitle", Key.REPRO_STEPS_LIST_ITEM_NUMBERING_TITLE);
put("reproStepsListItemNumberingTitle", Key.REPRO_STEPS_LIST_ITEM_NUMBERING_TITLE);
put("okButtonTitle", Key.BUG_ATTACHMENT_DIALOG_OK_BUTTON);
put("audio", Key.CHATS_TYPE_AUDIO);
put("image", Key.CHATS_TYPE_IMAGE);
Expand Down
138 changes: 138 additions & 0 deletions android/src/main/java/com/instabug/reactlibrary/RNInstabug.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package com.instabug.reactlibrary;

import android.app.Application;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;

import com.instabug.apm.APM;
import com.instabug.library.Instabug;
import com.instabug.library.LogLevel;
import com.instabug.library.Platform;
import com.instabug.library.invocation.InstabugInvocationEvent;
import com.instabug.reactlibrary.utils.InstabugUtil;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class RNInstabug {

private static RNInstabug instance;
public static final String SDK_VERSION = "11.13.0";

private RNInstabug() {}


public static RNInstabug getInstance() {
if (instance == null) {
synchronized (RNInstabug.class) {
if (instance == null) {
instance = new RNInstabug();
}
}
}
return instance;
}

/**
* Initializes the SDK on the native side, which is useful for capturing startup issues specific to the native part of the app.
*
* @param application The application context.
* @param applicationToken The app's identifying token, available on your dashboard.
* @param logLevel The level of detail in logs that you want to print.
* <p>Pick one of the log levels described in {@link LogLevel}.
* default logLevel is {@link LogLevel#ERROR}</p>
* @param InvocationEvent The events that trigger the SDK's user interface.
* Choose from the available events listed in {@link InstabugInvocationEvent}.
*
* @example <p>Here's an example usage: </p>
* <blockquote><pre>
* RNInstabug.getInstance().init(
* this,
* "your_token_here",
* LogLevel.VERBOSE,
* InstabugInvocationEvent.SHAKE,
* ... // Other invocation events
* );
* </pre></blockquote>
*/
public void init(
@NonNull Application application,
@NonNull String applicationToken,
int logLevel,
@NonNull InstabugInvocationEvent... InvocationEvent
) {
try {

setBaseUrlForDeprecationLogs();
setCurrentPlatform();

new Instabug.Builder(application, applicationToken)
.setInvocationEvents(InvocationEvent)
.setSdkDebugLogsLevel(logLevel)
.build();

// Temporarily disabling APM hot launches
APM.setHotAppLaunchEnabled(false);
} catch (Exception e) {
e.printStackTrace();
}

}



/**
* Initializes the SDK on the native side, which is useful for capturing startup issues specific to the native part of the app.
*
* @param application The application context.
* @param applicationToken The app's identifying token, available on your dashboard.
* @param invocationEvent The events that trigger the SDK's user interface.
* Choose from the available events listed in {@link InstabugInvocationEvent}.
*
* @example <p>Here's an example usage: </p>
* <blockquote><pre>
* RNInstabug.getInstance().init(
* this,
* "your_token_here",
* InstabugInvocationEvent.SHAKE,
* ... // Other invocation events
* );
* </pre></blockquote>
*/
public void init(
@NonNull Application application,
@NonNull String applicationToken,
@NonNull InstabugInvocationEvent... invocationEvent
) {
init(application, applicationToken, LogLevel.ERROR, invocationEvent);
}

@VisibleForTesting
public void setCurrentPlatform() {
try {
Method method = InstabugUtil.getMethod(Class.forName("com.instabug.library.Instabug"), "setCurrentPlatform", int.class, String.class);
if (method != null) {
Log.i("IBG-CP-Bridge", "invoking setCurrentPlatform with platform: " + Platform.RN + " and version: 11.13.0");
method.invoke(null, Platform.RN, SDK_VERSION); // Second parameter is the version of the RN SDK
} else {
Log.e("IBG-CP-Bridge", "setCurrentPlatform was not found by reflection");
}
} catch (Exception e) {
e.printStackTrace();
}
}

@VisibleForTesting
public void setBaseUrlForDeprecationLogs() {
try {
Method method = InstabugUtil.getMethod(Class.forName("com.instabug.library.util.InstabugDeprecationLogger"), "setBaseUrl", String.class);
if (method != null) {
method.invoke(null, "https://docs.instabug.com/docs/react-native-sdk-migration-guide");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Loading