supabase-kt
supabase-kt copied to clipboard
[Bug]: Im getting an error when I try to install Storage in hilt.
General Info
- [X] I checked for similar bug report
- [X] I am using the latest version
- [X] I checked the troubleshooting page for similar problems
- [X] I enabled logging and checked the logs
Version(s)
2.1.5
Target(s)
1.12.0
What happened? (include your code)
The sdk cannot install storage client when using hilt and I checked for mutliple projects and this thing happens the same. The app is crashing . Here is the code snippet of it. ` package com.bharath.kiet_student_app.di
import com.bharath.kiet_student_app.BuildConfig import com.bharath.kiet_student_app.data.repository.SupabaseRepositoryImpl import com.bharath.kiet_student_app.domain.repository.SupabaseRepository import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import io.github.jan.supabase.SupabaseClient import io.github.jan.supabase.createSupabaseClient import io.github.jan.supabase.postgrest.Postgrest import io.github.jan.supabase.postgrest.postgrest
import io.github.jan.supabase.storage.Storage import io.github.jan.supabase.storage.storage import javax.inject.Singleton
/**
- @property SupaModule Module for creating instances of supabase class components
- @sample SupaModule.provideSupabaseRepository
- @see AppModule for better documentation as methods are very similar */
@InstallIn(SingletonComponent::class) @Module object SupaModule {
@Provides
@Singleton
fun provideSupabaseClient(): SupabaseClient {
return createSupabaseClient(
BuildConfig.SUPABASE_PROJECT_URL,
BuildConfig.SUPABASE_API_ANON_KEY,
) {
install(Storage)
install(Postgrest)
}
}
@Provides
@Singleton
fun provideStorageClientSupaBase(supabaseClient: SupabaseClient): Storage {
return supabaseClient.storage
}
@Provides
@Singleton
fun providePostgrestClient(supabaseClient: SupabaseClient): Postgrest {
return supabaseClient.postgrest
}
@Provides
@Singleton
fun provideSupabaseRepository(supabaseClient: SupabaseClient): SupabaseRepository {
return SupabaseRepositoryImpl(supabaseClient.postgrest, supabaseClient.storage)
}
} ` Please fix this issue ASAP.
Steps To Reproduce (optional)
Please
Relevant log output (optional)
java.lang.RuntimeException: Unable to create application com.bharath.kietadminapp.AdminApp: java.lang.NullPointerException
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7926)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2646)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:328)
at android.app.ActivityThread.main(ActivityThread.java:9220)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
Caused by: java.lang.NullPointerException
at com.russhwolf.settings.NoArgKt.Settings(NoArg.kt:32)
at io.github.jan.supabase.storage.resumable.SettingsResumableCache.<init>(SettingsResumableCache.kt:15)
at io.github.jan.supabase.storage.resumable.SettingsResumableCacheKt.createDefaultResumableCache(SettingsResumableCache.kt:55)
at io.github.jan.supabase.storage.Storage$Config$Resumable.<init>(Storage.kt:129)
at io.github.jan.supabase.storage.Storage$Config.<init>(Storage.kt:120)
at io.github.jan.supabase.storage.Storage$Companion.createConfig(Storage.kt:170)
at io.github.jan.supabase.storage.Storage$Companion.createConfig(Storage.kt:156)
at io.github.jan.supabase.SupabaseClientBuilder.install(SupabaseClientBuilder.kt:100)
at io.github.jan.supabase.SupabaseClientBuilder.install$default(SupabaseClientBuilder.kt:99)
at com.bharath.kietadminapp.common.di.AppModule.provideSupabaseClient(AppModule.kt:46)
at com.bharath.kietadminapp.common.di.AppModule_ProvideSupabaseClientFactory.provideSupabaseClient(AppModule_ProvideSupabaseClientFactory.java:35)
at com.bharath.kietadminapp.DaggerAdminApp_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.get(DaggerAdminApp_HiltComponents_SingletonC.java:984)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.bharath.kietadminapp.DaggerAdminApp_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.get(DaggerAdminApp_HiltComponents_SingletonC.java:981)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.bharath.kietadminapp.DaggerAdminApp_HiltComponents_SingletonC$SingletonCImpl.insertStudentsToLocalUseCase(DaggerAdminApp_HiltComponents_SingletonC.java:895)
at com.bharath.kietadminapp.DaggerAdminApp_HiltComponents_SingletonC$SingletonCImpl.customWorkerFactory(DaggerAdminApp_HiltComponents_SingletonC.java:915)
at com.bharath.kietadminapp.DaggerAdminApp_HiltComponents_SingletonC$SingletonCImpl.injectAdminApp2(DaggerAdminApp_HiltComponents_SingletonC.java:959)
at com.bharath.kietadminapp.DaggerAdminApp_HiltComponents_SingletonC$SingletonCImpl.injectAdminApp(DaggerAdminApp_HiltComponents_SingletonC.java:939)
at com.bharath.kietadminapp.Hilt_AdminApp.hiltInternalInject(Hilt_AdminApp.java:51)
at com.bharath.kietadminapp.Hilt_AdminApp.onCreate(Hilt_AdminApp.java:42)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1316)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7913)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2646)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:328)
at android.app.ActivityThread.main(ActivityThread.java:9220)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
For some reason it fails to create a default settings instance, but if you don't use resumable uploads anyway you can just do this:
createSupabaseClient(
BuildConfig.SUPABASE_PROJECT_URL,
BuildConfig.SUPABASE_API_ANON_KEY,
) {
install(Storage) {
resumable {
cache = MemoryResumableCache()
}
}
install(Postgrest)
}
@bharath914 Could you please also share code of the repository? Perhaps there's missing @Inject
annotation in the constructor of the SupabaseRepositoryImpl
. Also double check @HiltApplication
in your Application class and @AndroidEntry
point of the Fragment/Activity
Closing due to inactivity. Feel free to reopen!
Currently Im Using Compose but still the app is crashing
App Module. ` @InstallIn(SingletonComponent::class) @Module object SupaModule {
@Provides
@Singleton
fun provideSupabaseClient(): SupabaseClient {
return createSupabaseClient(
BuildConfig.SUPABASE_PROJECT_URL,
BuildConfig.SUPABASE_API_ANON_KEY,
) {
install(Postgrest)
install(Storage) {
resumable {
cache = MemoryResumableCache()
}
}
}
}
@Provides
@Singleton
fun providePostgrestClient(supabaseClient: SupabaseClient): Postgrest {
return supabaseClient.postgrest
}
@Provides
@Singleton
fun provideSupabaseRepository(supabaseClient: SupabaseClient): SupabaseRepository {
return SupabaseRepositoryImpl(supabaseClient.postgrest)
}
}`
Error Logs
FATAL EXCEPTION: main
Process: com.bharath.kiet_student_app, PID: 3323
java.lang.RuntimeException: Unable to create application com.bharath.kiet_student_app.KietApp: java.lang.NullPointerException
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6764)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.NullPointerException
at com.russhwolf.settings.NoArgKt.Settings(NoArg.kt:32)
at io.github.jan.supabase.storage.resumable.SettingsResumableCache.
` import com.bharath.kiet_student_app.BuildConfig import com.bharath.kiet_student_app.data.repository.SupabaseRepositoryImpl import com.bharath.kiet_student_app.domain.repository.SupabaseRepository import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import io.github.jan.supabase.SupabaseClient import io.github.jan.supabase.createSupabaseClient import io.github.jan.supabase.postgrest.Postgrest import io.github.jan.supabase.postgrest.postgrest import io.github.jan.supabase.storage.Storage import javax.inject.Singleton
/**
- @property SupaModule Module for creating instances of supabase class components
- @sample SupaModule.provideSupabaseRepository
- @see AppModule for better documentation as methods are very similar */
@InstallIn(SingletonComponent::class) @Module object SupaModule {
@Provides
@Singleton
fun provideSupabaseClient(): SupabaseClient {
return createSupabaseClient(
BuildConfig.SUPABASE_PROJECT_URL,
BuildConfig.SUPABASE_API_ANON_KEY,
) {
install(Storage)
install(Postgrest)
}
}
@Provides
@Singleton
fun providePostgrestClient(supabaseClient: SupabaseClient): Postgrest {
return supabaseClient.postgrest
}
@Provides
@Singleton
fun provideSupabaseRepository(supabaseClient: SupabaseClient): SupabaseRepository {
return SupabaseRepositoryImpl(supabaseClient.postgrest)
}
}`
Check this . Same error is happening every time. Other components such as Postgrest is working fine . Storage also working fine before 2.x.x supabase version. But after migrating to 2.x.x then this thing is happening
` import com.bharath.kiet_student_app.BuildConfig import com.bharath.kiet_student_app.data.repository.SupabaseRepositoryImpl import com.bharath.kiet_student_app.domain.repository.SupabaseRepository import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import io.github.jan.supabase.SupabaseClient import io.github.jan.supabase.createSupabaseClient import io.github.jan.supabase.postgrest.Postgrest import io.github.jan.supabase.postgrest.postgrest import io.github.jan.supabase.storage.Storage import javax.inject.Singleton
/**
- @Property SupaModule Module for creating instances of supabase class components
- @sample SupaModule.provideSupabaseRepository
- @see AppModule for better documentation as methods are very similar */
@Installin(SingletonComponent::class) @module object SupaModule {
@Provides @Singleton fun provideSupabaseClient(): SupabaseClient { return createSupabaseClient( BuildConfig.SUPABASE_PROJECT_URL, BuildConfig.SUPABASE_API_ANON_KEY, ) { install(Storage) install(Postgrest) } } @Provides @Singleton fun providePostgrestClient(supabaseClient: SupabaseClient): Postgrest { return supabaseClient.postgrest } @Provides @Singleton fun provideSupabaseRepository(supabaseClient: SupabaseClient): SupabaseRepository { return SupabaseRepositoryImpl(supabaseClient.postgrest) }
}`
Check this . Same error is happening every time. Other components such as Postgrest is working fine . Storage also working fine before 2.x.x supabase version. But after migrating to 2.x.x then this thing is happening
It looks like you forgot to provide Storage
instance. Please add this block into your SupabaseModule
@Provides
@Singleton
fun provideSupabaseStorage(supabaseClient: SupabaseClient): Storage {
return supabaseClient.storage
}
Nothing had been changed
Same error is happening
This is the exact what I provided in my sample. Check out the file here https://github.com/hieuwu/product-sample-supabase-kt/blob/main/app/src/main/java/com/example/manageproducts/di/SupabaseModule.kt
Can you also check the Fragment
or Activity
if it is marked with @AndroidEntryPoint
?
I had checked your code it is same as mine. I also added @AndroidEntryPoint
and @HiltAndroidApp
.
There is no problem with Dagger Hilt . Also The supabase storage worked fine before the newest dependency upgrades.
I think there is a problem with the sdk itself .
Today I had updated to latest version 2.2.3 as well but the problem still exists.
Solve this problem Asap as my app heavily relies on storage feature.
Currently I Set my buckets to Public and accessing them by urls.
Let me try to add MemoryResumableCache
. When I upgraded Supabase from 1.0.0 to 2.0.0, all the breaking change is mostly in GoTrue
and Postgrest
I had checked your code it is same as mine. I also added
@AndroidEntryPoint
and@HiltAndroidApp
. There is no problem with Dagger Hilt . Also The supabase storage worked fine before the newest dependency upgrades. I think there is a problem with the sdk itself . Today I had updated to latest version 2.2.3 as well but the problem still exists. Solve this problem Asap as my app heavily relies on storage feature. Currently I Set my buckets to Public and accessing them by urls.
Can you try example from this https://supabase.com/docs/reference/kotlin/storage-from-upload?example=create-resumable-upload ?
I tried with version 2.2.3 in my sample and it works well. Please double check again @bharath914 . It would be great if you provide the minimum code that cause the crash
I will check and update here
I tried again but same result app is crashing for no reason