fix: Fix Android build setting (#4967)

This commit is contained in:
Peter Pesti-Varga
2025-03-17 13:13:05 +01:00
committed by GitHub
parent aa910ca3f0
commit e5ce6532f5
20 changed files with 91 additions and 78 deletions

View File

@@ -11,7 +11,7 @@ android {
defaultConfig {
applicationId = "com.formbricks.demo"
minSdk = 26
minSdk = 24
targetSdk = 35
versionCode = 1
versionName = "1.0"

View File

@@ -9,7 +9,6 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Demo"
tools:targetApi="31">

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

View File

@@ -12,7 +12,7 @@ android {
compileSdk = 35
defaultConfig {
minSdk = 26
minSdk = 24
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
@@ -30,6 +30,24 @@ android {
)
}
}
packaging {
resources {
excludes += "META-INF/library_release.kotlin_module"
excludes += "classes.dex"
excludes += "**.**"
pickFirsts += "**/DataBinderMapperImpl.java"
pickFirsts += "**/DataBinderMapperImpl.class"
pickFirsts += "**/formbrickssdk/DataBinderMapperImpl.java"
pickFirsts += "**/formbrickssdk/DataBinderMapperImpl.class"
}
}
viewBinding {
enable = true
}
dataBinding {
enable = true
}
buildFeatures {
dataBinding = true
viewBinding = true
@@ -65,8 +83,6 @@ dependencies {
implementation(libs.material)
implementation(libs.timber)
implementation(libs.kotlinx.serialization.json)
implementation(libs.androidx.legacy.support.v4)
implementation(libs.androidx.lifecycle.livedata.ktx)

View File

@@ -0,0 +1,2 @@
-keep class com.formbricks.formbrickssdk.DataBinderMapperImpl { *; }
-keep class com.formbricks.formbrickssdk.Formbricks { *; }

View File

@@ -7,12 +7,11 @@ import androidx.annotation.Keep
import androidx.fragment.app.FragmentManager
import com.formbricks.formbrickssdk.api.FormbricksApi
import com.formbricks.formbrickssdk.helper.FormbricksConfig
import com.formbricks.formbrickssdk.logger.Logger
import com.formbricks.formbrickssdk.manager.SurveyManager
import com.formbricks.formbrickssdk.manager.UserManager
import com.formbricks.formbrickssdk.model.error.SDKError
import com.formbricks.formbrickssdk.webview.FormbricksFragment
import timber.log.Timber
@Keep
object Formbricks {
@@ -61,10 +60,6 @@ object Formbricks {
SurveyManager.refreshEnvironmentIfNeeded()
UserManager.syncUserStateIfNeeded()
if (loggingEnabled) {
Timber.plant(Timber.DebugTree())
}
isInitialized = true
}
@@ -79,7 +74,7 @@ object Formbricks {
*/
fun setUserId(userId: String) {
if (!isInitialized) {
Timber.e(SDKError.sdkIsNotInitialized)
Logger.e(exception = SDKError.sdkIsNotInitialized)
return
}
UserManager.set(userId)
@@ -96,7 +91,7 @@ object Formbricks {
*/
fun setAttribute(attribute: String, key: String) {
if (!isInitialized) {
Timber.e(SDKError.sdkIsNotInitialized)
Logger.e(exception = SDKError.sdkIsNotInitialized)
return
}
UserManager.addAttribute(attribute, key)
@@ -113,7 +108,7 @@ object Formbricks {
*/
fun setAttributes(attributes: Map<String, String>) {
if (!isInitialized) {
Timber.e(SDKError.sdkIsNotInitialized)
Logger.e(exception = SDKError.sdkIsNotInitialized)
return
}
UserManager.setAttributes(attributes)
@@ -130,7 +125,7 @@ object Formbricks {
*/
fun setLanguage(language: String) {
if (!isInitialized) {
Timber.e(SDKError.sdkIsNotInitialized)
Logger.e(exception = SDKError.sdkIsNotInitialized)
return
}
Formbricks.language = language
@@ -148,12 +143,12 @@ object Formbricks {
*/
fun track(action: String) {
if (!isInitialized) {
Timber.e(SDKError.sdkIsNotInitialized)
Logger.e(exception = SDKError.sdkIsNotInitialized)
return
}
if (!isInternetAvailable()) {
Timber.w(SDKError.connectionIsNotAvailable)
Logger.w(exception = SDKError.connectionIsNotAvailable)
return
}
@@ -171,7 +166,7 @@ object Formbricks {
*/
fun logout() {
if (!isInitialized) {
Timber.e(SDKError.sdkIsNotInitialized)
Logger.e(exception = SDKError.sdkIsNotInitialized)
return
}
@@ -195,7 +190,7 @@ object Formbricks {
/// Assembles the survey fragment and presents it
internal fun showSurvey(id: String) {
if (fragmentManager == null) {
Timber.e(SDKError.fragmentManagerIsNotSet)
Logger.e(exception = SDKError.fragmentManagerIsNotSet)
return
}

View File

@@ -4,9 +4,6 @@ import com.formbricks.formbrickssdk.model.environment.EnvironmentDataHolder
import com.formbricks.formbrickssdk.model.user.UserState
import com.formbricks.formbrickssdk.model.user.UserStateData
import java.text.SimpleDateFormat
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.util.Date
import java.util.Locale
import java.util.TimeZone
@@ -22,9 +19,9 @@ fun Date.dateString(): String {
fun UserStateData.lastDisplayAt(): Date? {
lastDisplayAt?.let {
try {
val formatter = DateTimeFormatter.ofPattern(dateFormatPattern)
val dateTime = LocalDateTime.parse(it, formatter)
return Date.from(dateTime.atZone(ZoneId.of("GMT")).toInstant())
val formatter = SimpleDateFormat(dateFormatPattern, Locale.getDefault())
formatter.timeZone = TimeZone.getTimeZone("UTC")
return formatter.parse(it)
} catch (e: Exception) {
return null
}
@@ -36,9 +33,9 @@ fun UserStateData.lastDisplayAt(): Date? {
fun UserState.expiresAt(): Date? {
expiresAt?.let {
try {
val formatter = DateTimeFormatter.ofPattern(dateFormatPattern)
val dateTime = LocalDateTime.parse(it, formatter)
return Date.from(dateTime.atZone(ZoneId.of("GMT")).toInstant())
val formatter = SimpleDateFormat(dateFormatPattern, Locale.getDefault())
formatter.timeZone = TimeZone.getTimeZone("UTC")
return formatter.parse(it)
} catch (e: Exception) {
return null
}
@@ -50,9 +47,9 @@ fun UserState.expiresAt(): Date? {
fun EnvironmentDataHolder.expiresAt(): Date? {
data?.expiresAt?.let {
try {
val formatter = DateTimeFormatter.ofPattern(dateFormatPattern)
val dateTime = LocalDateTime.parse(it, formatter)
return Date.from(dateTime.atZone(ZoneId.of("GMT")).toInstant())
val formatter = SimpleDateFormat(dateFormatPattern, Locale.getDefault())
formatter.timeZone = TimeZone.getTimeZone("UTC")
return formatter.parse(it)
} catch (e: Exception) {
return null
}

View File

@@ -0,0 +1,24 @@
package com.formbricks.formbrickssdk.logger
import android.util.Log
import com.formbricks.formbrickssdk.Formbricks
object Logger {
fun d(message: String) {
if (Formbricks.loggingEnabled) {
Log.d("FormbricksSDK", message)
}
}
fun e(message: String? = "Exception", exception: RuntimeException? = null) {
if (Formbricks.loggingEnabled) {
Log.e("FormbricksSDK", message, exception)
}
}
fun w(message: String? = "Warning", exception: RuntimeException? = null) {
if (Formbricks.loggingEnabled) {
Log.w("FormbricksSDK", message, exception)
}
}
}

View File

@@ -5,6 +5,7 @@ import com.formbricks.formbrickssdk.Formbricks
import com.formbricks.formbrickssdk.api.FormbricksApi
import com.formbricks.formbrickssdk.extensions.expiresAt
import com.formbricks.formbrickssdk.extensions.guard
import com.formbricks.formbrickssdk.logger.Logger
import com.formbricks.formbrickssdk.model.environment.EnvironmentDataHolder
import com.formbricks.formbrickssdk.model.environment.Survey
import com.formbricks.formbrickssdk.model.user.Display
@@ -12,12 +13,10 @@ import com.google.gson.Gson
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.Date
import java.util.Timer
import java.util.TimerTask
import java.util.concurrent.TimeUnit
/**
* The SurveyManager is responsible for managing the surveys that are displayed to the user.
@@ -58,7 +57,7 @@ object SurveyManager {
try {
Gson().fromJson(json, EnvironmentDataHolder::class.java)
} catch (e: Exception) {
Timber.tag("SurveyManager").e("Unable to retrieve environment data from the local storage.")
Logger.e("Unable to retrieve environment data from the local storage.")
null
}
}
@@ -102,7 +101,7 @@ object SurveyManager {
if (!force) {
environmentDataHolder?.expiresAt()?.let {
if (it.after(Date())) {
Timber.tag("SurveyManager").d("Environment state is still valid until $it")
Logger.d("Environment state is still valid until $it")
filterSurveys()
return
}
@@ -117,7 +116,7 @@ object SurveyManager {
hasApiError = false
} catch (e: Exception) {
hasApiError = true
Timber.tag("SurveyManager").e(e, "Unable to refresh environment state.")
Logger.e("Unable to refresh environment state.")
startErrorTimer()
}
}
@@ -148,7 +147,7 @@ object SurveyManager {
Formbricks.showSurvey(it)
}
}, Date.from(Instant.now().plusSeconds(timeout.toLong())))
}, Date(System.currentTimeMillis() + timeout.toLong() * 1000))
}
}
}
@@ -167,7 +166,7 @@ object SurveyManager {
*/
fun postResponse(surveyId: String?) {
val id = surveyId.guard {
Timber.tag("SurveyManager").e("Survey id is mandatory to set.")
Logger.e("Survey id is mandatory to set.")
return
}
@@ -179,7 +178,7 @@ object SurveyManager {
*/
fun onNewDisplay(surveyId: String?) {
val id = surveyId.guard {
Timber.tag("SurveyManager").e("Survey id is mandatory to set.")
Logger.e("Survey id is mandatory to set.")
return
}
@@ -193,7 +192,7 @@ object SurveyManager {
val date = expiresAt.guard { return }
refreshTimer.schedule(object: TimerTask() {
override fun run() {
Timber.tag("SurveyManager").d("Refreshing environment state.")
Logger.d("Refreshing environment state.")
refreshEnvironmentIfNeeded()
}
@@ -207,7 +206,7 @@ object SurveyManager {
val targetDate = Date(System.currentTimeMillis() + 1000 * 60 * REFRESH_STATE_ON_ERROR_TIMEOUT_IN_MINUTES)
refreshTimer.schedule(object: TimerTask() {
override fun run() {
Timber.tag("SurveyManager").d("Refreshing environment state after an error")
Logger.d("Refreshing environment state after an error")
refreshEnvironmentIfNeeded()
}
@@ -240,7 +239,7 @@ object SurveyManager {
}
else -> {
Timber.tag("SurveyManager").e("Invalid Display Option")
Logger.e("Invalid Display Option")
false
}
}
@@ -257,7 +256,7 @@ object SurveyManager {
val recontactDays = survey.recontactDays ?: defaultRecontactDays
if (recontactDays != null) {
val daysBetween = ChronoUnit.DAYS.between(lastDisplayedAt.toInstant(), Instant.now())
val daysBetween = TimeUnit.MILLISECONDS.toDays(Date().time - lastDisplayedAt.time)
return@filter daysBetween >= recontactDays.toInt()
}

View File

@@ -7,13 +7,13 @@ import com.formbricks.formbrickssdk.extensions.dateString
import com.formbricks.formbrickssdk.extensions.expiresAt
import com.formbricks.formbrickssdk.extensions.guard
import com.formbricks.formbrickssdk.extensions.lastDisplayAt
import com.formbricks.formbrickssdk.logger.Logger
import com.formbricks.formbrickssdk.model.user.Display
import com.formbricks.formbrickssdk.network.queue.UpdateQueue
import com.google.gson.Gson
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber
import java.util.Date
import java.util.Timer
import java.util.TimerTask
@@ -140,7 +140,7 @@ object UserManager {
SurveyManager.filterSurveys()
startSyncTimer()
} catch (e: Exception) {
Timber.tag("SurveyManager").e(e, "Unable to post survey response.")
Logger.e("Unable to post survey response.")
}
}
}

View File

@@ -1,7 +1,7 @@
package com.formbricks.formbrickssdk.network.queue
import com.formbricks.formbrickssdk.logger.Logger
import com.formbricks.formbrickssdk.manager.UserManager
import timber.log.Timber
import java.util.*
import kotlin.concurrent.timer
@@ -57,11 +57,11 @@ class UpdateQueue private constructor() {
private fun commit() {
val currentUserId = userId
if (currentUserId == null) {
Timber.d("Error: User ID is not set yet")
Logger.d("Error: User ID is not set yet")
return
}
Timber.d("UpdateQueue - commit() called on UpdateQueue with $currentUserId and $attributes")
Logger.d("UpdateQueue - commit() called on UpdateQueue with $currentUserId and $attributes")
UserManager.syncUser(currentUserId, attributes)
}

View File

@@ -6,14 +6,12 @@ import android.app.Dialog
import android.content.Intent
import android.graphics.Color
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.OpenableColumns
import android.util.Base64
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
import android.view.WindowManager
import android.webkit.ConsoleMessage
import android.webkit.WebChromeClient
@@ -25,16 +23,14 @@ import androidx.fragment.app.viewModels
import com.formbricks.formbrickssdk.Formbricks
import com.formbricks.formbrickssdk.R
import com.formbricks.formbrickssdk.databinding.FragmentFormbricksBinding
import com.formbricks.formbrickssdk.logger.Logger
import com.formbricks.formbrickssdk.manager.SurveyManager
import com.formbricks.formbrickssdk.model.javascript.FileUploadData
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.gson.JsonObject
import kotlinx.serialization.json.JsonArray
import timber.log.Timber
import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.time.Instant
import java.util.Date
import java.util.Timer
import java.util.TimerTask
@@ -58,7 +54,8 @@ class FormbricksFragment : BottomSheetDialogFragment() {
dismiss()
}
}, Date.from(Instant.now().plusSeconds(CLOSING_TIMEOUT_IN_SECONDS)))
}, Date(System.currentTimeMillis() + CLOSING_TIMEOUT_IN_SECONDS * 1000)
)
}
override fun onDisplayCreated() {
@@ -158,7 +155,7 @@ class FormbricksFragment : BottomSheetDialogFragment() {
override fun onConsoleMessage(consoleMessage: ConsoleMessage?): Boolean {
consoleMessage?.let { cm ->
val log = "[CONSOLE:${cm.messageLevel()}] \"${cm.message()}\", source: ${cm.sourceId()} (${cm.lineNumber()})"
Timber.tag("Javascript message").d(log)
Logger.d(log)
}
return super.onConsoleMessage(consoleMessage)
}
@@ -229,4 +226,3 @@ class FormbricksFragment : BottomSheetDialogFragment() {
private const val CLOSING_TIMEOUT_IN_SECONDS = 5L
}
}

View File

@@ -1,11 +1,11 @@
package com.formbricks.formbrickssdk.webview
import android.webkit.JavascriptInterface
import com.formbricks.formbrickssdk.logger.Logger
import com.formbricks.formbrickssdk.model.javascript.JsMessageData
import com.formbricks.formbrickssdk.model.javascript.EventType
import com.formbricks.formbrickssdk.model.javascript.FileUploadData
import com.google.gson.JsonParseException
import timber.log.Timber
class WebAppInterface(private val callback: WebAppCallback?) {
@@ -22,7 +22,7 @@ class WebAppInterface(private val callback: WebAppCallback?) {
*/
@JavascriptInterface
fun message(data: String) {
Timber.tag("WebAppInterface message").d(data)
Logger.d(data)
try {
val jsMessage = JsMessageData.from(data)
@@ -34,13 +34,13 @@ class WebAppInterface(private val callback: WebAppCallback?) {
EventType.ON_FILE_PICK -> { callback?.onFilePick(FileUploadData.from(data)) }
}
} catch (e: Exception) {
Timber.tag("WebAppInterface error").e(e)
Logger.e(e.message)
} catch (e: JsonParseException) {
Timber.tag("WebAppInterface error").e(e, "Failed to parse JSON message: $data")
Logger.e("Failed to parse JSON message: $data")
} catch (e: IllegalArgumentException) {
Timber.tag("WebAppInterface error").e(e, "Invalid message format: $data")
Logger.e("Invalid message format: $data")
} catch (e: Exception) {
Timber.tag("WebAppInterface error").e(e, "Unexpected error processing message: $data")
Logger.e("Unexpected error processing message: $data")
}
}

View File

@@ -27,8 +27,6 @@ lifecycleViewmodelKtx = "2.8.7"
fragmentKtx = "1.8.5"
databindingCommon = "8.8.0"
timber = "5.0.1"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
@@ -53,7 +51,6 @@ retrofit-converter-gson = { module = "com.squareup.retrofit2:converter-gson", ve
retrofit-converter-scalars = { module = "com.squareup.retrofit2:converter-scalars", version.ref = "retrofit" }
okhttp3-logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp3" }
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-legacy-support-v4 = { group = "androidx.legacy", name = "legacy-support-v4", version.ref = "legacySupportV4" }