diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/EntryChoiceActivity.kt b/auth/app/src/main/java/com/google/firebase/quickstart/auth/EntryChoiceActivity.kt index d862254c86..c8500bd296 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/EntryChoiceActivity.kt +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/EntryChoiceActivity.kt @@ -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() { diff --git a/crash/app/build.gradle b/crash/app/build.gradle index 5405f407a3..378d01680e 100644 --- a/crash/app/build.gradle +++ b/crash/app/build.gradle @@ -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' @@ -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' @@ -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' diff --git a/crash/app/src/androidTest/java/com/google/samples/quickstart/crash/MainActivityTest.java b/crash/app/src/androidTest/java/com/google/samples/quickstart/crash/MainActivityTest.java index 83f4ab6011..72ee20c5c0 100644 --- a/crash/app/src/androidTest/java/com/google/samples/quickstart/crash/MainActivityTest.java +++ b/crash/app/src/androidTest/java/com/google/samples/quickstart/crash/MainActivityTest.java @@ -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; diff --git a/crash/app/src/main/AndroidManifest.xml b/crash/app/src/main/AndroidManifest.xml index 3c19756493..6f06a165ad 100644 --- a/crash/app/src/main/AndroidManifest.xml +++ b/crash/app/src/main/AndroidManifest.xml @@ -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"> - + + + + diff --git a/crash/app/src/main/java/com/google/samples/quickstart/crash/EntryChoiceActivity.kt b/crash/app/src/main/java/com/google/samples/quickstart/crash/EntryChoiceActivity.kt new file mode 100644 index 0000000000..fba4a711c3 --- /dev/null +++ b/crash/app/src/main/java/com/google/samples/quickstart/crash/EntryChoiceActivity.kt @@ -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 { + 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)) + ) + } + +} \ No newline at end of file diff --git a/crash/app/src/main/java/com/google/samples/quickstart/crash/MainActivity.java b/crash/app/src/main/java/com/google/samples/quickstart/crash/java/MainActivity.java similarity index 97% rename from crash/app/src/main/java/com/google/samples/quickstart/crash/MainActivity.java rename to crash/app/src/main/java/com/google/samples/quickstart/crash/java/MainActivity.java index ea700deb50..7ddc7dbac2 100644 --- a/crash/app/src/main/java/com/google/samples/quickstart/crash/MainActivity.java +++ b/crash/app/src/main/java/com/google/samples/quickstart/crash/java/MainActivity.java @@ -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; @@ -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. diff --git a/crash/app/src/main/java/com/google/samples/quickstart/crash/kotlin/MainActivity.kt b/crash/app/src/main/java/com/google/samples/quickstart/crash/kotlin/MainActivity.kt new file mode 100644 index 0000000000..0f09af9750 --- /dev/null +++ b/crash/app/src/main/java/com/google/samples/quickstart/crash/kotlin/MainActivity.kt @@ -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" + } +} diff --git a/crash/app/src/main/res/layout/activity_main.xml b/crash/app/src/main/res/layout/activity_main.xml index b7ca6f63ed..ef4e89fd95 100644 --- a/crash/app/src/main/res/layout/activity_main.xml +++ b/crash/app/src/main/res/layout/activity_main.xml @@ -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">