While this file exists, create-react-app did not create a git repo within this folder. If you take a look at the file, it has taken care of ignoring a number of items (even.DSStore for Mac users): package.json. This file outlines all the settings for the React app. Name is the name of your app. React Conf is back this year and so are some new exciting announcements. News is out that Create React Native App is now officially out. If you used CRA before then you will already know that this will let you create a bootstrapped app with some simple commands.
-->The App Center SDK uses a modular architecture so you can use any or all of the services.
Let's get started with setting up App Center React Native SDK in your app to use App Center Analytics and App Center Crashes.
Before you begin, please make sure that the following prerequisites are met:
If you have already created your app in the App Center portal, you can skip this step.
Once you have created an app, you can obtain its App Secret on the Settings page on the App Center Portal. At the top right hand corner of the Settings page, click on the triple vertical dots and select Copy app secret
to get your App Secret.
The default integration of the SDK uses CocoaPods for iOS. If you are not using CocoaPods in your app, you need to integrate the React Native SDK manually for your iOS app.
Open a Terminal and navigate to the root of your React Native project, then enter the following line to add App Center Analytics and Crashes to the app:
In case you prefer yarn
over npm
, use the following command to install App Center:
The App Center SDK uses a modular approach, where you just add the modules for App Center services that you want to use. appcenter-analytics and appcenter-crashes make sense to add to almost every app, as they provide value with no additional setup required. appcenter provides general purpose App Center APIs, useful for multiple services.
Run pod install --repo-update
from iOS directory to install CocoaPods dependencies.
Create a new file with the name AppCenter-Config.plist
with the following content and replace {APP_SECRET_VALUE}
with your app secret value. Don't forget to add this file to the Xcode project (right-click the app in Xcode and click Add files to ...).
Modify the app's AppDelegate.m file to include code for starting SDK:
didFinishLaunchingWithOptions
methodCreate a new file with the name appcenter-config.json in android/app/src/main/assets/
with the following content and replace {APP_SECRET_VALUE}
with your app secret value.
Note: If the folder named assets does not exist, it should be created under 'project_root/android/app/src/main/assets'
Modify the app's res/values/strings.xml to include the following lines:
Note
If you have your React modules linked using relative path inside your Podfile but not referenced in the project, the linking script will fail because it links App Center using static pod versions. You will either have to follow the steps from the React Native troubleshooting section if you have already run the linking script, or link it yourself
Link the plugins to the React Native app by using the react-native link command.
For iOS, it will try to download the App Center SDK for iOS and macOS from CocoaPods, if you see an error like:
Please run the following command:
And then retry running react-native link
.
Note
App Center SDK does not set up mocks automatically for App Center modules during the linking process. If you are using Jest test framework in your application and experience errors caused by the App Center SDK while running tests with Jest, add the following to the jest section of package.json file (include only modules in use):
Note
Whether processing of crashes is automatic or triggered by Javascript methods, crashes are always processed after the restart of the application. Crashes cannot be processed at the time the application crashes.
Edit the project's android/app/src/main/assets/appcenter-config.json
and replace the YOUR_APP_SECRET
placeholder value with your App Center project's application secret.
Edit the project's ios/{YourAppName}/AppCenter-Config.plist
file, and replace the YOUR_APP_SECRET
placeholder value with your App Center project's application secret. If AppCenter-Config.plist already exists but not part of your Xcode project, you must add it to the Xcode project manually (right-click the app in XCode and click Add files to ...).
Do this integration, if you don't want to use CocoaPods.We strongly recommend integrating the SDK via CocoaPods as described above. Nonetheless, it's also possible to integrate the iOS native SDK manually.
Note
The latest App Center React Native SDK doesn't necessarily depend on the latest App Center iOS SDK, because the iOS SDK is updated and released before the React Native one.
The consequence is that you have to know which version of the iOS SDK the React Native SDK depends on.
Download the App Center SDK for React Native frameworks provided as a zip file and unzip it.
You will see a folder named AppCenterReactNativeShared which contains a single framework for the required React Native iOS bridge.
Download the corresponding App Center SDK for iOS frameworks provided as a zip file and unzip it.
You will see a folder called AppCenter-SDK-Apple/iOS that contains different frameworks for each App Center service. The framework called AppCenter
is required in the project as it contains code that is shared between the different modules.
[Optional] Create a subdirectory for 3rd-party libraries.
Open Finder and copy the previously unzipped AppCenter-SDK-Apple/iOS and AppCenterReactNativeShared folders into your project's folder at the location where you want it to reside.
Add the SDK frameworks to the project in Xcode:
Link AppCenter React Native plugins projects to your app's project:
Make sure the Project Navigator is visible (⌘+1).
For each AppCenter React Native plugin navigate to the folder containing source code. Paths respectively will be
/node_modules/appcenter/ios
/node_modules/appcenter-analytics/ios
/node_modules/appcenter-crashes/ios
/node_modules/appcenter-push/ios
Drag and drop .xcodeproj
files from the Finder into Xcode's Project Navigator. Typically under Libraries group.
Link libraries for AppCenter React Native plugins.Open your project settings and under General tab in the Linked Frameworks and Libraries section add new items referencing target libraries added on the previous step:
libAppCenterReactNative.a
libAppCenterReactNativeAnalytics.a
libAppCenterReactNativeCrashes.a
libAppCenterReactNativePush.a
Modify Header Search Paths to find headers from the AppCenter React Native plugins projects.Open your project settings and under Build Settings tab in the Header Search Paths section add new locations for header files:
$(SRCROOT)/../node_modules/appcenter/ios/AppCenterReactNative
$(SRCROOT)/../node_modules/appcenter-analytics/ios/AppCenterReactNativeAnalytics
$(SRCROOT)/../node_modules/appcenter-crashes/ios/AppCenterReactNativeCrashes
$(SRCROOT)/../node_modules/appcenter-push/ios/AppCenterReactNativePush
Modify the app's AppDelegate.m file to include code for starting SDK:
didFinishLaunchingWithOptions
methodCreate new file with the name AppCenter-Config.plist
with the following content and replace {APP_SECRET_VALUE}
with your app secret value. Don't forget to add this file to the XCode project (right-click the app in XCode and click Add files to ...).
Note
The next two steps are only for the apps that use React Native 0.60 and above.
Disable autolinking for React Native 0.60 and above:
dependency.platforms.ios
to null
:Modify Header Search Paths to find React Native headers from the App Center React Native plugins projects:
recursive
option: ${SRCROOT}/../../../ios/Pods/Headers
Integration steps without the react-native link
command.
Open android/settings.gradle file and insert the following lines. Include the dependencies that you want in your project. Each SDK module needs to be added as a separate dependency in this section. If you want to use App Center Analytics and Crashes, add the following lines:
Open the project's app level build.gradle file (android/app/build.gradle
) and add the following lines into dependencies
section:
Modify the app's MainApplication.java file to include code for starting SDK:
List<ReactPackage> getPackages()
methodOpen strings.xml file (android/app/src/main/res/values
) and add the following lines inside <resources></resources>
tags:
Create a new file with the name appcenter-config.json in android/app/src/main/assets/
with the following content and replace APP_SECRET_VALUE
with your app secret value.
Note
Apps that target Android 6.0 (API level 23) or higher have Auto Backup automatically enabled.
Note
If you already have a custom file with backup rule, switch to the third step.
a. Create appcenter_backup_rule.xml file in the android/app/src/main/res/xml folder.
b. Open the project's AndroidManifest.xml file. Add the android:fullBackupContent
attribute to the <application>
element. It should point to the appcenter_backup_rule.xml resource file.
c. Add the following backup rules to the appcenter_backup_rule.xml file:
Now you can build and launch your application either from command line or Xcode/Android Studio.
You may build and launch your iOS application by the following command:
Tip
You can launch it on an iOS simulator or iOS device by specifying the iOS device name in react-native run-ios --device 'myDeviceName'
.
You may build and launch your Android application by the following command:
Tip
You can launch it on an android emulator or android device by specifying the device id in react-native run-android --deviceId 'myDeviceId'
(deviceId
from adb devices
command).
For iOS, open your project's ios/{appname}.xcworkspace
or ios/{appname}.xcodeproj
file in Xcode and build from there.
Note
If you linked App Center automatically via react-native link
(as in step 3.1), you should open the project's ios/{appname}.xcworkspace
file in Xcode. Because App Center CocoaPods dependencies only works with xcworkspace
not xcodeproj
, and the ios/{appname}.xcodeproj
file won't have App Center CocoaPods dependencies linked.
For Android, import your android project in Android Studio and build from there.
You are all set to visualize Analytics and Crashes data on the portal that the SDK collects automatically. There is no additional setup required. Look at Analytics and Crashes section for APIs guides and walkthroughs to learn what App Center can do.