diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ca256ff..08df720 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -20,6 +20,25 @@ plugins { kotlin("kapt") } +// from: https://discuss.kotlinlang.org/t/use-git-hash-as-version-number-in-build-gradle-kts/19818/8 +fun String.runCommand( + workingDir: File = File("."), + timeoutAmount: Long = 60, + timeoutUnit: TimeUnit = TimeUnit.SECONDS +): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex())) + .directory(workingDir) + .redirectOutput(ProcessBuilder.Redirect.PIPE) + .redirectError(ProcessBuilder.Redirect.PIPE) + .start() + .apply { waitFor(timeoutAmount, timeoutUnit) } + .run { + val error = errorStream.bufferedReader().readText().trim() + if (error.isNotEmpty()) { + return@run "" + } + inputStream.bufferedReader().readText().trim() + } + // The application ID val appID = "com.dzeio.openhealth" @@ -32,6 +51,14 @@ val sdkMin = 21 // target SDK version val sdkTarget = 33 +val branch = "git rev-parse --abbrev-ref HEAD".runCommand(workingDir = rootDir) +var tag = "git tag -l --points-at HEAD".runCommand(workingDir = rootDir) +if (tag == "") { + tag = "not tagged" +} +val commitId = "git rev-parse HEAD".runCommand(workingDir = rootDir) + .subSequence(0, 7) + android { signingConfigs { @@ -83,28 +110,29 @@ android { "new String[]{\"" + locales.joinToString("\",\"") + "\"}" ) resourceConfigurations += locales + + buildConfigField("String", "BRANCH", "\"$branch\"") + buildConfigField("String", "TAG", "\"$tag\"") + buildConfigField("String", "COMMIT", "\"$commitId\"") } buildTypes { getByName("release") { // Slimmer version - isMinifyEnabled = false - isShrinkResources = false - isDebuggable = true + isMinifyEnabled = true + isShrinkResources = true + isDebuggable = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) + signingConfig = signingConfigs.getByName("release") } getByName("debug") { - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" - ) applicationIdSuffix = ".dev" versionNameSuffix = "-dev" isDebuggable = true diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index f3dade6..3183830 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -20,67 +20,7 @@ # hide the original source file name. #-renamesourcefileattribute SourceFile -# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and -# EnclosingMethod is required to use InnerClasses. --keepattributes Signature, InnerClasses, EnclosingMethod - -# Retrofit does reflection on method and parameter annotations. --keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations - -# Keep annotation default values (e.g., retrofit2.http.Field.encoded). --keepattributes AnnotationDefault - -# Retain service method parameters when optimizing. --keepclassmembers,allowshrinking,allowobfuscation interface * { - @retrofit2.http.* ; +# do not obfuscate fields with the annotation `@SerializedName` +-keepclassmembers,allowobfuscation class * { + @com.google.gson.annotations.SerializedName ; } - -# Ignore annotation used for build tooling. --dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement - -# Ignore JSR 305 annotations for embedding nullability information. --dontwarn javax.annotation.** - -# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath. --dontwarn kotlin.Unit - -# Top-level functions that can only be used by Kotlin. --dontwarn retrofit2.KotlinExtensions --dontwarn retrofit2.KotlinExtensions$* - -# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy -# and replaces all potential values with null. Explicitly keeping the interfaces prevents this. --if interface * { @retrofit2.http.* ; } --keep,allowobfuscation interface <1> - -# Keep inherited services. --if interface * { @retrofit2.http.* ; } --keep,allowobfuscation interface * extends <1> - -# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items). --keep,allowobfuscation,allowshrinking interface retrofit2.Call --keep,allowobfuscation,allowshrinking class retrofit2.Response - -# With R8 full mode generic signatures are stripped for classes that are not -# kept. Suspend functions are wrapped in continuations where the type argument -# is used. --keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation - - -# JSR 305 annotations are for embedding nullability information. --dontwarn javax.annotation.** - -# A resource is loaded with a relative path so the package of this class must be preserved. --adaptresourcefilenames okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz - -# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java. --dontwarn org.codehaus.mojo.animal_sniffer.* - -# OkHttp platform used only on JVM and when Conscrypt and other security providers are available. --dontwarn okhttp3.internal.platform.** --dontwarn org.conscrypt.** --dontwarn org.bouncycastle.** --dontwarn org.openjsse.** - -# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java. --dontwarn org.codehaus.mojo.animal_sniffer.* diff --git a/app/src/main/java/com/dzeio/openhealth/Application.kt b/app/src/main/java/com/dzeio/openhealth/Application.kt index 218b901..5a754ae 100644 --- a/app/src/main/java/com/dzeio/openhealth/Application.kt +++ b/app/src/main/java/com/dzeio/openhealth/Application.kt @@ -16,7 +16,6 @@ class Application : Application() { } override fun onCreate() { - val prefs = PreferenceManager.getDefaultSharedPreferences(this) // setup the CrashHandler @@ -25,7 +24,16 @@ class Application : Application() { .withPrefs(prefs) .witheErrorReporterCrashKey(R.string.error_reporter_crash) .withPrefsKey(Settings.CRASH_LAST_TIME) - .withPrefix("${BuildConfig.APPLICATION_ID} v${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})") + .withPrefix( + """ + ${BuildConfig.APPLICATION_ID} v${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE}) + + Build informations: + Commit: ${BuildConfig.COMMIT} + Branch: ${BuildConfig.BRANCH} + Tag: ${BuildConfig.TAG} + """.trimIndent() + ) .build() .setup(this) diff --git a/app/src/main/java/com/dzeio/openhealth/ui/ErrorActivity.kt b/app/src/main/java/com/dzeio/openhealth/ui/ErrorActivity.kt index 77dcfd6..43de522 100644 --- a/app/src/main/java/com/dzeio/openhealth/ui/ErrorActivity.kt +++ b/app/src/main/java/com/dzeio/openhealth/ui/ErrorActivity.kt @@ -3,13 +3,11 @@ package com.dzeio.openhealth.ui import android.content.ActivityNotFoundException import android.content.Intent import android.net.Uri -import android.os.Build import android.os.Bundle import android.os.Process import android.view.LayoutInflater import android.widget.Toast import com.dzeio.openhealth.Application -import com.dzeio.openhealth.BuildConfig import com.dzeio.openhealth.core.BaseActivity import com.dzeio.openhealth.databinding.ActivityErrorBinding import kotlin.system.exitProcess @@ -28,20 +26,8 @@ class ErrorActivity : BaseActivity() { val data = intent.getStringExtra("error") - // Get Application datas - val deviceToReport = if (Build.DEVICE.contains(Build.MANUFACTURER)) Build.DEVICE else "${Build.MANUFACTURER} ${Build.DEVICE}" - - val reportText = """ - Crash Report (Thread: ${intent?.getLongExtra("threadId", -1) ?: "unknown"}) - ${BuildConfig.APPLICATION_ID} v${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE}) - on $deviceToReport (${Build.MODEL}) running Android ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT}) - - backtrace: - - """.trimIndent() + data - // put it in the textView - binding.errorText.text = reportText + binding.errorText.text = data // Handle the Quit button binding.errorQuit.setOnClickListener { @@ -51,14 +37,15 @@ class ErrorActivity : BaseActivity() { // Handle the Email Button binding.errorSubmitEmail.setOnClickListener { - // Create Intent - val intent = Intent(Intent.ACTION_SEND) - intent.data = Uri.parse("mailto:") - intent.type = "text/plain" + val intent = Intent(Intent.ACTION_VIEW) + intent.setDataAndType( + Uri.parse("mailto:"), + "text/plain" + ) intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("report.openhealth@dzeio.com")) intent.putExtra(Intent.EXTRA_SUBJECT, "Error report for application crash") - intent.putExtra(Intent.EXTRA_TEXT, "Send Report Email\n$reportText") + intent.putExtra(Intent.EXTRA_TEXT, "Send Report Email\n$data") try { startActivity(Intent.createChooser(intent, "Send Report Email...")) @@ -69,14 +56,17 @@ class ErrorActivity : BaseActivity() { // Handle the GitHub Button binding.errorSubmitGithub.setOnClickListener { - // Build URL - val url = "https://github.com/dzeiocom/OpenHealth/issues/new?title=Application Error&body=$reportText" + val url = + "https://github.com/dzeiocom/OpenHealth/issues/new?" + + "title=Application Error&" + + "body=${data?.replace("\n", "\\n")}" try { - startActivity( - Intent(Intent.ACTION_VIEW, Uri.parse(url)) - ) + val intent = Intent(Intent.ACTION_VIEW).apply { + setData(Uri.parse(url)) + } + startActivity(intent) } catch (e: ActivityNotFoundException) { Toast.makeText(this, "No Web Browser found :(", Toast.LENGTH_LONG).show() } diff --git a/app/src/main/java/com/dzeio/openhealth/ui/food/FoodDialogViewModel.kt b/app/src/main/java/com/dzeio/openhealth/ui/food/FoodDialogViewModel.kt index 853e458..07fa6a2 100644 --- a/app/src/main/java/com/dzeio/openhealth/ui/food/FoodDialogViewModel.kt +++ b/app/src/main/java/com/dzeio/openhealth/ui/food/FoodDialogViewModel.kt @@ -21,7 +21,7 @@ class FoodDialogViewModel @Inject internal constructor( val res = foodRepository.getById(productId) val food = res.first() if (food != null) { - items.postValue(food) + items.postValue(food!!) } } } diff --git a/app/src/main/res/layout/activity_error.xml b/app/src/main/res/layout/activity_error.xml index 045108c..3633d72 100644 --- a/app/src/main/res/layout/activity_error.xml +++ b/app/src/main/res/layout/activity_error.xml @@ -1,9 +1,9 @@ @@ -11,6 +11,7 @@ android:id="@+id/textView3" style="?textAppearanceHeadline5" android:layout_width="wrap_content" + android:textAlignment="center" android:layout_height="wrap_content" android:text="@string/error_app_crash" app:layout_constraintEnd_toEndOf="parent" @@ -20,6 +21,7 @@ @@ -53,7 +56,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/report_github" - android:layout_marginStart="16dp" app:layout_constraintBaseline_toBaselineOf="@+id/error_submit_email" app:layout_constraintStart_toStartOf="parent" /> @@ -62,7 +64,6 @@ android:layout_marginBottom="16dp" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginEnd="16dp" android:text="@string/report_email" app:layout_constraintBottom_toTopOf="@+id/error_quit" app:layout_constraintEnd_toEndOf="parent" />