Dev-hwang / flutter_foreground_task

This plugin is used to implement a foreground service on the Android platform.
https://pub.dev/packages/flutter_foreground_task
MIT License
149 stars 109 forks source link

Error in API 34. Package doesn't work on Android #255

Closed AbduraufDev closed 2 months ago

AbduraufDev commented 2 months ago

After making the sdk version 34, I added new stuff to the manifest(

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<service android:name="uz.teamwork.mehrgo.flutter_foreground_task.service.ForegroundService" android:foregroundServiceType="dataSync" android:exported="false"/>

). After that, the package did not work for me at all on Android devices. It works on iOS devices but not on Android.

Dev-hwang commented 2 months ago

@AbduraufUZB

Please tell me console log and what error occurred.

AbduraufDev commented 2 months ago

@AbduraufUZB

Please tell me console log and what error occurred.

D/EGL_emulation( 5276): app_time_stats: avg=23.21ms min=12.48ms max=175.43ms count=43 D/EGL_emulation( 5276): app_time_stats: avg=16.65ms min=13.20ms max=20.61ms count=60 D/EGL_emulation( 5276): app_time_stats: avg=20.78ms min=10.21ms max=218.41ms count=48 D/EGL_emulation( 5276): app_time_stats: avg=16.65ms min=9.21ms max=22.60ms count=61 E/FrameTracker( 5276): force finish cuj, time out: JIME_INSETS_ANIMATION::1@1@com.example.example D/EGL_emulation( 5276): app_time_stats: avg=20.03ms min=8.81ms max=157.80ms count=50 D/EGL_emulation( 5276): app_time_stats: avg=16.65ms min=13.59ms max=20.05ms count=61

Dev-hwang commented 2 months ago

I need more detailed logs... I can't tell from the above log what problem is occurring.

Dev-hwang commented 2 months ago

What did you add to the manifest? Add it and will the app work on API 33?

Dev-hwang commented 2 months ago

Could you please share the code(AndroidManifest.xml, app/build.gradle, uses plugin in TaskHandler) if possible?

AbduraufDev commented 2 months ago

Could you please share the code(AndroidManifest.xml, app/build.gradle, uses plugin in TaskHandler) if possible?

def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } }

def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") }

def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '32' }

def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '32.0' }

apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) }

android { compileSdkVersion 34 ndkVersion flutter.ndkVersion

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "uz.teamwork.ecotaxi"
    // You can update the following values to match your application needs.
    // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
    minSdkVersion 25
    targetSdkVersion 34
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

signingConfigs {
   release {
       keyAlias keystoreProperties['keyAlias']
       keyPassword keystoreProperties['keyPassword']
       storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
       storePassword keystoreProperties['storePassword']
   }
}

buildTypes {
    release {
        signingConfig signingConfigs.release
    }
}

}

flutter { source '../..' }

dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" }

Build gradle

AbduraufDev commented 2 months ago

Could you please share the code(AndroidManifest.xml, app/build.gradle, uses plugin in TaskHandler) if possible?

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="uz.teamwork.ecotaxi">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application android:label="Eco Taxi" android:name="${applicationName}" android:icon="@mipmap/ic_launcher"> <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyAVNLXCL2b0PAVP9shN05OmF2LvvzgJubM"/> <service android:name="uz.teamwork.ecotaxi.flutter_foreground_task.service.ForegroundService" android:foregroundServiceType="dataSync" android:exported="false"/> <activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:enableOnBackInvokedCallback="true" android:windowSoftInputMode="adjustResize">

        <meta-data
          android:name="io.flutter.embedding.android.NormalTheme"
          android:resource="@style/NormalTheme"
          />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <!-- Don't delete the meta-data below.
         This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>

Manifiest

AbduraufDev commented 2 months ago

This code was running on api 34

Dev-hwang commented 2 months ago

See this example.

This example is a location service running on API 34.

To get location in the background, you need to add the permission below:

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

And you must always allow location permission before starting the foreground service. This is required.

AbduraufDev commented 2 months ago

No its not working ...(

чт, 15 авг. 2024 г. в 14:41, Pravera @.***>:

does it work well?

— Reply to this email directly, view it on GitHub https://github.com/Dev-hwang/flutter_foreground_task/issues/255#issuecomment-2290980032, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXGFIEX2LVYBLSHKTGJM46LZRRZVDAVCNFSM6AAAAABMLTXQ2OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJQHE4DAMBTGI . You are receiving this because you were mentioned.Message ID: @.***>

mx1up commented 2 months ago

@AbduraufUZB please provide a minimal project (as a github repo) showcasing your problem.

AbduraufDev commented 2 months ago

If I don't add this permission to the man manifest, my program doesn't work. But I'm not using the man location function, what solution can you give me?

пт, 16 авг. 2024 г. в 15:30, Levi @.***>:

same here, when I set target sdk to 34, it will crash, logs:

D/AndroidRuntime(16137): Shutting down VM E/AndroidRuntime(16137): FATAL EXCEPTION: main E/AndroidRuntime(16137): Process: com.gopeed, PID: 16137 E/AndroidRuntime(16137): java.lang.RuntimeException: Unable to start service @.*** with Intent { cmp=com.gopeed/com.pravera.flutter_foreground_task.service.ForegroundService }: android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{59ff584 16137:com.gopeed/u0a406} targetSDK=34 E/AndroidRuntime(16137): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5071) E/AndroidRuntime(16137): at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0) E/AndroidRuntime(16137): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2435) E/AndroidRuntime(16137): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime(16137): at android.os.Looper.loopOnce(Looper.java:224) E/AndroidRuntime(16137): at android.os.Looper.loop(Looper.java:318) E/AndroidRuntime(16137): at android.app.ActivityThread.main(ActivityThread.java:8772) E/AndroidRuntime(16137): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(16137): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561) E/AndroidRuntime(16137): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013) E/AndroidRuntime(16137): Caused by: android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{59ff584 16137:com.gopeed/u0a406} targetSDK=34 E/AndroidRuntime(16137): at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:53) E/AndroidRuntime(16137): at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:49) E/AndroidRuntime(16137): at android.os.Parcel.readParcelableInternal(Parcel.java:4870) E/AndroidRuntime(16137): at android.os.Parcel.readParcelable(Parcel.java:4852) E/AndroidRuntime(16137): at android.os.Parcel.createExceptionOrNull(Parcel.java:3052) E/AndroidRuntime(16137): at android.os.Parcel.createException(Parcel.java:3041) E/AndroidRuntime(16137): at android.os.Parcel.readException(Parcel.java:3024) E/AndroidRuntime(16137): at android.os.Parcel.readException(Parcel.java:2966) E/AndroidRuntime(16137): at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7280) E/AndroidRuntime(16137): at android.app.Service.startForeground(Service.java:862) E/AndroidRuntime(16137): at com.pravera.flutter_foreground_task.service.ForegroundService.startForegroundService(ForegroundService.kt:258) E/AndroidRuntime(16137): at com.pravera.flutter_foreground_task.service.ForegroundService.onStartCommand(ForegroundService.kt:128) E/AndroidRuntime(16137): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5053) E/AndroidRuntime(16137): ... 9 more W/com.gopeed(16137): type=1400 audit(0.0:513260): avc: denied { search } for name="miuilog" dev="dm-50" ino=680 scontext=u:r:untrusted_app:s0:c150,c257,c512,c768 tcontext=u:object_r:data_log_file:s0 tclass=dir permissive=0 app=com.duowan.kiwi W/com.gopeed(16137): type=1400 audit(0.0:513261): avc: denied { search } for name="miuilog" dev="dm-50" ino=680 scontext=u:r:untrusted_app:s0:c150,c257,c512,c768 tcontext=u:object_r:data_log_file:s0 tclass=dir permissive=0 app=com.duowan.kiwi W/com.gopeed(16137): type=1400 audit(0.0:513262): avc: denied { search } for name="miuilog" dev="dm-50" ino=680 scontext=u:r:untrusted_app:s0:c150,c257,c512,c768 tcontext=u:object_r:data_log_file:s0 tclass=dir permissive=0 app=com.duowan.kiwi W/ScoutUtils(16137): Failed to mkdir /data/miuilog/stability/memleak/heapdump/ W/com.gopeed(16137): type=1400 audit(0.0:513263): avc: denied { search } for name="miuilog" dev="dm-50" ino=680 scontext=u:r:untrusted_app:s0:c150,c257,c512,c768 tcontext=u:object_r:data_log_file:s0 tclass=dir permissive=0 app=com.duowan.kiwi W/com.gopeed(16137): type=1400 audit(0.0:513264): avc: denied { search } for name="miuilog" dev="dm-50" ino=680 scontext=u:r:untrusted_app:s0:c150,c257,c512,c768 tcontext=u:object_r:data_log_file:s0 tclass=dir permissive=0 app=com.duowan.kiwi W/com.gopeed(16137): type=1400 audit(0.0:513265): avc: denied { search } for name="miuilog" dev="dm-50" ino=680 scontext=u:r:untrusted_app:s0:c150,c257,c512,c768 tcontext=u:object_r:data_log_file:s0 tclass=dir permissive=0 app=com.duowan.kiwi W/com.gopeed(16137): type=1400 audit(0.0:513266): avc: denied { getattr } for path="/data/miuilog" dev="dm-50" ino=680 scontext=u:r:untrusted_app:s0:c150,c257,c512,c768 tcontext=u:object_r:data_log_file:s0 tclass=dir permissive=0 app=com.duowan.kiwi E/BinderMonitor(16137): err open binder_delay errno=13 I/Process (16137): Process is going to kill itself! I/Process (16137): java.lang.Exception I/Process (16137): at android.os.Process.killProcess(Process.java:1363) I/Process (16137): at com.android.internal.os.RuntimeInit$KillApplicationHandler.uncaughtException(RuntimeInit.java:174) I/Process (16137): at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1071) I/Process (16137): at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1066) I/Process (16137): at java.lang.Thread.dispatchUncaughtException(Thread.java:2306) I/Process (16137): Sending signal. PID: 16137 SIG: 9 Lost connection to device.

Exited.

— Reply to this email directly, view it on GitHub https://github.com/Dev-hwang/flutter_foreground_task/issues/255#issuecomment-2293257774, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXGFIESR7NURM5SSNZOGEETZRXIELAVCNFSM6AAAAABMLTXQ2OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGI2TONZXGQ . You are receiving this because you were mentioned.Message ID: @.***>