Skip to content

Commit

Permalink
Merge pull request #27 from capacitor-community/crashes-android-support
Browse files Browse the repository at this point in the history
Crashes android support
  • Loading branch information
johnborges authored Sep 16, 2021
2 parents e0d2180 + 38ebfe5 commit f76f6f3
Show file tree
Hide file tree
Showing 73 changed files with 1,259 additions and 366 deletions.
4 changes: 4 additions & 0 deletions appcenter-crashes/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 0.4.0

* adding Android support

## 0.3.1

* Update `Appcenter/Analytics` to 4.2.0
Expand Down
8 changes: 4 additions & 4 deletions appcenter-crashes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ Check if Crashes is enabled or not.
### setEnabled(...)

```typescript
setEnabled(options: { shouldEnable: boolean; }) => Promise<void>
setEnabled(options: { enable: boolean; }) => Promise<void>
```

You can enable and disable App Center Crashes at runtime. If you disable it, the SDK won't do any crash reporting for the app.
The state is persisted in the device's storage across application launches.

| Param | Type |
| ------------- | --------------------------------------- |
| **`options`** | <code>{ shouldEnable: boolean; }</code> |
| Param | Type |
| ------------- | --------------------------------- |
| **`options`** | <code>{ enable: boolean; }</code> |

**Since:** 0.1.0

Expand Down
12 changes: 7 additions & 5 deletions appcenter-crashes/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ext {
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.12'
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.1.0'
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.1'
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.2.0'
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0'
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
}

buildscript {
Expand All @@ -11,7 +11,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.android.tools.build:gradle:4.2.1'
}
}

Expand Down Expand Up @@ -49,6 +49,8 @@ repositories {


dependencies {
api 'com.microsoft.appcenter:appcenter-crashes:4.2.0'
api 'com.microsoft.appcenter.reactnative:appcenter-react-native:4.2.0' // change to own version
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':capacitor-android')
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion appcenter-crashes/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.plugins.example">
package="com.getcapacitor.plugin.appcenter.crashes">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.getcapacitor.plugin.appcenter.crashes;

import com.microsoft.appcenter.AppCenter;
import com.microsoft.appcenter.crashes.Crashes;

public class CrashesBase {

public void enable(boolean enabled) {
Crashes.setEnabled(enabled).get();
}

public boolean isEnabled() {
return Crashes.isEnabled().get();
}

public void start() {
if (AppCenter.isConfigured()) {
AppCenter.start(Crashes.class);
}
}

public void generateTestCrash() {
Crashes.generateTestCrash();
}

public boolean hasReceivedMemoryWarningInLastSession() {
return Crashes.hasReceivedMemoryWarningInLastSession().get();
}

public boolean hasCrashedInLastSession() {
return Crashes.hasCrashedInLastSession().get();
}

// public void lastSessionCrashReport() {
// return Crashes.lastSessionCrashReport().get()
// }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.getcapacitor.plugin.appcenter.crashes;

import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;

import com.microsoft.appcenter.AppCenter;
import com.microsoft.appcenter.crashes.Crashes;
import com.microsoft.appcenter.reactnative.shared.AppCenterReactNativeShared;

@CapacitorPlugin(name = "Crashes")
public class CrashesPlugin extends Plugin {

private CrashesBase implementation = new CrashesBase();

@Override
public void load() {
AppCenterReactNativeShared.configureAppCenter(this.getActivity().getApplication());
implementation.start();
}

@PluginMethod(returnType = PluginMethod.RETURN_NONE)
public void setEnable(PluginCall call) {
implementation.enable(call.getBoolean("enable", false));
call.resolve();
}

@PluginMethod
public void isEnabled(PluginCall call) {
JSObject ret = new JSObject();
ret.put("value", implementation.isEnabled());
call.resolve(ret);
}

@PluginMethod(returnType = PluginMethod.RETURN_NONE)
public void generateTestCrash(PluginCall call) {
implementation.generateTestCrash();
call.resolve();
}

@PluginMethod
public void hasReceivedMemoryWarningInLastSession(PluginCall call) {
JSObject ret = new JSObject();
ret.put("value", implementation.hasReceivedMemoryWarningInLastSession());
call.resolve(ret);
}

@PluginMethod
public void hasCrashedInLastSession(PluginCall call) {
JSObject ret = new JSObject();
ret.put("value", implementation.hasCrashedInLastSession());
call.resolve(ret);
}

@PluginMethod
public void lastSessionCrashReport(PluginCall call) {
call.unimplemented("Not yet implemented on Android.");
}

}

This file was deleted.

This file was deleted.

10 changes: 5 additions & 5 deletions appcenter-crashes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@capacitor-community/appcenter-crashes",
"version": "0.3.1",
"version": "0.4.0",
"description": "Capacitor plugin for Microsoft's App Center Crashes",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -49,10 +49,10 @@
"prepublishOnly": "npm run build"
},
"devDependencies": {
"@capacitor/android": "3.0.0",
"@capacitor/core": "3.0.0",
"@capacitor/android": "3.2.2",
"@capacitor/core": "3.2.2",
"@capacitor/docgen": "^0.0.17",
"@capacitor/ios": "3.0.0",
"@capacitor/ios": "3.2.2",
"@ionic/eslint-config": "^0.3.0",
"@ionic/prettier-config": "^1.0.1",
"@ionic/swiftlint-config": "^1.1.2",
Expand All @@ -65,7 +65,7 @@
"typescript": "~4.0.3"
},
"peerDependencies": {
"@capacitor/core": "3.0.0"
"@capacitor/core": "3.2.2"
},
"prettier": "@ionic/prettier-config",
"swiftlint": "@ionic/swiftlint-config",
Expand Down
6 changes: 3 additions & 3 deletions appcenter-crashes/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ export interface CrashesPlugin {
/**
* You can enable and disable App Center Crashes at runtime. If you disable it, the SDK won't do any crash reporting for the app.
* The state is persisted in the device's storage across application launches.
* @param {shouldEnable: boolean} options
* @param {enable: boolean} options
* @since 0.1.0
* @example
* import Crashes from '@capacitor-community/appcenter-crashes';
*
* await Crashes.enable({shouldEnable: true});
* await Crashes.enable({enable: true});
*/
setEnabled(options: {shouldEnable: boolean}): Promise<void>;
setEnabled(options: {enable: boolean}): Promise<void>;

/**
* Generate a test crash for easy testing of the SDK. This API can only be used in test/beta apps and won't do anything in production apps.
Expand Down
96 changes: 96 additions & 0 deletions example/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Using Android gitignore template: https://github.com/github/gitignore/blob/HEAD/Android.gitignore

# Built application files
*.apk
*.aar
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
.cxx/

# Google Services (e.g. APIs or Firebase)
# google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/

# Android Profiling
*.hprof

# Cordova plugins for Capacitor
capacitor-cordova-android-plugins

# Copied web assets
app/src/main/assets/public
2 changes: 2 additions & 0 deletions example/android/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build/*
!/build/.npmkeep
Loading

0 comments on commit f76f6f3

Please sign in to comment.