Skip to content

Commit

Permalink
refactor: Add F-Droid flavor without proprietary dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
timschneeb committed Feb 5, 2023
1 parent e39aa97 commit 2d897c0
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 60 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
uses: gradle/gradle-command-action@v2
with:
arguments: assemble${{ matrix.flavor }}Release
arguments: assemble${{ matrix.flavor }}FullRelease

- name: Build preview app
if: "!startsWith(github.ref, 'refs/tags/')"
uses: gradle/gradle-command-action@v2
with:
arguments: assemble${{ matrix.flavor }}Preview
arguments: assemble${{ matrix.flavor }}FullPreview

- name: Declare preview build type
if: "!startsWith(github.ref, 'refs/tags/')"
Expand All @@ -77,7 +77,7 @@ jobs:
- name: Sign APKs
uses: ilharp/sign-android-release@v1.0.4
with:
releaseDir: app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}/${{ env.BUILD_TYPE }}
releaseDir: app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}Full/${{ env.BUILD_TYPE }}
signingKey: ${{ secrets.SIGNING_KEYSTORE }}
keyAlias: ${{ secrets.KEY_ALIAS }}
keyStorePassword: ${{ secrets.KEYSTORE_PASSWORD }}
Expand All @@ -86,39 +86,39 @@ jobs:
- name: Rename build artifacts
run: |
set -e
rename -v 's/-unsigned-signed//g' app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}/${{ env.BUILD_TYPE }}/*.apk
rm app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}/${{ env.BUILD_TYPE }}/*unsigned*.apk
rename -v 's/-unsigned-signed//g' app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}Full/${{ env.BUILD_TYPE }}/*.apk
rm app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}Full/${{ env.BUILD_TYPE }}/*unsigned*.apk
ls -l
- name: Upload build artifact (universal)
uses: actions/upload-artifact@v3.1.1
with:
name: "${{ matrix.flavor }}JamesDSP-universal-preview_apk"
path: app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}/${{ env.BUILD_TYPE }}/*universal-*.apk
path: app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}Full/${{ env.BUILD_TYPE }}/*universal-*.apk

- name: Upload build artifact (x86)
uses: actions/upload-artifact@v3.1.1
with:
name: "${{ matrix.flavor }}JamesDSP-x86-preview_apk"
path: app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}/${{ env.BUILD_TYPE }}/*x86-*.apk
path: app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}Full/${{ env.BUILD_TYPE }}/*x86-*.apk

- name: Upload build artifact (x86_64)
uses: actions/upload-artifact@v3.1.1
with:
name: "${{ matrix.flavor }}JamesDSP-x86_64-preview_apk"
path: app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}/${{ env.BUILD_TYPE }}/*x86_64-*.apk
path: app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}Full/${{ env.BUILD_TYPE }}/*x86_64-*.apk

- name: Upload build artifact (armeabi-v7a)
uses: actions/upload-artifact@v3.1.1
with:
name: "${{ matrix.flavor }}JamesDSP-armeabi-v7a-preview_apk"
path: app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}/${{ env.BUILD_TYPE }}/*armeabi-v7a-*.apk
path: app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}Full/${{ env.BUILD_TYPE }}/*armeabi-v7a-*.apk

- name: Upload build artifact (arm64-v8a)
uses: actions/upload-artifact@v3.1.1
with:
name: "${{ matrix.flavor }}JamesDSP-arm64-v8a-preview_apk"
path: app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}/${{ env.BUILD_TYPE }}/*arm64-v8a-*.apk
path: app/build/outputs/apk/${{ steps.flavor.outputs.lowercase }}Full/${{ env.BUILD_TYPE }}/*arm64-v8a-*.apk

- name: Changelog
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -139,7 +139,7 @@ jobs:
name: RootlessJamesDSP ${{ env.VERSION_TAG }}
body: "${{ steps.changelog.outputs.changelog }}  "
files: |
app/build/outputs/apk/rootless/${{ env.BUILD_TYPE }}/*.apk
app/build/outputs/apk/rootlessFull/${{ env.BUILD_TYPE }}/*.apk
draft: true
prerelease: false
env:
Expand Down
33 changes: 22 additions & 11 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,18 @@ android {
}

flavorDimensions += "version"
flavorDimensions += "dependencies"
productFlavors {
create("fdroid") {
dimension = "dependencies"
buildConfigField("boolean", "FOSS_ONLY", "true")
android.defaultConfig.externalNativeBuild.cmake.arguments += "-DNO_CRASHLYTICS=1"
}
create("full") {
dimension = "dependencies"
buildConfigField("boolean", "FOSS_ONLY", "false")
}

create("rootless") {
dimension = "version"

Expand Down Expand Up @@ -137,13 +148,13 @@ android {

// Hooks to upload native symbols to crashlytics automatically
afterEvaluate {
getTasksByName("bundleRootlessRelease", false).firstOrNull()?.finalizedBy("uploadCrashlyticsSymbolFileRootlessRelease")
getTasksByName("bundleRootRelease", false).firstOrNull()?.finalizedBy("uploadCrashlyticsSymbolFileRootRelease")
getTasksByName("assembleRootlessRelease", false).firstOrNull()?.finalizedBy("uploadCrashlyticsSymbolFileRootlessRelease")
getTasksByName("assembleRootRelease", false).firstOrNull()?.finalizedBy("uploadCrashlyticsSymbolFileRootRelease")
getTasksByName("bundleRootlessFullRelease", false).firstOrNull()?.finalizedBy("uploadCrashlyticsSymbolFileRootlessFullRelease")
getTasksByName("bundleRootFullRelease", false).firstOrNull()?.finalizedBy("uploadCrashlyticsSymbolFileRootFullRelease")
getTasksByName("assembleRootlessFullRelease", false).firstOrNull()?.finalizedBy("uploadCrashlyticsSymbolFileRootlessFullRelease")
getTasksByName("assembleRootFullRelease", false).firstOrNull()?.finalizedBy("uploadCrashlyticsSymbolFileRootFullRelease")

getTasksByName("assembleRootlessPreview", false).first().finalizedBy("uploadCrashlyticsSymbolFileRootlessRelease")
getTasksByName("assembleRootPreview", false).first().finalizedBy("uploadCrashlyticsSymbolFileRootRelease")
getTasksByName("assembleRootlessFullPreview", false).first().finalizedBy("uploadCrashlyticsSymbolFileRootlessFullRelease")
getTasksByName("assembleRootFullPreview", false).first().finalizedBy("uploadCrashlyticsSymbolFileRootFullRelease")
}

dependencies {
Expand All @@ -164,16 +175,16 @@ dependencies {
implementation("androidx.preference:preference-ktx:1.2.0")
implementation("androidx.preference:preference:1.2.0")
implementation("androidx.databinding:databinding-runtime:7.3.1")
implementation("com.google.android.material:material:1.8.0-beta01")
implementation("com.google.android.material:material:1.9.0-alpha01")

// Dependency injection
implementation("io.insert-koin:koin-android:3.2.0")

// Firebase
implementation(platform("com.google.firebase:firebase-bom:30.4.1"))
implementation("com.google.firebase:firebase-analytics-ktx")
implementation("com.google.firebase:firebase-crashlytics-ktx")
implementation("com.google.firebase:firebase-crashlytics-ndk")
"fullImplementation"(platform("com.google.firebase:firebase-bom:30.4.1"))
"fullImplementation"("com.google.firebase:firebase-analytics-ktx")
"fullImplementation"("com.google.firebase:firebase-crashlytics-ktx")
"fullImplementation"("com.google.firebase:firebase-crashlytics-ndk")

// Web API client
implementation("com.google.code.gson:gson:2.10")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@file:Suppress("UNUSED_PARAMETER")

// Stubbed
object CrashlyticsImpl {
fun setCollectionEnabled(on: Boolean) {}
fun setCustomKey(key: String, value: String) {}
fun setCustomKey(key: String, value: Int) {}
fun log(msg: String) {}
fun recordException(t: Throwable) {}
fun sendUnsentReports() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase

object CrashlyticsImpl {
fun setCollectionEnabled(on: Boolean) = Firebase.crashlytics.setCrashlyticsCollectionEnabled(on)
fun setCustomKey(key: String, value: String) = Firebase.crashlytics.setCustomKey(key, value)
fun setCustomKey(key: String, value: Int) = Firebase.crashlytics.setCustomKey(key, value)
fun log(msg: String) = Firebase.crashlytics.log(msg)
fun recordException(t: Throwable) = Firebase.crashlytics.recordException(t)
fun sendUnsentReports() = Firebase.crashlytics.sendUnsentReports()
}
6 changes: 6 additions & 0 deletions app/src/main/cpp/libcrashlytics-connector/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

#include "Log.h"

#ifdef NO_CRASHLYTICS
void log::toCrashlytics(const char *level, const char* tag, const char *fmt, ...) {
// Stubbed
}
#else
// TODO clean up this abomination
void log::toCrashlytics(const char *level, const char* tag, const char *fmt, ...) {
va_list arguments;
Expand All @@ -15,3 +20,4 @@ void log::toCrashlytics(const char *level, const char* tag, const char *fmt, ...
free(buf);
va_end(arguments);
}
#endif
3 changes: 3 additions & 0 deletions app/src/main/cpp/libcrashlytics-connector/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
#define TAG "Global_JNI"
#endif

#ifndef NO_CRASHLYTICS
#include "crashlytics.h"
#endif

#include <android/log.h>
#include <memory>
#include <string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/cpp/libjamesdsp-wrapper/JamesDspWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,9 @@ void receiveLiveprogStdOut(const char *buffer, void* userData)

extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *, void *)
{
#ifndef NO_CRASHLYTICS
firebase::crashlytics::Initialize();
#endif
LOGD("JNI_OnLoad called")
return JNI_VERSION_1_6;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package me.timschneeberger.rootlessjamesdsp

import CrashlyticsImpl
import android.app.Application
import android.content.*
import android.media.audiofx.AudioEffect
import android.os.Build
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.PreferenceManager
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import fr.bipi.tressence.file.FileLoggerTree
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
Expand Down Expand Up @@ -67,7 +63,8 @@ class MainApplication : Application(), SharedPreferences.OnSharedPreferenceChang

override fun onCreate() {
Timber.plant(DebugTree())
Timber.plant(CrashReportingTree())
if(!BuildConfig.FOSS_ONLY)
Timber.plant(CrashReportingTree())
Timber.plant(FileLoggerTree.Builder()
.withFileName("application.log")
.withDirName(this.cacheDir.absolutePath)
Expand All @@ -84,21 +81,23 @@ class MainApplication : Application(), SharedPreferences.OnSharedPreferenceChang
dumpFile.delete()
}

// Soft-disable crashlytics in debug mode by default on each launch
if(BuildConfig.DEBUG) {
prefs
.edit()
.putBoolean(getString(R.string.key_share_crash_reports), false)
.apply()
}
if(!BuildConfig.FOSS_ONLY) {
// Soft-disable crashlytics in debug mode by default on each launch
if (BuildConfig.DEBUG) {
prefs
.edit()
.putBoolean(getString(R.string.key_share_crash_reports), false)
.apply()
}

val crashlytics = prefs.getBoolean(getString(R.string.key_share_crash_reports), true) && (!BuildConfig.DEBUG || BuildConfig.PREVIEW)
Timber.d("Crashlytics enabled? $crashlytics")
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(crashlytics)
val crashlytics = prefs.getBoolean(getString(R.string.key_share_crash_reports), true) && (!BuildConfig.DEBUG || BuildConfig.PREVIEW)
Timber.d("Crashlytics enabled? $crashlytics")
CrashlyticsImpl.setCollectionEnabled(crashlytics)

FirebaseCrashlytics.getInstance().setCustomKey("buildType", BuildConfig.BUILD_TYPE)
FirebaseCrashlytics.getInstance().setCustomKey("buildCommit", BuildConfig.COMMIT_SHA)
FirebaseCrashlytics.getInstance().setCustomKey("flavor", BuildConfig.FLAVOR)
CrashlyticsImpl.setCustomKey("buildType", BuildConfig.BUILD_TYPE)
CrashlyticsImpl.setCustomKey("buildCommit", BuildConfig.COMMIT_SHA)
CrashlyticsImpl.setCustomKey("flavor", BuildConfig.FLAVOR)
}

val initialPrefList = arrayOf(
R.string.key_appearance_theme_mode
Expand Down Expand Up @@ -133,15 +132,15 @@ class MainApplication : Application(), SharedPreferences.OnSharedPreferenceChang

override fun onLowMemory() {
Timber.w("onLowMemory: Running low on memory")
FirebaseCrashlytics.getInstance().setCustomKey("last_low_memory_event", SimpleDateFormat("yyyyMMdd HHmmss z", Locale.US).format(Date()))
CrashlyticsImpl.setCustomKey("last_low_memory_event", SimpleDateFormat("yyyyMMdd HHmmss z", Locale.US).format(Date()))
super.onLowMemory()
}

override fun onTrimMemory(level: Int) {
if (level >= 60)
Timber.w("onTrimMemory: Memory trim at level $level requested")
FirebaseCrashlytics.getInstance().setCustomKey("last_memory_trim_event", SimpleDateFormat("yyyyMMdd HHmmss z", Locale.US).format(Date()))
FirebaseCrashlytics.getInstance().setCustomKey("last_memory_trim_level", level)
CrashlyticsImpl.setCustomKey("last_memory_trim_event", SimpleDateFormat("yyyyMMdd HHmmss z", Locale.US).format(Date()))
CrashlyticsImpl.setCustomKey("last_memory_trim_level", level)
super.onTrimMemory(level)
}

Expand Down Expand Up @@ -175,10 +174,10 @@ class MainApplication : Application(), SharedPreferences.OnSharedPreferenceChang

override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
val safeTag = tag ?: "Unknown"
Firebase.crashlytics.log("[${priorityAsString(priority)}] $safeTag: $message")
CrashlyticsImpl.log("[${priorityAsString(priority)}] $safeTag: $message")

if (t != null && (priority == Log.ERROR || priority == Log.WARN || priority == Log.ASSERT)) {
Firebase.crashlytics.recordException(t)
CrashlyticsImpl.recordException(t)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.timschneeberger.rootlessjamesdsp.activity

import CrashlyticsImpl
import android.Manifest
import android.annotation.SuppressLint
import android.content.*
Expand All @@ -21,7 +22,6 @@ import androidx.preference.Preference
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.crashlytics.FirebaseCrashlytics
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -581,7 +581,7 @@ class MainActivity : BaseActivity() {
}

private fun quitGracefully() {
FirebaseCrashlytics.getInstance().sendUnsentReports()
CrashlyticsImpl.sendUnsentReports()
Timer().schedule(2000){
this@MainActivity.finishAndRemoveTask()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.timschneeberger.rootlessjamesdsp.fragment

import CrashlyticsImpl
import android.os.Build
import android.os.Bundle
import android.util.TypedValue
Expand All @@ -8,7 +9,6 @@ import android.view.View
import android.view.ViewGroup
import androidx.core.content.res.ResourcesCompat
import androidx.preference.*
import com.google.firebase.crashlytics.FirebaseCrashlytics
import me.timschneeberger.rootlessjamesdsp.BuildConfig
import me.timschneeberger.rootlessjamesdsp.R
import me.timschneeberger.rootlessjamesdsp.utils.AssetManagerExtensions.installPrivateAssets
Expand All @@ -27,7 +27,7 @@ class SettingsMiscFragment : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.app_misc_preferences, rootKey)

crashReports?.setOnPreferenceChangeListener { _, newValue ->
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(newValue as Boolean)
CrashlyticsImpl.setCollectionEnabled(newValue as Boolean)
true
}

Expand All @@ -37,6 +37,7 @@ class SettingsMiscFragment : PreferenceFragmentCompat() {
true
}

crashReports?.parent?.isVisible = !BuildConfig.FOSS_ONLY
debugDatabase?.parent?.isVisible = BuildConfig.DEBUG
autoStartNotify?.parent?.isVisible = BuildConfig.ROOTLESS
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package me.timschneeberger.rootlessjamesdsp.interop

import CrashlyticsImpl
import android.content.Context
import androidx.annotation.StringRes
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase

class PreferenceCache(val context: Context) {
val changedNamespaces = ArrayList<String>()
Expand Down Expand Up @@ -43,7 +42,7 @@ class PreferenceCache(val context: Context) {
}
}

Firebase.crashlytics.setCustomKey("pref_$name", current.toString())
CrashlyticsImpl.setCustomKey("pref_$name", current.toString())
cache[name] = current as Any
return current
}
Expand Down

0 comments on commit 2d897c0

Please sign in to comment.