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

Add raven-android submodule. #261

Merged
merged 1 commit into from
Oct 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 1 addition & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,7 @@ To use it with maven, add the following repository:
```

## Android
Raven works on Android, and relies on the
[ServiceLoader](https://developer.android.com/reference/java/util/ServiceLoader.html)
system which uses the content of `META-INF/services`.
This is used to declare the `RavenFactory` implementations (to allow more
control over the automatically generated instances of `Raven`) in
`META-INF/services/com.getsentry.raven.RavenFactory`.

Unfortunately, when the APK is built, the content of `META-INF/services` in
the dependencies is lost, this prevents Raven from working properly. Some
solutions exist:

- Use [maven-android-plugin](http://simpligility.github.io/android-maven-plugin/)
which has already solved this
[problem](https://web.archive.org/web/20150523160437/http://code.google.com/p/maven-android-plugin/issues/detail?id=97)
- Manually create a `META-INF/services/com.getsentry.raven.RavenFactory` for
the project which will contain the canonical name of the implementation of
`RavenFactory` (ie. `com.getsentry.raven.DefaultRavenFactory`).
- Manually register the `RavenFactory` when the application starts:

```java
RavenFactory.registerFactory(new DefaultRavenFactory());
```
Raven works on Android, please see the [Android README](https://github.com/getsentry/raven-java/blob/raven-android-start/raven-android/README.md).

## HTTP Request Context
If the runtime environment utilizes Servlets, events that are created during
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@

<modules>
<module>raven</module>
<module>raven-android</module>
<module>raven-appengine</module>
<module>raven-log4j</module>
<module>raven-logback</module>
Expand Down
61 changes: 61 additions & 0 deletions raven-android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Raven-Android

## Installation

### Gradle (Android Studio)

In your `app/build.gradle` add: `compile 'com.getsentry.raven:raven-android:7.6.0'`

### Other dependency managers
Details in the [central Maven repository](https://search.maven.org/#artifactdetails%7Ccom.getsentry.raven%7Craven-android%7C7.6.0%7Cjar).

## Usage

### Configuration

Configure your Sentry DSN (client key) in `AndroidManifest.xml`:

```xml
<application>
<meta-data
android:name="com.getsentry.raven.android.DSN"
android:value="https://publicKey:secretKey@host:port/1?options" />
</application>
```

Your application must also have permission to access the internet in order to send
event to the Sentry server. In `AndroidManifest.xml`:

```xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
```

Then, in your application's `onCreate`, initialize the Raven client:

```java
import com.getsentry.raven.android.Raven;

// `this` is your main Activity
Raven.init(this.getApplicationContext());
```

Now you can use `Raven` to capture events in your application:

```java
// Pass a String event
Raven.capture("Error message");

// Or pass it a throwable
try {
something()
} catch (Exception e) {
Raven.capture(e);
}

// Or build an event yourself
EventBuilder eventBuilder = new EventBuilder()
.withMessage("Exception caught")
.withLevel(Event.Level.ERROR);
Raven.capture(eventBuilder.build());
```
91 changes: 91 additions & 0 deletions raven-android/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.getsentry.raven</groupId>
<artifactId>raven-all</artifactId>
<version>7.7.1-SNAPSHOT</version>
</parent>

<artifactId>raven-android</artifactId>
<packaging>jar</packaging>

<name>Raven-Java for Android</name>
<description>Android Raven-Java client.</description>

<properties>
<android.version>4.1.1.4</android.version>
<junit.version>4.12</junit.version>
<robolectric.version>2.4</robolectric.version>
<maven-ant.version>2.1.3</maven-ant.version>
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>raven</artifactId>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${android.version}</version>
<scope>provided</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.robolectric</groupId>
<artifactId>robolectric</artifactId>
<version>${robolectric.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-ant-tasks</artifactId>
<version>${maven-ant.version}</version>
<scope>test</scope>
</dependency>

<!-- Integration tests dependencies -->
<!-- Raven Test-jar does not provide test dependencies transitively -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>raven</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.getsentry.raven.android;

import android.content.Context;
import android.util.Log;
import com.getsentry.raven.*;
import com.getsentry.raven.android.event.helper.AndroidEventBuilderHelper;
import com.getsentry.raven.buffer.Buffer;
import com.getsentry.raven.buffer.DiskBuffer;
import com.getsentry.raven.dsn.Dsn;

import java.io.File;

/**
* RavenFactory that handles Android-specific construction, like taking advantage
* of the Android Context instance.
*/
public class AndroidRavenFactory extends DefaultRavenFactory {

/**
* Logger tag.
*/
public static final String TAG = AndroidRavenFactory.class.getName();
/**
* Default Buffer directory name.
*/
private static final String DEFAULT_BUFFER_DIR = "raven-buffered-events";

private Context ctx;

/**
* Construct an AndroidRavenFactory using the specified Android Context.
*
* @param ctx Android Context.
*/
public AndroidRavenFactory(Context ctx) {
this.ctx = ctx;

Log.d(TAG, "Construction of Android Raven.");
}

@Override
public com.getsentry.raven.Raven createRavenInstance(Dsn dsn) {
com.getsentry.raven.Raven ravenInstance = super.createRavenInstance(dsn);
ravenInstance.addBuilderHelper(new AndroidEventBuilderHelper(ctx));
return ravenInstance;
}

@Override
protected Buffer getBuffer(Dsn dsn) {
File bufferDir;
if (dsn.getOptions().get(BUFFER_DIR_OPTION) != null) {
bufferDir = new File(dsn.getOptions().get(BUFFER_DIR_OPTION));
} else {
bufferDir = new File(ctx.getCacheDir().getAbsolutePath(), DEFAULT_BUFFER_DIR);
}

Log.d(TAG, "Using buffer dir: " + bufferDir.getAbsolutePath());
return new DiskBuffer(bufferDir, getBufferSize(dsn));
}

}