Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.google.firebase.quickstart.auth
import android.content.Intent
import com.firebase.example.internal.BaseEntryChoiceActivity
import com.firebase.example.internal.Choice
import com.google.android.gms.common.util.CollectionUtils.listOf
import com.google.firebase.quickstart.auth.java.ChooserActivity

class EntryChoiceActivity : BaseEntryChoiceActivity() {
Expand Down
4 changes: 4 additions & 0 deletions crash/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'

check.dependsOn 'assembleDebugAndroidTest'
Expand Down Expand Up @@ -33,6 +35,7 @@ configurations.all {
}

dependencies {
implementation project(':internal')
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'

Expand All @@ -43,6 +46,7 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

apply plugin: 'com.google.gms.google-services'
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.test.suitebuilder.annotation.LargeTest;
import android.widget.CheckBox;

import com.google.samples.quickstart.crash.java.MainActivity;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
5 changes: 4 additions & 1 deletion crash/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ specific language governing permissions and limitations under the License.
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".EntryChoiceActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".java.MainActivity" />
<activity android:name=".kotlin.MainActivity" />

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.google.samples.quickstart.crash

import android.content.Intent
import com.firebase.example.internal.BaseEntryChoiceActivity
import com.firebase.example.internal.Choice
import com.google.android.gms.common.util.CollectionUtils.listOf
import com.google.samples.quickstart.crash.java.MainActivity

class EntryChoiceActivity : BaseEntryChoiceActivity() {

override fun getChoices(): List<Choice> {
return listOf(
Choice(
"Java",
"Run the Firebase Crash quickstart written in Java.",
Intent(this, MainActivity::class.java)),
Choice(
"Kotlin",
"Run the Firebase Crash quickstart written in Kotlin.",
Intent(this, com.google.samples.quickstart.crash.kotlin.MainActivity::class.java))
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.samples.quickstart.crash;
package com.google.samples.quickstart.crash.java;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -24,6 +24,7 @@
import android.widget.CheckBox;

import com.crashlytics.android.Crashlytics;
import com.google.samples.quickstart.crash.R;

/**
* This Activity shows the different ways of reporting application crashes.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.google.samples.quickstart.crash.kotlin

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.crashlytics.android.Crashlytics
import com.google.samples.quickstart.crash.R
import kotlinx.android.synthetic.main.activity_main.*

/**
* This Activity shows the different ways of reporting application crashes.
* - Report non-fatal exceptions that are caught by your app.
* - Automatically Report uncaught crashes.
*
* It also shows how to add log messages to crash reports using log().
*
* Check https://console.firebase.google.com to view and analyze your crash reports.
*
* Check https://firebase.google.com/docs/crashlytics for more information on Firebase Crashlytics.
*/
class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

// Log the onCreate event, this will also be printed in logcat
Crashlytics.log(Log.VERBOSE, TAG, "onCreate")

// Add some custom values and identifiers to be included in crash reports
Crashlytics.setInt("MeaningOfLife", 42)
Crashlytics.setString("LastUIAction", "Test value")
Crashlytics.setUserIdentifier("123456789")

// Report a non-fatal exception, for demonstration purposes
Crashlytics.logException(Exception("Non-fatal exception: something went wrong!"))

// Checkbox to indicate when to catch the thrown exception.
val catchCrashCheckBox = catchCrashCheckBox

// Button that causes NullPointerException to be thrown.
val crashButton = crashButton
crashButton.setOnClickListener {
// Log that crash button was clicked.
Crashlytics.log(Log.INFO, TAG, "Crash button clicked.")

// If catchCrashCheckBox is checked catch the exception and report is using
// logException(), Otherwise throw the exception and let Crashlytics automatically
// report the crash.
if (catchCrashCheckBox.isChecked) {
try {
throw NullPointerException()
} catch (ex: NullPointerException) {
// [START crashlytics_log_and_report]
Crashlytics.log(Log.ERROR, TAG, "NPE caught!")
Crashlytics.logException(ex)
// [END crashlytics_log_and_report]
}

} else {
throw NullPointerException()
}
}

// Log that the Activity was created.
// [START crashlytics_log_event]
Crashlytics.log("Activity created")
// [END crashlytics_log_event]
}

companion object {

private val TAG = "MainActivity"
}
}
2 changes: 1 addition & 1 deletion crash/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ specific language governing permissions and limitations under the License.
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.google.samples.quickstart.crash.MainActivity">
tools:context="com.google.samples.quickstart.crash.java.MainActivity">

<ImageView
android:id="@+id/icon"
Expand Down