From 65356eee870a3cd98d266d7eb822278bff7a2488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Fri, 19 Jul 2024 16:00:57 +0200 Subject: [PATCH] feat: upgrade to the new SDK while also upgrading kotlin --- samples/android/app/build.gradle | 12 +++-- .../android/app/src/main/AndroidManifest.xml | 1 + .../java/com/example/unleash/FirstFragment.kt | 8 +-- .../java/com/example/unleash/MainActivity.kt | 4 +- .../com/example/unleash/SecondFragment.kt | 6 +-- .../com/example/unleash/UnleashApplication.kt | 50 ++++++++----------- .../src/main/res/layout/fragment_first.xml | 1 + .../src/main/res/layout/fragment_second.xml | 1 + samples/android/build.gradle | 6 +-- .../gradle/wrapper/gradle-wrapper.properties | 2 +- 10 files changed, 46 insertions(+), 45 deletions(-) diff --git a/samples/android/app/build.gradle b/samples/android/app/build.gradle index 8d87930..ec6348c 100644 --- a/samples/android/app/build.gradle +++ b/samples/android/app/build.gradle @@ -7,13 +7,13 @@ plugins { } android { - compileSdkVersion 30 + compileSdkVersion 34 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.example.unleash" minSdkVersion 21 - targetSdkVersion 30 + targetSdkVersion 31 versionCode 1 versionName "1.0" @@ -29,6 +29,11 @@ android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 + java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(8)) + } + } } kotlinOptions { jvmTarget = '1.8' @@ -51,7 +56,8 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.1.0' implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' - implementation 'io.getunleash:unleash-android-proxy-sdk:0.5.0' + //implementation 'io.getunleash:unleash-android-proxy-sdk:0.5.0' + implementation "io.getunleash:unleash-android:0.1.2-beta.1" testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/samples/android/app/src/main/AndroidManifest.xml b/samples/android/app/src/main/AndroidManifest.xml index e2bb650..56ccc86 100644 --- a/samples/android/app/src/main/AndroidManifest.xml +++ b/samples/android/app/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ android:usesCleartextTraffic="true"> diff --git a/samples/android/app/src/main/java/com/example/unleash/FirstFragment.kt b/samples/android/app/src/main/java/com/example/unleash/FirstFragment.kt index edf65b8..08ce47f 100644 --- a/samples/android/app/src/main/java/com/example/unleash/FirstFragment.kt +++ b/samples/android/app/src/main/java/com/example/unleash/FirstFragment.kt @@ -1,14 +1,14 @@ package com.example.unleash import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import com.example.unleash.databinding.FragmentFirstBinding import dagger.hilt.android.AndroidEntryPoint -import io.getunleash.UnleashClient +import io.getunleash.android.Unleash import javax.inject.Inject /** @@ -17,7 +17,7 @@ import javax.inject.Inject @AndroidEntryPoint class FirstFragment : Fragment() { - @Inject lateinit var unleashClient: UnleashClient + @Inject lateinit var unleashClient: Unleash private var _binding: FragmentFirstBinding? = null @@ -42,7 +42,7 @@ class FirstFragment : Fragment() { if (unleashClient.isEnabled("android-sdk-first-fragment-demo")) { val bundle = Bundle() val variant = unleashClient.getVariant("android-sdk-first-fragment-demo") - bundle.putString("argName", variant.payload?.getValueAsString() ?: variant.name) + bundle.putString("argName", variant.payload?.value ?: variant.name) findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment, bundle) } } diff --git a/samples/android/app/src/main/java/com/example/unleash/MainActivity.kt b/samples/android/app/src/main/java/com/example/unleash/MainActivity.kt index ca8f5f0..d302bfc 100644 --- a/samples/android/app/src/main/java/com/example/unleash/MainActivity.kt +++ b/samples/android/app/src/main/java/com/example/unleash/MainActivity.kt @@ -13,11 +13,11 @@ import androidx.navigation.ui.setupActionBarWithNavController import com.example.unleash.databinding.ActivityMainBinding import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint -import io.getunleash.UnleashClient +import io.getunleash.android.Unleash @AndroidEntryPoint class MainActivity : AppCompatActivity() { - private lateinit var unleashClient: UnleashClient + private lateinit var unleashClient: Unleash private lateinit var appBarConfiguration: AppBarConfiguration private lateinit var binding: ActivityMainBinding diff --git a/samples/android/app/src/main/java/com/example/unleash/SecondFragment.kt b/samples/android/app/src/main/java/com/example/unleash/SecondFragment.kt index f17c6af..452d38b 100644 --- a/samples/android/app/src/main/java/com/example/unleash/SecondFragment.kt +++ b/samples/android/app/src/main/java/com/example/unleash/SecondFragment.kt @@ -1,15 +1,15 @@ package com.example.unleash import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView +import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import com.example.unleash.databinding.FragmentSecondBinding import dagger.hilt.android.AndroidEntryPoint -import io.getunleash.UnleashClient +import io.getunleash.android.Unleash import javax.inject.Inject /** @@ -19,7 +19,7 @@ import javax.inject.Inject class SecondFragment : Fragment() { @Inject - lateinit var unleashClient: UnleashClient + lateinit var unleashClient: Unleash private var _binding: FragmentSecondBinding? = null diff --git a/samples/android/app/src/main/java/com/example/unleash/UnleashApplication.kt b/samples/android/app/src/main/java/com/example/unleash/UnleashApplication.kt index ad07bfb..4c760fa 100644 --- a/samples/android/app/src/main/java/com/example/unleash/UnleashApplication.kt +++ b/samples/android/app/src/main/java/com/example/unleash/UnleashApplication.kt @@ -1,16 +1,17 @@ package com.example.unleash import android.app.Application +import android.content.Context import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.HiltAndroidApp +import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent -import io.getunleash.UnleashClient -import io.getunleash.UnleashConfig -import io.getunleash.UnleashContext -import io.getunleash.cache.InMemoryToggleCache -import io.getunleash.polling.PollingModes +import io.getunleash.android.DefaultUnleash +import io.getunleash.android.Unleash +import io.getunleash.android.UnleashConfig +import io.getunleash.android.data.UnleashContext import javax.inject.Singleton import kotlin.random.Random @@ -19,8 +20,6 @@ import kotlin.random.Random @InstallIn(SingletonComponent::class) internal object UnleashClientModule { val unleashContext = UnleashContext.newBuilder() - .appName("unleash-android") - .instanceId("main-activity-unleash-demo-${Random.nextLong()}") .userId("unleash_demo_user") .sessionId(Random.nextLong().toString()) .build() @@ -28,28 +27,21 @@ internal object UnleashClientModule { @Provides @Singleton - fun unleashClient(): UnleashClient { - return UnleashClient.newBuilder() - .unleashConfig( - UnleashConfig.newBuilder() - .appName("unleash-android") - .instanceId("unleash-android-${Random.nextLong()}") - .enableMetrics() - .clientKey("default:development.5d6b7aaeb6a9165f28e91290d13ba0ed39f56f6d9e6952c642fed7cc") - .proxyUrl("https://eu.app.unleash-hosted.com/demo/api/frontend") - .pollingMode( - PollingModes.autoPoll( - autoPollIntervalSeconds = 15 - ) { - - } - ) - .metricsInterval(5000) - .build() - ) - .cache(InMemoryToggleCache()) - .unleashContext(unleashContext) - .build() + fun unleashClient( + @ApplicationContext context: Context + ): Unleash { + val unleash = DefaultUnleash( + androidContext = context, + unleashConfig = UnleashConfig.newBuilder("unleash-android") + .clientKey("default:development.5d6b7aaeb6a9165f28e91290d13ba0ed39f56f6d9e6952c642fed7cc") + .proxyUrl("https://eu.app.unleash-hosted.com/demo/api/frontend") + .pollingStrategy.interval(15000) + .metricsStrategy.interval(5000) + .build(), + unleashContext = unleashContext + ) + unleash.start() + return unleash } } diff --git a/samples/android/app/src/main/res/layout/fragment_first.xml b/samples/android/app/src/main/res/layout/fragment_first.xml index 303eed3..0d3d4c3 100644 --- a/samples/android/app/src/main/res/layout/fragment_first.xml +++ b/samples/android/app/src/main/res/layout/fragment_first.xml @@ -12,6 +12,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_first_fragment" + android:textSize="24sp" app:layout_constraintBottom_toTopOf="@id/button_first" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/samples/android/app/src/main/res/layout/fragment_second.xml b/samples/android/app/src/main/res/layout/fragment_second.xml index 16a9ab6..b03122b 100644 --- a/samples/android/app/src/main/res/layout/fragment_second.xml +++ b/samples/android/app/src/main/res/layout/fragment_second.xml @@ -12,6 +12,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_second_fragment" + android:textSize="24sp" app:layout_constraintBottom_toTopOf="@id/button_second" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/samples/android/build.gradle b/samples/android/build.gradle index 67cad28..dccd26f 100644 --- a/samples/android/build.gradle +++ b/samples/android/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.6.21' - ext.hilt_version = '2.40.1' + ext.kotlin_version = '1.8.20' + ext.hilt_version = '2.44' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:8.0.2' + classpath 'com.android.tools.build:gradle:8.5.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version" diff --git a/samples/android/gradle/wrapper/gradle-wrapper.properties b/samples/android/gradle/wrapper/gradle-wrapper.properties index 6dcc2ae..a9e70af 100644 --- a/samples/android/gradle/wrapper/gradle-wrapper.properties +++ b/samples/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Tue May 25 09:19:20 CEST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME