From e2ad48a4ffce93136329cbbb667820cbdaeb9028 Mon Sep 17 00:00:00 2001 From: Emily Ploszaj Date: Thu, 19 Sep 2024 11:24:01 -0500 Subject: [PATCH 1/4] Add consumer proguard rules --- .../firebase-vertexai.gradle.kts | 1 + firebase-vertexai/src/consumer-rules.pro | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 firebase-vertexai/src/consumer-rules.pro diff --git a/firebase-vertexai/firebase-vertexai.gradle.kts b/firebase-vertexai/firebase-vertexai.gradle.kts index 59306df92a9..1af1abbe2fd 100644 --- a/firebase-vertexai/firebase-vertexai.gradle.kts +++ b/firebase-vertexai/firebase-vertexai.gradle.kts @@ -42,6 +42,7 @@ android { defaultConfig { minSdk = 21 targetSdk = 34 + consumerProguardFiles("consumer-rules.pro") multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } diff --git a/firebase-vertexai/src/consumer-rules.pro b/firebase-vertexai/src/consumer-rules.pro new file mode 100644 index 00000000000..7947f53cd58 --- /dev/null +++ b/firebase-vertexai/src/consumer-rules.pro @@ -0,0 +1,23 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile + +-keep class com.google.firebase.vertexai.common.** { *; } From c77819b8bfc1611afbc152feb4420603c861e91e Mon Sep 17 00:00:00 2001 From: Emily Ploszaj Date: Wed, 25 Sep 2024 11:20:30 -0500 Subject: [PATCH 2/4] Adjust proguard configuration --- .../{src => }/consumer-rules.pro | 5 +++++ .../firebase-vertexai.gradle.kts | 9 ++++++++ firebase-vertexai/proguard-rules.pro | 21 +++++++++++++++++++ 3 files changed, 35 insertions(+) rename firebase-vertexai/{src => }/consumer-rules.pro (78%) create mode 100644 firebase-vertexai/proguard-rules.pro diff --git a/firebase-vertexai/src/consumer-rules.pro b/firebase-vertexai/consumer-rules.pro similarity index 78% rename from firebase-vertexai/src/consumer-rules.pro rename to firebase-vertexai/consumer-rules.pro index 7947f53cd58..34484454708 100644 --- a/firebase-vertexai/src/consumer-rules.pro +++ b/firebase-vertexai/consumer-rules.pro @@ -21,3 +21,8 @@ #-renamesourcefileattribute SourceFile -keep class com.google.firebase.vertexai.common.** { *; } + +-dontwarn io.ktor.client.engine.mock.MockEngine$Companion +-dontwarn io.ktor.client.engine.mock.MockEngine +-dontwarn io.ktor.client.engine.mock.MockRequestHandleScope +-dontwarn io.ktor.client.engine.mock.MockUtilsKt diff --git a/firebase-vertexai/firebase-vertexai.gradle.kts b/firebase-vertexai/firebase-vertexai.gradle.kts index 1af1abbe2fd..9bdabd0f0ce 100644 --- a/firebase-vertexai/firebase-vertexai.gradle.kts +++ b/firebase-vertexai/firebase-vertexai.gradle.kts @@ -46,6 +46,15 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/firebase-vertexai/proguard-rules.pro b/firebase-vertexai/proguard-rules.pro new file mode 100644 index 00000000000..f1b424510da --- /dev/null +++ b/firebase-vertexai/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile From 7a6aca5f8c3b307ed18e7bc4e726a5a30c4529f7 Mon Sep 17 00:00:00 2001 From: Emily Ploszaj Date: Wed, 25 Sep 2024 11:51:31 -0500 Subject: [PATCH 3/4] Refactor out ktor mock to simplify rules --- firebase-vertexai/consumer-rules.pro | 5 ---- firebase-vertexai/gradle.properties | 2 +- .../firebase/vertexai/common/APIController.kt | 26 +------------------ .../firebase/vertexai/common/util/tests.kt | 7 +++-- .../google/firebase/vertexai/util/tests.kt | 7 +++-- 5 files changed, 12 insertions(+), 35 deletions(-) diff --git a/firebase-vertexai/consumer-rules.pro b/firebase-vertexai/consumer-rules.pro index 34484454708..7947f53cd58 100644 --- a/firebase-vertexai/consumer-rules.pro +++ b/firebase-vertexai/consumer-rules.pro @@ -21,8 +21,3 @@ #-renamesourcefileattribute SourceFile -keep class com.google.firebase.vertexai.common.** { *; } - --dontwarn io.ktor.client.engine.mock.MockEngine$Companion --dontwarn io.ktor.client.engine.mock.MockEngine --dontwarn io.ktor.client.engine.mock.MockRequestHandleScope --dontwarn io.ktor.client.engine.mock.MockUtilsKt diff --git a/firebase-vertexai/gradle.properties b/firebase-vertexai/gradle.properties index 248cb71a97e..e4c1653db25 100644 --- a/firebase-vertexai/gradle.properties +++ b/firebase-vertexai/gradle.properties @@ -12,5 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -version=16.0.0-beta06 +version=16.0.0-beta10 latestReleasedVersion=16.0.0-beta05 diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/APIController.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/APIController.kt index 113573bab1e..cca690df32b 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/APIController.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/APIController.kt @@ -17,15 +17,12 @@ package com.google.firebase.vertexai.common import android.util.Log -import androidx.annotation.VisibleForTesting import com.google.firebase.vertexai.common.server.FinishReason import com.google.firebase.vertexai.common.util.decodeToFlow import com.google.firebase.vertexai.common.util.fullModelName import io.ktor.client.HttpClient import io.ktor.client.call.body import io.ktor.client.engine.HttpClientEngine -import io.ktor.client.engine.mock.MockEngine -import io.ktor.client.engine.mock.respond import io.ktor.client.engine.okhttp.OkHttp import io.ktor.client.plugins.HttpTimeout import io.ktor.client.plugins.contentnegotiation.ContentNegotiation @@ -38,13 +35,9 @@ import io.ktor.client.statement.HttpResponse import io.ktor.client.statement.bodyAsChannel import io.ktor.client.statement.bodyAsText import io.ktor.http.ContentType -import io.ktor.http.HttpHeaders import io.ktor.http.HttpStatusCode import io.ktor.http.contentType -import io.ktor.http.headersOf import io.ktor.serialization.kotlinx.json.json -import io.ktor.utils.io.ByteChannel -import kotlin.time.Duration import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.flow.Flow @@ -54,6 +47,7 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import kotlinx.coroutines.withTimeout import kotlinx.serialization.json.Json +import kotlin.time.Duration internal val JSON = Json { ignoreUnknownKeys = true @@ -91,24 +85,6 @@ internal constructor( headerProvider: HeaderProvider? = null, ) : this(key, model, requestOptions, OkHttp.create(), apiClient, headerProvider) - @VisibleForTesting(otherwise = VisibleForTesting.NONE) - constructor( - key: String, - model: String, - requestOptions: RequestOptions, - apiClient: String, - headerProvider: HeaderProvider?, - channel: ByteChannel, - status: HttpStatusCode, - ) : this( - key, - model, - requestOptions, - MockEngine { respond(channel, status, headersOf(HttpHeaders.ContentType, "application/json")) }, - apiClient, - headerProvider, - ) - private val model = fullModelName(model) private val client = diff --git a/firebase-vertexai/src/test/java/com/google/firebase/vertexai/common/util/tests.kt b/firebase-vertexai/src/test/java/com/google/firebase/vertexai/common/util/tests.kt index dba31e45730..74834a89bbd 100644 --- a/firebase-vertexai/src/test/java/com/google/firebase/vertexai/common/util/tests.kt +++ b/firebase-vertexai/src/test/java/com/google/firebase/vertexai/common/util/tests.kt @@ -28,7 +28,11 @@ import com.google.firebase.vertexai.common.shared.Content import com.google.firebase.vertexai.common.shared.TextPart import io.kotest.matchers.collections.shouldNotBeEmpty import io.kotest.matchers.nulls.shouldNotBeNull +import io.ktor.client.engine.mock.MockEngine +import io.ktor.client.engine.mock.respond +import io.ktor.http.HttpHeaders import io.ktor.http.HttpStatusCode +import io.ktor.http.headersOf import io.ktor.utils.io.ByteChannel import io.ktor.utils.io.close import io.ktor.utils.io.writeFully @@ -106,10 +110,9 @@ internal fun commonTest( "super_cool_test_key", "gemini-pro", requestOptions, + MockEngine { respond(channel, status, headersOf(HttpHeaders.ContentType, "application/json")) }, TEST_CLIENT_ID, null, - channel, - status, ) CommonTestScope(channel, apiController).block() } diff --git a/firebase-vertexai/src/test/java/com/google/firebase/vertexai/util/tests.kt b/firebase-vertexai/src/test/java/com/google/firebase/vertexai/util/tests.kt index 37c0581b372..5da1d947165 100644 --- a/firebase-vertexai/src/test/java/com/google/firebase/vertexai/util/tests.kt +++ b/firebase-vertexai/src/test/java/com/google/firebase/vertexai/util/tests.kt @@ -21,7 +21,11 @@ import com.google.firebase.vertexai.common.APIController import com.google.firebase.vertexai.common.RequestOptions import io.kotest.matchers.collections.shouldNotBeEmpty import io.kotest.matchers.nulls.shouldNotBeNull +import io.ktor.client.engine.mock.MockEngine +import io.ktor.client.engine.mock.respond +import io.ktor.http.HttpHeaders import io.ktor.http.HttpStatusCode +import io.ktor.http.headersOf import io.ktor.utils.io.ByteChannel import io.ktor.utils.io.close import io.ktor.utils.io.writeFully @@ -93,10 +97,9 @@ internal fun commonTest( "super_cool_test_key", "gemini-pro", requestOptions, + MockEngine { respond(channel, status, headersOf(HttpHeaders.ContentType, "application/json")) }, TEST_CLIENT_ID, null, - channel, - status, ) val model = GenerativeModel("cool-model-name", controller = apiController) CommonTestScope(channel, model).block() From 8408e26ab82a819901f4b37bfd90e7aa1f84e2b6 Mon Sep 17 00:00:00 2001 From: Emily Ploszaj Date: Wed, 25 Sep 2024 15:25:06 -0500 Subject: [PATCH 4/4] Revert test version --- firebase-vertexai/gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/gradle.properties b/firebase-vertexai/gradle.properties index e4c1653db25..248cb71a97e 100644 --- a/firebase-vertexai/gradle.properties +++ b/firebase-vertexai/gradle.properties @@ -12,5 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -version=16.0.0-beta10 +version=16.0.0-beta06 latestReleasedVersion=16.0.0-beta05