Skip to content

Commit 574d159

Browse files
chore: custom sdk updates (#19)
* chore: custom sdk tcb * chore: custom sdk tcb * chore: custom sdk tcb * chore: custom sdk tcb * chore: custom sdk tcb
1 parent 23610fa commit 574d159

File tree

13 files changed

+185
-67
lines changed

13 files changed

+185
-67
lines changed

android/build.gradle.kts

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import com.vanniktech.maven.publish.SonatypeHost
22

33
plugins {
44
id("com.android.library")
5-
kotlin("android")
6-
kotlin("kapt")
7-
kotlin("plugin.serialization") version "2.1.0"
5+
id("kotlin-android")
6+
id("kotlin-kapt")
7+
kotlin("plugin.serialization") version "1.7.20"
88
id("org.jetbrains.dokka") version "1.9.10"
99
id("jacoco")
10-
id("com.vanniktech.maven.publish") version "0.31.0"
10+
id("com.vanniktech.maven.publish") version "0.24.0"
1111
id("org.sonarqube") version "4.4.1.3373"
12+
id("maven-publish")
1213
}
1314

1415
// Import JaCoCo configuration
@@ -25,7 +26,7 @@ jacoco {
2526

2627
android {
2728
namespace = "com.formbricks.android"
28-
compileSdk = 35
29+
compileSdk = 34
2930

3031
defaultConfig {
3132
minSdk = 24
@@ -36,29 +37,42 @@ android {
3637

3738
buildTypes {
3839
getByName("debug") {
39-
enableAndroidTestCoverage = true
40+
// enableAndroidTestCoverage = true
4041
isTestCoverageEnabled = true // For backward compatibility
4142
}
4243
release {
43-
isMinifyEnabled = true
44+
isMinifyEnabled = false
4445
proguardFiles(
4546
getDefaultProguardFile("proguard-android-optimize.txt"),
4647
"proguard-rules.pro"
4748
)
4849
}
4950
}
5051

51-
packaging {
52+
53+
packagingOptions {
5254
resources {
53-
excludes += "META-INF/library_release.kotlin_module"
54-
excludes += "classes.dex"
55-
excludes += "**.**"
56-
pickFirsts += "**/DataBinderMapperImpl.java"
57-
pickFirsts += "**/DataBinderMapperImpl.class"
58-
pickFirsts += "**/formbrickssdk/DataBinderMapperImpl.java"
59-
pickFirsts += "**/formbrickssdk/DataBinderMapperImpl.class"
55+
excludes += setOf(
56+
"META-INF/DEPENDENCIES",
57+
"META-INF/LICENSE",
58+
"META-INF/LICENSE.txt",
59+
"META-INF/license.txt",
60+
"META-INF/NOTICE",
61+
"META-INF/NOTICE.txt",
62+
"META-INF/notice.txt",
63+
"META-INF/ASL2.0",
64+
"META-INF/*.kotlin_module",
65+
"classes.dex"
66+
)
67+
pickFirsts += setOf(
68+
"**/DataBinderMapperImpl.class",
69+
"**/DataBinderMapperImpl.java",
70+
"**/formbrickssdk/DataBinderMapperImpl.java",
71+
"**/formbrickssdk/DataBinderMapperImpl.class"
72+
)
6073
}
6174
}
75+
6276
buildFeatures {
6377
dataBinding = true
6478
viewBinding = true
@@ -94,36 +108,38 @@ dependencies {
94108

95109
androidTestImplementation(libs.androidx.junit)
96110
androidTestImplementation(libs.androidx.espresso.core)
111+
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.7.20"))
97112
}
98113

99114
mavenPublishing {
100-
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
115+
// publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
116+
publishToMavenCentral()
101117

102118
signAllPublications()
103119

104120
coordinates(groupId, artifactId, version.toString())
105121

106122
pom {
107-
name = "Formbricks Android SDK"
108-
description = "Formbricks anroid SDK"
109-
url = "https://github.com/formbricks/android"
123+
name.set("Formbricks Android SDK")
124+
description.set("Formbricks anroid SDK")
125+
url.set("https://github.com/formbricks/android")
110126
licenses {
111127
license {
112-
name = "MIT License"
113-
url = "https://opensource.org/licenses/MIT"
128+
name.set("MIT License")
129+
url.set("https://opensource.org/licenses/MIT")
114130
}
115131
}
116132
developers {
117133
developer {
118-
id = "formbricks"
119-
name = "Formbricks"
120-
134+
id.set("formbricks")
135+
name.set("Formbricks")
136+
email.set("[email protected]")
121137
}
122138
}
123139
scm {
124-
connection = "scm:git:git://github.com/formbricks/android.git"
125-
developerConnection = "scm:git:ssh://github.com:formbricks/android.git"
126-
url = "https://github.com/formbricks/android"
140+
connection.set("scm:git:git://github.com/formbricks/android.git")
141+
developerConnection.set("scm:git:ssh://github.com:formbricks/android.git")
142+
url.set("https://github.com/formbricks/android")
127143
}
128144
}
129145
}
@@ -185,4 +201,10 @@ sonar {
185201

186202
tasks.sonar {
187203
dependsOn("jacocoAndroidTestReport")
204+
}
205+
206+
afterEvaluate {
207+
tasks.withType<Sign>().configureEach {
208+
enabled = false
209+
}
188210
}

android/consumer-rules.pro

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
-keep class com.formbricks.android.Formbricks { *; }
33
-keep class com.formbricks.android.helper.FormbricksConfig { *; }
44
-keep class com.formbricks.android.model.error.SDKError { *; }
5-
-keep interface com.formbricks.android.FormbricksCallback { *; }
5+
-keep interface com.formbricks.android.FormbricksCallback { *; }
6+
-keep class com.android.org.conscrypt.** { *; }
7+
-keep class javax.annotation.** { *; }
8+
-keep class org.apache.harmony.xnet.provider.jsse.** { *; }
9+
# Please add these rules to your existing keep rules in order to suppress warnings.
10+
# This is generated automatically by the Android Gradle plugin.
11+
-dontwarn java.lang.invoke.StringConcatFactory

android/proguard-rules.pro

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
-keep class com.formbricks.android.Formbricks { *; }
3636
-keep class com.formbricks.android.helper.FormbricksConfig { *; }
3737
-keep class com.formbricks.android.model.error.SDKError { *; }
38+
-keep interface com.formbricks.android.FormbricksCallback { *; }
3839

3940
# Keep StringConcatFactory and related classes
4041
-keep class java.lang.invoke.StringConcatFactory { *; }
@@ -44,4 +45,11 @@
4445
-dontwarn java.lang.invoke.StringConcatFactory
4546

4647
# Keep DataBinding classes
47-
-keep class androidx.databinding.** { *; }
48+
-keep class androidx.databinding.** { *; }
49+
50+
-keep class com.android.org.conscrypt.** { *; }
51+
-keep class javax.annotation.** { *; }
52+
-keep class org.apache.harmony.xnet.provider.jsse.** { *; }
53+
# Please add these rules to your existing keep rules in order to suppress warnings.
54+
# This is generated automatically by the Android Gradle plugin.
55+
-dontwarn java.lang.invoke.StringConcatFactory

android/src/main/java/com/formbricks/android/Formbricks.kt

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,21 @@ import com.formbricks.android.helper.FormbricksConfig
1010
import com.formbricks.android.logger.Logger
1111
import com.formbricks.android.manager.SurveyManager
1212
import com.formbricks.android.manager.UserManager
13+
import com.formbricks.android.model.enums.SuccessType
1314
import com.formbricks.android.model.error.SDKError
1415
import com.formbricks.android.webview.FormbricksFragment
1516
import java.lang.RuntimeException
1617

18+
@Keep
19+
interface FormbricksCallback {
20+
fun onSurveyStarted()
21+
fun onSurveyFinished()
22+
fun onSurveyClosed()
23+
fun onPageCommitVisible()
24+
fun onError(error: Exception)
25+
fun onSuccess(successType: SuccessType)
26+
}
27+
1728
@Keep
1829
object Formbricks {
1930
internal lateinit var applicationContext: Context
@@ -22,9 +33,12 @@ object Formbricks {
2233
internal lateinit var appUrl: String
2334
internal var language: String = "default"
2435
internal var loggingEnabled: Boolean = true
36+
internal var autoDismissErrors: Boolean = true
2537
private var fragmentManager: FragmentManager? = null
2638
internal var isInitialized = false
2739

40+
var callback: FormbricksCallback? = null
41+
2842
/**
2943
* Initializes the Formbricks SDK with the given [Context] config [FormbricksConfig].
3044
* This method is mandatory to be called, and should be only once per application lifecycle.
@@ -48,6 +62,7 @@ object Formbricks {
4862
fun setup(context: Context, config: FormbricksConfig, forceRefresh: Boolean = false) {
4963
if (isInitialized && !forceRefresh) {
5064
val error = SDKError.sdkIsAlreadyInitialized
65+
callback?.onError(error)
5166
Logger.e(error)
5267
return
5368
}
@@ -58,7 +73,7 @@ object Formbricks {
5873
environmentId = config.environmentId
5974
loggingEnabled = config.loggingEnabled
6075
fragmentManager = config.fragmentManager
61-
76+
autoDismissErrors = config.autoDismissErrors
6277
config.userId?.let { UserManager.set(it) }
6378
config.attributes?.let { UserManager.setAttributes(it) }
6479
config.attributes?.get("language")?.let { UserManager.setLanguage(it) }
@@ -79,15 +94,17 @@ object Formbricks {
7994
* ```
8095
*
8196
*/
82-
fun setUserId(userId: String) {
97+
fun setUserId(userId: String, allowOverrideUserId: Boolean = false) {
8398
if (!isInitialized) {
8499
val error = SDKError.sdkIsNotInitialized
100+
callback?.onError(error)
85101
Logger.e(error)
86102
return
87103
}
88104

89-
if(UserManager.userId != null) {
105+
if (UserManager.userId != null && !allowOverrideUserId) {
90106
val error = RuntimeException("A userId is already set ${UserManager.userId} - please call logout first before setting a new one")
107+
callback?.onError(error)
91108
Logger.e(error)
92109
return
93110
}
@@ -107,6 +124,7 @@ object Formbricks {
107124
fun setAttribute(attribute: String, key: String) {
108125
if (!isInitialized) {
109126
val error = SDKError.sdkIsNotInitialized
127+
callback?.onError(error)
110128
Logger.e(error)
111129
return
112130
}
@@ -125,6 +143,7 @@ object Formbricks {
125143
fun setAttributes(attributes: Map<String, String>) {
126144
if (!isInitialized) {
127145
val error = SDKError.sdkIsNotInitialized
146+
callback?.onError(error)
128147
Logger.e(error)
129148
return
130149
}
@@ -143,6 +162,7 @@ object Formbricks {
143162
fun setLanguage(language: String) {
144163
if (!isInitialized) {
145164
val error = SDKError.sdkIsNotInitialized
165+
callback?.onError(error)
146166
Logger.e(error)
147167
return
148168
}
@@ -159,20 +179,22 @@ object Formbricks {
159179
* ```
160180
*
161181
*/
162-
fun track(action: String) {
182+
fun track(action: String, hiddenFields: Map<String, Any>? = null) {
163183
if (!isInitialized) {
164184
val error = SDKError.sdkIsNotInitialized
185+
callback?.onError(error)
165186
Logger.e(error)
166187
return
167188
}
168189

169190
if (!isInternetAvailable()) {
170191
val error = SDKError.connectionIsNotAvailable
192+
callback?.onError(error)
171193
Logger.e(error)
172194
return
173195
}
174196

175-
SurveyManager.track(action)
197+
SurveyManager.track(action = action, hiddenFields = hiddenFields)
176198
}
177199

178200
/**
@@ -187,10 +209,12 @@ object Formbricks {
187209
fun logout() {
188210
if (!isInitialized) {
189211
val error = SDKError.sdkIsNotInitialized
212+
callback?.onError(error)
190213
Logger.e(error)
191214
return
192215
}
193216

217+
callback?.onSuccess(SuccessType.LOGOUT_SUCCESS)
194218
UserManager.logout()
195219
}
196220

@@ -209,15 +233,16 @@ object Formbricks {
209233
}
210234

211235
/// Assembles the survey fragment and presents it
212-
internal fun showSurvey(id: String) {
236+
internal fun showSurvey(id: String, hiddenFields: Map<String, Any>? = null) {
213237
if (fragmentManager == null) {
214238
val error = SDKError.fragmentManagerIsNotSet
239+
callback?.onError(error)
215240
Logger.e(error)
216241
return
217242
}
218243

219244
fragmentManager?.let {
220-
FormbricksFragment.show(it, surveyId = id)
245+
FormbricksFragment.show(it, surveyId = id, hiddenFields = hiddenFields)
221246
}
222247
}
223248

android/src/main/java/com/formbricks/android/helper/FormbricksConfig.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ class FormbricksConfig private constructor(
1515
val userId: String?,
1616
val attributes: Map<String,String>?,
1717
val loggingEnabled: Boolean,
18-
val fragmentManager: FragmentManager?
18+
val fragmentManager: FragmentManager?,
19+
val autoDismissErrors: Boolean = true,
1920
) {
2021
class Builder(private val appUrl: String, private val environmentId: String) {
2122
private var userId: String? = null
2223
private var attributes: MutableMap<String,String> = mutableMapOf()
2324
private var loggingEnabled = false
2425
private var fragmentManager: FragmentManager? = null
26+
private var autoDismissErrors = true
2527

2628
fun setUserId(userId: String): Builder {
2729
this.userId = userId
@@ -48,14 +50,20 @@ class FormbricksConfig private constructor(
4850
return this
4951
}
5052

53+
fun setAutoDismissErrors(autoDismissErrors: Boolean): Builder {
54+
this.autoDismissErrors = autoDismissErrors
55+
return this
56+
}
57+
5158
fun build(): FormbricksConfig {
5259
return FormbricksConfig(
5360
appUrl = appUrl,
5461
environmentId = environmentId,
5562
userId = userId,
5663
attributes = attributes,
5764
loggingEnabled = loggingEnabled,
58-
fragmentManager = fragmentManager
65+
fragmentManager = fragmentManager,
66+
autoDismissErrors = autoDismissErrors
5967
)
6068
}
6169
}

0 commit comments

Comments
 (0)