loadBundle() with UTF8 chars throw error on android
See original GitHub issueBug report
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
What happened? How can we make the problem occur? This could be a description, log/console output, etc.
Relevant Code:
// TODO(you): code here to reproduce the problem
Describe the bug
loadBundle() function works fine on iOS and throws an error on android. I have the special character Ö
in the text of the Cloud Firestore document. If I remove this character Ö
it will work on android. It looks like UTF-8 chars not working.
Screenshot Cloud Firestore Document
Via an external tool, we create a bundle file of Cloud Firestore collections. If I load the bundle on iOS it works fine, but on Android, I get this error:
Exception has occurred.
FirebaseException ([cloud_firestore/load-bundle-error] Client specified an invalid argument. Note that this differs from failed-precondition. invalid-argument indicates arguments that are problematic regardless of the state of the system (e.g., an invalid field name).)
Bundle file content
142{"metadata":{"id":"entries-1.bin","createTime":{"seconds":"1625237175","nanos":286628000},"version":1,"totalDocuments":1,"totalBytes":"1164"}}205{"documentMetadata":{"name":"projects/healadvisor-analyse-bef33/databases/(default)/documents/entries/000599d22b9a76bc5021e63e285b2664","readTime":{"seconds":"1625237175","nanos":286628000},"exists":true}}953{"document":{"name":"projects/healadvisor-analyse-bef33/databases/(default)/documents/entries/000599d22b9a76bc5021e63e285b2664","fields":{"texts":{"mapValue":{"fields":{"en_EN":{"mapValue":{"fields":{"problem":{"stringValue":"Test"},"solutionDescription":{"nullValue":"NULL_VALUE"},"bgInfo":{"nullValue":"NULL_VALUE"},"problemDescription":{"nullValue":"NULL_VALUE"},"solution":{"nullValue":"NULL_VALUE"}}}},"de_DE":{"mapValue":{"fields":{"problem":{"stringValue":"Öffne mich"},"problemDescription":{"nullValue":"NULL_VALUE"},"bgInfo":{"nullValue":"NULL_VALUE"},"solutionDescription":{"nullValue":"NULL_VALUE"},"solution":{"nullValue":"NULL_VALUE"}}}}}}},"editedAt":{"timestampValue":{"seconds":"1619433798","nanos":411000000}},"symbols":{"nullValue":"NULL_VALUE"},"createdAt":{"timestampValue":{"seconds":"1496158950","nanos":104000000}}},"createTime":{"seconds":"1625039472","nanos":253980000},"updateTime":{"seconds":"1625225415","nanos":239443000}}}
[REQUIRED] Step 2: Describe your environment
- Android Studio version: 4.2.1
- Firebase Component:
Cloud Firestore
- Component version:
com.google.firebase:firebase-bom:28.1.0
We also tried this on native Android way with same problem.
package de.timewaver.timewaver;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.navigation.fragment.NavHostFragment;
import com.google.android.gms.tasks.Continuation;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.LoadBundleTask;
import com.google.firebase.firestore.LoadBundleTaskProgress;
import com.google.firebase.firestore.Query;
import com.google.firebase.firestore.QuerySnapshot;
import com.google.firebase.firestore.Source;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import de.timewaver.timewaver.databinding.FragmentFirstBinding;
public class FirstFragment extends Fragment {
private FragmentFirstBinding binding;
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState
) {
binding = FragmentFirstBinding.inflate(inflater, container, false);
return binding.getRoot();
}
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
binding.buttonFirst.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NavHostFragment.findNavController(FirstFragment.this)
.navigate(R.id.action_FirstFragment_to_SecondFragment);
}
});
AsyncTask.execute(new Runnable() {
@Override
public void run() {
try {
fetchBundleFrom();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
public InputStream getBundleStream(String urlString) throws IOException {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
return connection.getInputStream();
}
public void fetchBundleFrom() throws IOException {
FirebaseFirestore db = FirebaseFirestore.getInstance();
final InputStream bundleStream = getBundleStream("https://firebasestorage.googleapis.com/v0/b/healadvisor-analyse-bef33.appspot.com/o/bundles%2Fbundle-2.bundle?alt=media&token=aa1c4377-7c62-46c6-bca2-29948969f9b8");
LoadBundleTask loadTask = db.loadBundle(bundleStream);
loadTask.addOnCompleteListener(task -> {
Log.i("TAG","");
});
}
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Android WebView with garbled UTF-8 characters.
I had UTF-8 on Android 2.x and garbled ANSI on 4.x until I put in the charset=utf-8. in the wv.loadUrlWhatever() call. Excellent attention...
Read more >String.prototype.charCodeAt() - JavaScript - MDN Web Docs
A number representing the UTF-16 code unit value of the character at the given index . If index is out of range, charCodeAt()...
Read more >Character | Android Developers
Returns a hash code for this Character ; equal to the result of invoking charValue() . static char, highSurrogate(int codePoint).
Read more >Unrecoverable error. Failure when converting to UTF-8 #1756
I get this error when try to save an object. io.realm.exceptions. ... when converting to UTF-8", chars.data(), chars.size(), error_code));. ) ...
Read more >UTF8Encoding Class (System.Text) - Microsoft Learn
Represents a UTF-8 encoding of Unicode characters.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hah, I did not know that. I think the leading bytes here is a distraction, maybe the iOS app was connecting directly to storage, while Android app tried to read from a save file for debugging.
Either way, I can confirm there is an issue loading
Öffne mich
, that is the real issue. Will prepare a fix.@aBuder Thank you for filing this issue. We will investigate. In the meantime, could you please edit the first comment to add the information requested in the new issue template (e.g. version numbers)? This could help with investigation.