-
Notifications
You must be signed in to change notification settings - Fork 325
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
Events are not fired on Android #81
Comments
Hi @antonkulyk thanks for reporting your issue. Please provide a minimal reproduction of the issue by forking the example app |
Can't reproduce it on the example app 😞 |
I'm really not sure. I would start by stripping out functionality in your project until it's as close as possible to a minimal example which you have found to work. For example, maybe you would have better luck with a POST request rather than PUT, or maybe update the event handler callbacks (maybe an issue with the context the console log function is called with why passed in by reference? 🤷♂️ ) Upload.addListener('progress', uploadId, ({ progress }) => { console.log(`Progress: ${progress}%`) }) Sorry I can't provide any more information. Maybe @StevePotter would some ideas when he is available |
@TSMMark Hi there, I am fighting with that issue together with Anton. We have covered String uploadId = request.startUpload(); It gives back public void onProgress(Context context, UploadInfo uploadInfo); in String filePath = options.getString("path");
...
File testFile = new File(filePath);
if (testFile.exists()) {
Log.d(TAG, "FILE EXISTS");
} else {
Log.d(TAG, "FILE DOES NOT EXIST");
} And the file path passed appears to be valid. Any ideas on what might went wrong are very very welcome. |
@antonkulyk and @diurchenko, thanks for writing. To be clear, you set a breakpoint in Android Studio on Can you check logcat for any other possible tracing info? Also, can you use the Network Profile and see if you can track down the request to S3? Try not to get discouraged. Keep using the Android Studio tools and you'll get to the bottom of it. I would avoid messing with Javascript because this seems like a very platform-specific issue. |
@StevePotter Hi Steve! That wasn't a breakpoint, but |
Also experiencing this issue. @StevePotter setting breakpoints on the delegate methods confirm they aren't being called. I suspect that either gotev/android-upload-service is buggy or being misconfigured. Looking at gotev/android-upload-service#374 and gotev/android-upload-service#344 they mention that if you switch activities, the delegate method does not work and they recommend the broadcast receiver method. From android-upload-service's wiki: |
Hm...I tried to implement the broadcast receiver into the library and that also wasn't triggering. Also I can do a cancelUpload successfully a long time after doing a startUpload, so the fact that none of the delegates/broadcast listeners/global listeners (listening mechanisms from gotev/android-upload-service) are triggering, leads me to believe that startUpload isn't even starting successfully. I have confirmed this by monitoring incoming requests - when calling startUpload no requests are actually triggered. Thus, it seems fair to conclude that the problem lies not within the monitoring of the requests (delegates), but rather in the triggering of the request itself. I also tried updating to the latest version of It almost seems like https://github.com/gotev/android-upload-service/blob/877ec555cb0ebd9a03dee8caa8813153ce7dfa11/uploadservice/src/main/java/net/gotev/uploadservice/UploadRequest.java#L76 is not starting the service correctly or it is not calling @gotev Sorry to drag you in to another projects' issue, but do you have any idea why any of the commands in the startUpload->context.startService->onStartCommand chain would not be successful? In any case, I'm giving up on using this library for now, as it's taken quite a lot of time to debug already, to no avail. Really hoping for some good feedback to this comment. |
@sraka1 I think the problem has to be inspected at RN bridge level, because the service works successfully in production on all Androids and no errors like this ever happened. I encourage you to try the upload service demo app in the same environment in which you start your RN app and it should work. Adjust it with your custom parameters so it can make the same request to your backend. The Be sure to enable library debug log in all your tests, so you will get very verbose and detailed step by step logs which can help you debug. |
In native Android it doesn't make difference, but I don't know if in RN the two are treated differently. |
@gotev Yeah, I figured. Btw, I'm not an Android dev, but is the I debugged this thing a bit further and I get a |
You don't need to add any service declaration in your manifest. Just follow the getting started wiki page and make sure you set your package ID correctly by following the example. |
Okay, I tracked down the issue (but no fix yet). Context.startService (https://developer.android.com/reference/android/content/Context.html#startService(android.content.Intent)) - specifically here - returns a ComponentName OR null - to quote the docs P.S.: @gotev might be nice to check for that |
In normal conditions in a fully native app, if you don't configure the namespace correctly it simply won't start and the solution is in the getting started wiki. Post the code you are using to initialize the library and the full package string of your app. You said you are using broadcast receivers. Post that code as well. |
@gotev you mean the "Hey dude, please set the namespace" thing? Nonetheless, the service is not started ( Broadcast receivers vs. delegates in this casedoesn't matter, as the core (the UploadService mentioned in the Developer's Manual isn't started at all :/ |
The last thing you should try is the upload service demo app with your same settings. I bet that null is because of something done by RN unless proven otherwise. |
I'm pretty sure that somehow during the build, the AndroidManifest from android-upload-service is being ignored. And since there is then no definition, no service is started 😢 I will try now with the upload service demo app, but I'm also quite sure it will work...it's probably something with how RN does the Android build... |
Woohoo, finally found the problem! 🎉 I needed to add the following to my apps AndroidManifest.xml
The intent filter is not really super-necessary, but you might get warnings while building. This is to prevent other apps of starting this service, I guess... @gotev It looks like the RN build process was not merging in the AndroidManifest.xml from your package! 😮 |
If RN is not merging manifests, it can be a problem. Nowadays all the libraries on Android rely on the Gradle manifest merger to avoid having to mess around with your manifest. Reach out the RN guys and let them know about it, maybe they already have a solution for this. @StevePotter you're welcome! |
I guess it might be because here the AndroidManifest is two layers below the app one? App AndroidManifest->react-native-background-upload AndroidManifest->gotev/android-upload-service AndroidManifest... In any case, the fix I mentioned above works great :) P.S.: I've seen other react-native libraries asking users to add tags directly into their apps' AndroidManifest, so I don't think asking the users to do this would be a problem at all. So, yeah, @StevePotter I'd ask the users to do this... |
On native Android even multiple nested project's manifests are merged by Gradle without problems. So RN has that limitation and you have to tell users to manually add things into their manifests |
I'm experiencing the same issue on 5.0, react-native 0.56 |
Hoping that a new comment will raise this issue up: I have the same problem, and manifest update didn't help |
Hey guys, In my case, I don't have to add service in the AndroidManifest.xml. File is correctly uploading but the react-native events is just hunted up on some point and then I don't know what is happening? For example, I tried to upload 3MB picture multiple times sometimes it upload and I am getting event on react-native side. But sometimes events is just hanging up no call-backs for progress or completed or error or anything else. I don't know what to do now? |
I ended up with moving to pure XMLHttpRequest which works quite well |
This is some sort of joke right? |
To get upload events I had to use the Notification Object and set enabled=true for Android >= 8. (Still on version 4.4.0, RN 0.59.10). |
Any update on this? |
Hello, |
Hi, I need to upload files to Amazon S3 in my app.
Everything works fine on the iOS, but I have some troubles with Android.
Here is the example
For some reason, none of the
progress
,error
,canceled
andcompleted
events are not fired after the upload starts. I get anuploadId
and nothing happens after that.I've tried manipulating the SDKs versions (from this issue as well), upgrading React Native to the latest release, scanning the adb logcat. I've even put logs in the library's Java
startUpload
method, but everything seems to be fine. Do you have any idea what could go wrong? Perhaps your library has conflicts with another lib?React Native version: 0.52.0
react-native-background-upload version: 4.4.0
Devices: OnePlus 5 with Android 8 and 8.1, Google Pixel 2XL emulator with Android 7.x
The text was updated successfully, but these errors were encountered: