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

Setup Flipper. #43

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,8 @@ dependencies {

implementation(libs.showkase)
ksp(libs.showkase.processor)

// Flipper, debug builds only
debugImplementation(libs.debug.flipper)
debugImplementation("com.facebook.soloader:soloader:0.10.5")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.element.android.x.flipper

import android.content.Context
import android.os.Build
import com.facebook.flipper.android.AndroidFlipperClient
import com.facebook.flipper.android.utils.FlipperUtils
import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin
import com.facebook.flipper.plugins.inspector.DescriptorMapping
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin
import com.facebook.soloader.SoLoader

class VectorFlipperProxy(
private val context: Context,
) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ganfra I am not sure that adding this class with alter ego no-op versions is the best way to handle no-op version. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say we have 2 options:

  • do not call the initializer if not debug
  • isEnabled could also check if it's debug or not ?


private val isEnabled: Boolean
get() {
// https://github.com/facebook/flipper/issues/3572
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
return false
}

return FlipperUtils.shouldEnableFlipper(context)
}

fun init() {
if (!isEnabled) return

SoLoader.init(context, false)

val client = AndroidFlipperClient.getInstance(context)
client.addPlugin(CrashReporterPlugin.getInstance())
client.addPlugin(SharedPreferencesFlipperPlugin(context))
client.addPlugin(InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()))
client.start()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.element.android.x.initializer

import android.content.Context
import androidx.startup.Initializer
import io.element.android.x.flipper.VectorFlipperProxy

class FlipperInitializer : Initializer<Unit> {

override fun create(context: Context) {
VectorFlipperProxy(context).init()
}

override fun dependencies(): List<Class<out Initializer<*>>> = emptyList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import io.element.android.x.core.di.DaggerComponentOwner
import io.element.android.x.di.AppComponent
import io.element.android.x.di.DaggerAppComponent
import io.element.android.x.initializer.CrashInitializer
import io.element.android.x.initializer.FlipperInitializer
import io.element.android.x.initializer.MatrixInitializer
import io.element.android.x.initializer.TimberInitializer

Expand All @@ -36,6 +37,7 @@ class ElementXApplication : Application(), DaggerComponentOwner {
super.onCreate()
appComponent = DaggerAppComponent.factory().create(applicationContext)
AppInitializer.getInstance(this).apply {
initializeComponent(FlipperInitializer::class.java)
initializeComponent(CrashInitializer::class.java)
initializeComponent(TimberInitializer::class.java)
initializeComponent(MatrixInitializer::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.element.android.x.flipper

import android.content.Context

/**
* No op version for nightly application.
*/
class VectorFlipperProxy(
@Suppress("UNUSED_PARAMETER") context: Context
) {
fun init() = Unit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.element.android.x.flipper

import android.content.Context

/**
* No op version for release application.
*/
class VectorFlipperProxy(
@Suppress("UNUSED_PARAMETER") context: Context
) {
fun init() = Unit
}
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ appyx = "1.0.1"
seismic = "1.0.3"
dependencycheck = "7.4.4"
stem = "2.2.3"
flipper = "0.177.0"

# DI
dagger = "2.43"
Expand Down Expand Up @@ -124,7 +125,8 @@ compose_destinations_processor = { module = "io.github.raamcosta.compose-destina
showkase = { module = "com.airbnb.android:showkase", version.ref = "showkase" }
showkase_processor = { module = "com.airbnb.android:showkase-processor", version.ref = "showkase" }
jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" }
appyx_core = {module = "com.bumble.appyx:core", version.ref = "appyx"}
appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" }
debug_flipper = { module = "com.facebook.flipper:flipper", version.ref = "flipper" }

# Di
inject = { module = "javax.inject:javax.inject", version = "1" }
Expand All @@ -148,7 +150,7 @@ ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
anvil = { id = "com.squareup.anvil", version.ref = "anvil" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
molecule = {id = "app.cash.molecule", version.ref = "molecule"}
molecule = { id = "app.cash.molecule", version.ref = "molecule" }
dependencygraph = { id = "com.savvasdalkitsis.module-dependency-graph", version.ref = "dependencygraph" }
dependencycheck = { id = "org.owasp.dependencycheck", version.ref = "dependencycheck" }
stem = { id = "com.likethesalad.stem", version.ref = "stem" }
Expand Down