Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amplify 1.x crashes when trying to download from S3 (MissingForegroundServiceTypeException: Starting FGS without a type) #2881

Closed
1 task done
odbol opened this issue Jul 29, 2024 · 2 comments
Assignees
Labels
bug Something isn't working storage Related to the Storage category/plugins wontfix This will not be worked on

Comments

@odbol
Copy link

odbol commented Jul 29, 2024

Before opening, please confirm:

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)

  1. Run an android emu with SDK 35 Play Services
  2. 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" />
@github-actions github-actions bot added the pending-triage Issue is pending triage label Jul 29, 2024
@mattcreaser mattcreaser added bug Something isn't working storage Related to the Storage category/plugins labels Jul 29, 2024
@mattcreaser mattcreaser self-assigned this Jul 29, 2024
@github-actions github-actions bot removed the pending-triage Issue is pending triage label Jul 29, 2024
@mattcreaser
Copy link
Member

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.

@mattcreaser mattcreaser added the wontfix This will not be worked on label Jul 29, 2024
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working storage Related to the Storage category/plugins wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants