Amplify 1.x crashes when trying to download from S3 (MissingForegroundServiceTypeException: Starting FGS without a type)
Closed this issue · 2 comments
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
Language and Async Model
Kotlin, RxJava
Amplify Categories
Storage
Gradle script dependencies
// Put output below this line
defaultConfig {
minSdkVersion 21
targetSdkVersion 34
}
}
dependencies {
// Amplify core dependency
implementation 'com.amplifyframework:core:1.38.8'
// Support for Java 8 features
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
implementation 'com.amplifyframework:aws-storage-s3:1.38.8'
implementation 'com.amplifyframework:aws-auth-cognito:1.38.8'
implementation 'com.amplifyframework:rxbindings:1.38.8'
Environment information
# Put output below this line
Please include any relevant guides or documentation you're referencing
No response
Describe the bug
When calling RxAmplify.Storage.list(path)
on an Android emulator with SDK 35, it crashes with this exception:
FATAL EXCEPTION: main
Process: -----, PID: 16553
android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{862920f 16553:edu.gallaudet.aslbookshelf/u0a201} targetSDK=34
at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:53)
at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:49)
at android.os.Parcel.readParcelableInternal(Parcel.java:5075)
at android.os.Parcel.readParcelable(Parcel.java:5057)
at android.os.Parcel.createExceptionOrNull(Parcel.java:3237)
at android.os.Parcel.createException(Parcel.java:3226)
at android.os.Parcel.readException(Parcel.java:3209)
at android.os.Parcel.readException(Parcel.java:3151)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7193)
at android.app.Service.startForeground(Service.java:776)
at com.amplifyframework.storage.s3.service.AmplifyTransferService$Companion.startForeground(AmplifyTransferService.kt:200)
at com.amplifyframework.storage.s3.service.AmplifyTransferService$Companion$bind$1.onServiceConnected(AmplifyTransferService.kt:174)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2210)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2243)
at android.os.Handler.handleCallback(Handler.java:959)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8705)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
Reproduction steps (if applicable)
- Run an android emu with SDK 35 Play Services
- Run an app calling RxAmplify.Storage.list(path).
Code Snippet
// Put your code below this line.
Log output
// Put your logs below this line
amplifyconfiguration.json
No response
GraphQL Schema
// Put your schema below this line
Additional information and screenshots
Since there's no current way to migrate a 1.x project to 2.x, we need a solution for the 1.x library that works with Android SDK 35.
Suggested Solution
Luckily the fix is pretty simple: in com.amplifyframework.storage.s3.service.AmplifyTransferService$Companion.startForeground()
, make sure you call startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
instead (notice specifying the ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
type explicitly).
You may also need to add the permission to the manifest:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
and add the type to your service manifest declaration:
<application>
<service
android:name="com.amplifyframework.storage.s3.service.AmplifyTransferService"
android:foregroundServiceType="dataSync"
tools:node="merge" />
Hi @odbol.
Amplify v1 is no longer maintained, so we will not fix this issue and strongly recommend you upgrade to V2.
The docs you linked are for upgrading the Amplify backend (server-side) from Gen1 to Gen2. That is not necessary to move to Amplify v2 - Amplify v2 works with both Gen1 and Gen2 backends.
The migration process for Amplify Android from v1 to v2 is fairly straightforward, there are only a handful of code changes that might be necessary. Please see the migration guide for details.
This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.