Skip to content

Commit 885b66f

Browse files
authored
Add consumer proguard rules (#6279)
1 parent 552132b commit 885b66f

File tree

6 files changed

+68
-28
lines changed

6 files changed

+68
-28
lines changed

firebase-vertexai/consumer-rules.pro

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
22+
23+
-keep class com.google.firebase.vertexai.common.** { *; }

firebase-vertexai/firebase-vertexai.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,19 @@ android {
4242
defaultConfig {
4343
minSdk = 21
4444
targetSdk = 34
45+
consumerProguardFiles("consumer-rules.pro")
4546
multiDexEnabled = true
4647
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
4748
}
49+
buildTypes {
50+
release {
51+
isMinifyEnabled = false
52+
proguardFiles(
53+
getDefaultProguardFile("proguard-android-optimize.txt"),
54+
"proguard-rules.pro"
55+
)
56+
}
57+
}
4858
compileOptions {
4959
sourceCompatibility = JavaVersion.VERSION_1_8
5060
targetCompatibility = JavaVersion.VERSION_1_8

firebase-vertexai/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/APIController.kt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@
1717
package com.google.firebase.vertexai.common
1818

1919
import android.util.Log
20-
import androidx.annotation.VisibleForTesting
2120
import com.google.firebase.vertexai.common.server.FinishReason
2221
import com.google.firebase.vertexai.common.util.decodeToFlow
2322
import com.google.firebase.vertexai.common.util.fullModelName
2423
import com.google.firebase.vertexai.type.RequestOptions
2524
import io.ktor.client.HttpClient
2625
import io.ktor.client.call.body
2726
import io.ktor.client.engine.HttpClientEngine
28-
import io.ktor.client.engine.mock.MockEngine
29-
import io.ktor.client.engine.mock.respond
3027
import io.ktor.client.engine.okhttp.OkHttp
3128
import io.ktor.client.plugins.HttpTimeout
3229
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
@@ -39,12 +36,9 @@ import io.ktor.client.statement.HttpResponse
3936
import io.ktor.client.statement.bodyAsChannel
4037
import io.ktor.client.statement.bodyAsText
4138
import io.ktor.http.ContentType
42-
import io.ktor.http.HttpHeaders
4339
import io.ktor.http.HttpStatusCode
4440
import io.ktor.http.contentType
45-
import io.ktor.http.headersOf
4641
import io.ktor.serialization.kotlinx.json.json
47-
import io.ktor.utils.io.ByteChannel
4842
import kotlin.math.max
4943
import kotlin.time.Duration
5044
import kotlin.time.Duration.Companion.seconds
@@ -94,24 +88,6 @@ internal constructor(
9488
headerProvider: HeaderProvider? = null,
9589
) : this(key, model, requestOptions, OkHttp.create(), apiClient, headerProvider)
9690

97-
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
98-
constructor(
99-
key: String,
100-
model: String,
101-
requestOptions: RequestOptions,
102-
apiClient: String,
103-
headerProvider: HeaderProvider?,
104-
channel: ByteChannel,
105-
status: HttpStatusCode,
106-
) : this(
107-
key,
108-
model,
109-
requestOptions,
110-
MockEngine { respond(channel, status, headersOf(HttpHeaders.ContentType, "application/json")) },
111-
apiClient,
112-
headerProvider,
113-
)
114-
11591
private val model = fullModelName(model)
11692

11793
private val client =

firebase-vertexai/src/test/java/com/google/firebase/vertexai/common/util/tests.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ import com.google.firebase.vertexai.common.shared.TextPart
2828
import com.google.firebase.vertexai.type.RequestOptions
2929
import io.kotest.matchers.collections.shouldNotBeEmpty
3030
import io.kotest.matchers.nulls.shouldNotBeNull
31+
import io.ktor.client.engine.mock.MockEngine
32+
import io.ktor.client.engine.mock.respond
33+
import io.ktor.http.HttpHeaders
3134
import io.ktor.http.HttpStatusCode
35+
import io.ktor.http.headersOf
3236
import io.ktor.utils.io.ByteChannel
3337
import io.ktor.utils.io.close
3438
import io.ktor.utils.io.writeFully
@@ -106,10 +110,11 @@ internal fun commonTest(
106110
"super_cool_test_key",
107111
"gemini-pro",
108112
requestOptions,
113+
MockEngine {
114+
respond(channel, status, headersOf(HttpHeaders.ContentType, "application/json"))
115+
},
109116
TEST_CLIENT_ID,
110117
null,
111-
channel,
112-
status,
113118
)
114119
CommonTestScope(channel, apiController).block()
115120
}

firebase-vertexai/src/test/java/com/google/firebase/vertexai/util/tests.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ import com.google.firebase.vertexai.common.APIController
2121
import com.google.firebase.vertexai.type.RequestOptions
2222
import io.kotest.matchers.collections.shouldNotBeEmpty
2323
import io.kotest.matchers.nulls.shouldNotBeNull
24+
import io.ktor.client.engine.mock.MockEngine
25+
import io.ktor.client.engine.mock.respond
26+
import io.ktor.http.HttpHeaders
2427
import io.ktor.http.HttpStatusCode
28+
import io.ktor.http.headersOf
2529
import io.ktor.utils.io.ByteChannel
2630
import io.ktor.utils.io.close
2731
import io.ktor.utils.io.writeFully
@@ -93,10 +97,11 @@ internal fun commonTest(
9397
"super_cool_test_key",
9498
"gemini-pro",
9599
requestOptions,
100+
MockEngine {
101+
respond(channel, status, headersOf(HttpHeaders.ContentType, "application/json"))
102+
},
96103
TEST_CLIENT_ID,
97104
null,
98-
channel,
99-
status,
100105
)
101106
val model = GenerativeModel("cool-model-name", controller = apiController)
102107
CommonTestScope(channel, model).block()

0 commit comments

Comments
 (0)