diff --git a/firebase-vertexai/consumer-rules.pro b/firebase-vertexai/consumer-rules.pro new file mode 100644 index 00000000000..7947f53cd58 --- /dev/null +++ b/firebase-vertexai/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.** { *; } diff --git a/firebase-vertexai/firebase-vertexai.gradle.kts b/firebase-vertexai/firebase-vertexai.gradle.kts index 59306df92a9..9bdabd0f0ce 100644 --- a/firebase-vertexai/firebase-vertexai.gradle.kts +++ b/firebase-vertexai/firebase-vertexai.gradle.kts @@ -42,9 +42,19 @@ android { defaultConfig { minSdk = 21 targetSdk = 34 + consumerProguardFiles("consumer-rules.pro") 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 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 f81fa0fc99a..bee23d52613 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,7 +17,6 @@ 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 @@ -25,8 +24,6 @@ import com.google.firebase.vertexai.type.RequestOptions 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 @@ -39,12 +36,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.math.max import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds @@ -94,24 +88,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 8a7184e9851..db42d791c30 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.TextPart import com.google.firebase.vertexai.type.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 @@ -106,10 +110,11 @@ 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 7afb202c1d6..29b7923e35b 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.type.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,11 @@ 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()