-
Notifications
You must be signed in to change notification settings - Fork 0
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
[EMBR-3910] IOS - Allow the Embrace RN Sdk to be configured with a custom exporter #192
base: main
Are you sure you want to change the base?
Changes from all commits
277d87d
a27a2bb
74e2b92
2c6be4a
009ee6e
cb392ce
6f353cc
1b42a9b
0748517
521b29e
4a38ef5
363f001
38d73e8
681c792
a163e0b
57da81b
97ab747
d88fffd
41c58fa
5f04e98
a4390d6
763c2d5
4500408
712f6e0
d8c4c7c
86bb2ce
890ed6d
72cc4dc
5579424
3e99b07
37dfea8
4bbac7f
e10fd91
3921968
1502c9b
33e9cc3
fcbe1e2
0296ce1
8fe3573
2c28879
05a21fe
ecb3ae5
92094bc
a3d6f31
7a4937d
8046c43
e47721c
20f97a9
0324595
2977309
1e38f9c
c74716e
2dd3f61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,9 @@ Any new package under ./packages/ will get automatically picked up as a new Yarn | |
- `package.json` with name, description, main, typings (other fields will be filled by yarn constraints, version is supplied by Lerna) | ||
- `tsconfig.json` that extends from the one at the root | ||
- `README.md` | ||
- `src/` and `__tests__/` folders to contain the code for the package | ||
- `src/` and `__tests__/` folders to contain the code for the package. | ||
|
||
If an item from the previous list is missing, the package won't compile. | ||
|
||
## Adding dependencies | ||
|
||
|
@@ -25,6 +27,119 @@ are shared between multiple packages then they should be added to the Yarn const | |
This is also where we define common peerDependencies and enforce a common version. These are packages such as React Native | ||
that our packages require but that we leave to the customer to have defined as explicit dependencies. | ||
|
||
## Adding new Native Modules | ||
|
||
If new packages needs to connect with native code there are few things to have in mind. | ||
The folder structure should be something like the following: | ||
|
||
``` | ||
packages/ | ||
└── my-new-package/ | ||
├── ios/ # containing an Xcode workspace/project | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. were you able to get ios + android building using this structure without requiring a separate |
||
├── android/ # containing an Android workspace/project | ||
├── src/ | ||
│ ├── __tests__/ | ||
│ └── index.ts | ||
├── tsconfig.json | ||
├── package.json | ||
├── .eslintrc.js | ||
├── README.md | ||
└── MyNewPackage.podspec | ||
``` | ||
|
||
> Make sure the new `package.json` file list all files/folders we want to get packed during the build and pack process. Example: | ||
|
||
```json | ||
{ | ||
"files": [ | ||
"lib", | ||
"android", | ||
"ios", | ||
"NewPackageModule.podspec" | ||
], | ||
} | ||
``` | ||
|
||
This example is configured to pack lib/, android/, ios/ and NewPackageModule.podspec into the package we will publish in the future. All folders/files that should be packed and published should be listed here. If they are not there, the pack/publish process will ignore them. | ||
|
||
## iOS Native Module | ||
|
||
References are very important when developing a new iOS Standalone Native Module, we encourage developers to create new modules through Xcode to avoid any issue related to this. | ||
|
||
### Recommended steps | ||
|
||
- Open Xcode and create a new workspace. | ||
- Create a new target with the same name | ||
- Create the proper files following the [iOS Native Modules for React Native](https://reactnative.dev/docs/native-modules-ios) official documentation. | ||
|
||
This repository already contains classes using Swift. We highly recommend to keep this approach. More information about how to do it can be found in the (official documentation)[https://reactnative.dev/docs/native-modules-ios#exporting-swift]. | ||
|
||
At the end of this process the ios folder structure should contain something like the following: | ||
|
||
``` | ||
ios/ | ||
└── MyNewModule.xcworkspace | ||
└── MyNewModule/ | ||
├── MyNewModule.xcodeproj | ||
├── MyNewModule-Bridging-Header.h | ||
├── MyNewModule.m | ||
└── MyNewModule.swift | ||
``` | ||
|
||
This is the bare minimum we need to create a new iOS Native Module. | ||
|
||
> Do not forget to properly create the .podspec file outside the ios folder listing all dependencies. Also it's a good idea to check in that this file is in place after run the build and pack the new package. Without this file the new iOS Native Module won't be recognized by the application and won't be installed. | ||
|
||
## Android Native Module | ||
|
||
Also for Android Standalone Native Modules we highly recommend to start the development process using Android Studio. | ||
|
||
### Recommended steps | ||
|
||
- Open Android Studio and create a new project using Empty Activity template. | ||
- Provide a proper Project and Package Name (i.e MyNewPiece and io.embrace.mynewpiece respectively) | ||
- Choose a location to save the new project (under android/ folder), select the languaje for the project and the build configuration and finish the process. | ||
|
||
This process is going to create several folders/files with an structure like | ||
|
||
``` | ||
android/ | ||
├── src/ | ||
│ └── main/ | ||
│ ├── java/ | ||
│ │ └── io/ | ||
│ │ └── embrace/ | ||
│ │ └── mynewpiece/ | ||
│ │ └── MyNewPiece.java # we will tweak this file name in following steps | ||
│ ├── res/ | ||
│ └── AndroidManifest.xml | ||
├── gradlew.bat | ||
├── gradlew | ||
├── gradle/ | ||
│ └── wrapper/ | ||
│ ├── gradle-wrapper.properties | ||
│ └── gradle-wrapper.jar | ||
├── local.properties | ||
├── gradle.properties | ||
├── settings.gradle (or settings.gradle.kts) | ||
└── build.gradle (or build.gradle.kts) | ||
``` | ||
|
||
In order to create an (Android React Native Module)[https://reactnative.dev/docs/native-modules-android] it's also recommended to follow the official documentation | ||
|
||
Once this is done files should be the following inside `io.embrace.mynewpiece`: | ||
|
||
``` | ||
src/ | ||
└── main/ | ||
└── java/ | ||
└── io/ | ||
└── embrace/ | ||
└── myapplication/ | ||
├── MyNewPieceModule.java | ||
└── MyNewPiecePackage.java | ||
``` | ||
|
||
## Testing changes during development | ||
|
||
From the root of the project you can lint and test all packages with: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ const HomeScreen = () => { | |
"custom.property.test": "hey", | ||
"another.property": "ho", | ||
"yet.another": "hum", | ||
"rn.sdk.test": 1234567, | ||
"rn.sdk.test": "1234567", | ||
}); | ||
}, []); | ||
|
||
|
@@ -84,6 +84,22 @@ const HomeScreen = () => { | |
title="CRASH (not anonymous)" | ||
/> | ||
</ThemedView> | ||
|
||
<ThemedView style={styles.stepContainer}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks to be duplicated from above |
||
<ThemedText type="subtitle">Logs</ThemedText> | ||
<Button onPress={sendLogs} title="LOGs (war/info/error)" /> | ||
<Button onPress={sendMessage} title="Custom Message (also a log)" /> | ||
<Button onPress={handleErrorLog} title="Handled JS Exception" /> | ||
</ThemedView> | ||
|
||
<ThemedView style={styles.stepContainer}> | ||
<ThemedText type="subtitle">Crashes (Unhandled Exceptions)</ThemedText> | ||
<Button onPress={handleLogUnhandledError} title="CRASH" /> | ||
<Button | ||
onPress={handleLogUnhandledErrorNotAnonymous} | ||
title="CRASH (not anonymous)" | ||
/> | ||
</ThemedView> | ||
</ParallaxScrollView> | ||
); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has some similar information to
packages/react-native-tracer-provider/DEVELOPING.md
but is more comprehensive, I added a note to https://www.notion.so/embraceio/Strategy-Template-for-new-packages-that-have-native-code-10a7e3c99852800faf13cc70fe783f25?pvs=4 that after merging we can deletepackages/react-native-tracer-provider/DEVELOPING.md
and move any extra information from there into this file