So, I've spent the past 2 hours searching for a solution for this but I cannot get anywhere.
I've followed this link to setup the google sheet API in order to use it with Flutter.
I keep getting this error:
ServerRequestFailedException (Failed to obtain access credentials. Error: invalid_grant Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim. Status code: 400)
As far as I've seen, this is related to a time problem but I've made sure the device's time is correct + enabled auto setting in the settings.
I'm using an android emulator (Pixel 4 API 27)
These are 2 pictures to show my time settings:
My code: (I'm calling the initSheet() in main)
class SpreadSheet {
static late final gsheets;
static late final spreadsheet;
static Future<bool> initSheet() async {
// TODO: Handle errors (Wrong time....)
gsheets = GSheets(_credentials);
/// link looks like so https://docs.google.com/spreadsheets/d/YOUR_SPREADSHEET_ID/edit#gid=0
/// [YOUR_SPREADSHEET_ID] in the path is the id your need
spreadsheet = await gsheets
.spreadsheet("1t51H_CSHPFoKB7KW_AcGMi3gwyJnecfM_k5wvk4OQ04");
return (spreadsheet == null ? false : true);
}
}
Somehow, the code is running perfectly now.
I used flutter clean & had to re-download gradle-6.9 zip because it got corrupted somehow.
I still don't know if that's exactly what actually fixed it or no but it'll be worth the try if someone faces this problem again.
My app that uses Google Maps SDK (v2) just started crashing with this exception:
Process: com.currentlocation.android, PID: 7328
java.lang.ArrayIndexOutOfBoundsException: length=1; index=12
at com.google.maps.api.android.lib6.gmm6.vector.ct.<init>(:com.google.android.gms.dynamite_mapsdynamite#201216081#20.12.16 (120400-0):9)
at com.google.maps.api.android.lib6.gmm6.vector.cv.a(:com.google.android.gms.dynamite_mapsdynamite#201216081#20.12.16 (120400-0):23)
at com.google.maps.api.android.lib6.gmm6.util.m.run(:com.google.android.gms.dynamite_mapsdynamite#201216081#20.12.16 (120400-0):14)
at java.lang.Thread.run(Thread.java:919)
In the v3 beta SDK, the stack trace is:
2020-04-23 15:59:06.064 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example, PID: 22717
java.lang.ArrayIndexOutOfBoundsException: length=1; index=12
at com.google.android.libraries.maps.bv.zzbs.<init>(ZoomTable.java:24)
at com.google.android.libraries.maps.bv.zzbv.zza(ZoomTableQuadTree.java:57)
at com.google.android.libraries.maps.br.zzd.zza(Unknown Source:4)
at com.google.android.libraries.maps.hi.zzas.zza(Suppliers.java:7)
at com.google.android.libraries.maps.br.zza.zzh(SharedMapComponentImpl.java:58)
at com.google.android.libraries.maps.gu.zzat.zza(RendererFactoryImpl.java:88)
at com.google.android.libraries.maps.it.zzav.zza(GoogleMapImpl.java:59)
at com.google.android.libraries.maps.it.zzci.zza(MapFragmentDelegateImpl.java:3)
at com.google.android.libraries.maps.it.zzcg.zza(MapFragmentDelegateImpl.java:15)
at com.google.android.libraries.maps.SupportMapFragment$zza.onCreateView(SupportMapFragment.java:15)
at com.google.android.gms.dynamic.zae.zaa(com.google.android.gms:play-services-base##17.1.0:4)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.zaa(com.google.android.gms:play-services-base##17.1.0:9)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.onCreateView(com.google.android.gms:play-services-base##17.1.0:25)
at com.google.android.libraries.maps.SupportMapFragment.onCreateView(SupportMapFragment.java:34)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2698)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:310)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1185)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1354)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1432)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1495)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2617)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2569)
at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2722)
at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:336)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1186)
at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2222)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1995)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1951)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1847)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2621)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2569)
at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2722)
at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:336)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1186)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1354)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1432)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1495)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2617)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2569)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:247)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:541)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:201)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1432)
at android.app.Activity.performStart(Activity.java:7848)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3294)
2020-04-23 15:59:06.064 E/AndroidRuntime: at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
What is the cause?
Edit: following is the official solution from Google (link)
Summary
Google Maps SDK thread crashes App (ArrayIndexOutOfBoundsException) - Solution Offered
Description
On April 23 2020 starting at 11:30 PDT, Google served for 4 hours an update to the configuration of a Maps mobile component, triggering crashes in Maps SDKs for Android and iOS. Applications on devices that downloaded this version of the configuration (during the outage period) were vulnerable to the crash. Workaround solutions are offered for Maps SDKs for Android and iOS.
Maps SDK for Android
Maps SDK for Android v2 (included in Google Play Services)
The updates to Google Play Services to fix the crash has been published to all devices with Google Play Services version 17.4.55 and newer. There is no change to the version number of Google Play Services on the device after the update is installed. No action is required from developers or end users to receive the updated Maps module; however, developers can verify that the module is present on a given device with the following adb command:
adb shell dumpsys activity provider com.google.android.gms.chimera.container.GmsModuleProvider
You should see the line Module Set ID: maps listed in the Module Sets section.
Module Set ID: maps, Module Set Version: 2015120015120000
The crash rates of Maps SDK for Android v2 are back to normal.
As of now, if you have not updated your app with the client-side code workarounds mentioned below, you do not need to take further action.
If you have already updated your app with the workarounds, you can remove the workaround in a subsequent update of your app (but keeping the workaround is safe).
Premium Plan Maps SDK for Android v2 or Maps SDK for Android v3 beta (static libraries)
If your app uses the Premium Plan Maps SDK for Android v2 or Maps SDK for Android v3 beta (static libraries), and is still experiencing crashes, we still highly recommend you to roll out the workarounds below via an update to your app. As your application is loading a static version of the SDK which is vulnerable to the bad data being stored on some devices, only an update to your application can solve the problem.
Play Store review approvals
If you update your app but experience Play Store review approvals delays, please file a support case with your app’s Package ID: Contact the support team. Our Support Team will internally escalate your request and expedite the approval.
Negative reviews in the Google Play Store
Some application developers inquired about 1-star reviews in the Google Play Store left by end-users due to crashes. Only comments that violate Google Play's policy [ 1 ] can be removed. You can also flag abusive reviews in the Play Console [ 2 ]. Applications will not be automatically removed from the Google Play store due to negative reviews. It's also worth noting that the calculation of your overall app review rating favors recent reviews, which means that your rating will recover to pre-incident levels over time.
[ 1 ] Ratings & Review on the Play Store
[ 2 ] Report inappropriate reviews
Maps SDK for iOS
Crash rates on iOS are back to normal. If your application is still experiencing crashes, you need to update and publish your app with the code workarounds communicated here.
For questions about deploying or expediting your application in the Apple App Store, please contact Apple directly.
With this update, we are closing this issue. Thank you to everyone for your patience. Our team is performing an in-depth internal investigation of this incident; as soon as possible, we will publish our analysis (in approximately a week). In the meantime, if you have any questions, or are still experiencing problems, please file a support case.
Workarounds:
End users on Android can clear the affected app's data (not just the
cache).
End users on iOS can uninstall then reinstall the affected app(s).
App Developers can apply the code workarounds below in order to solve
the issue for all their end users.
Code workaround for iOS:
Recommended placement for the code is before GMSServices initialization in the application(_:didFinishLaunchingWithOptions:) (Swift) or application:didFinishLaunchingWithOptions: (Objective-C) method. Specifically:
Swift:
let key = "GoogleMapsServerControlledParamsKey_bug_154855417"
if !UserDefaults.standard.bool(forKey: key) {
let urls = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)
if urls.count > 0 {
let paramUrl = urls[0].appendingPathComponent("com.google.GoogleMaps/ServerControlledParams", isDirectory: false)
try? FileManager.default.removeItem(at: paramUrl)
}
UserDefaults.standard.set(true, forKey: key)
}
Objective-C:
NSString *key = #"GoogleMapsServerControlledParamsKey_bug_154855417";
BOOL keyExists = [[NSUserDefaults standardUserDefaults] boolForKey:key];
if (!keyExists) {
NSArray<NSURL *> *array =
[[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory
inDomains:NSUserDomainMask];
if (array.count > 0) {
NSURL *url =
[array[0] URLByAppendingPathComponent:#"com.google.GoogleMaps/ServerControlledParams"
isDirectory:NO];
if (url) {
[[NSFileManager defaultManager] removeItemAtURL:url error:NULL];
}
}
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:key];
}
Code workaround for Android:
The recommended placement for the code is in Application.onCreate():
Java
try {
SharedPreferences hasFixedGoogleBug154855417 = getSharedPreferences("google_bug_154855417", Context.MODE_PRIVATE);
if (!hasFixedGoogleBug154855417.contains("fixed")) {
File corruptedZoomTables = new File(getFilesDir(), "ZoomTables.data");
File corruptedSavedClientParameters = new File(getFilesDir(), "SavedClientParameters.data.cs");
File corruptedClientParametersData =
new File(
getFilesDir(),
"DATA_ServerControlledParametersManager.data."
+ getBaseContext().getPackageName());
File corruptedClientParametersDataV1 =
new File(
getFilesDir(),
"DATA_ServerControlledParametersManager.data.v1."
+ getBaseContext().getPackageName());
corruptedZoomTables.delete();
corruptedSavedClientParameters.delete();
corruptedClientParametersData.delete();
corruptedClientParametersDataV1.delete();
hasFixedGoogleBug154855417.edit().putBoolean("fixed", true).apply();
}
} catch (Exception e) {
}
Kotlin
try {
val sharedPreferences = getSharedPreferences("google_bug_154855417", Context.MODE_PRIVATE)
if (!sharedPreferences.contains("fixed")) {
val corruptedZoomTables = File(filesDir, "ZoomTables.data")
val corruptedSavedClientParameters = File(filesDir, "SavedClientParameters.data.cs")
val corruptedClientParametersData = File(filesDir, "DATA_ServerControlledParametersManager.data.${packageName}")
val corruptedClientParametersDataV1 = File(filesDir, "DATA_ServerControlledParametersManager.data.v1.${packageName}")
corruptedZoomTables.delete()
corruptedSavedClientParameters.delete()
corruptedClientParametersData.delete()
corruptedClientParametersDataV1.delete()
sharedPreferences.edit().putBoolean("fixed", true).apply()
}
} catch (exception: Exception) {
}
The workarounds provided here covers all available flavors and versions of our SDKs for Android. To clarify further (in case you released an earlier version of the workaround that did not delete as many files):
Applications that use Maps Android SDK v2 should only need to delete
one file: ZoomTables.data.
Applications that use Maps Android SDK v3 beta should only need to
delete one file, either
DATA_ServerControlledParametersManager.data.v1. +
getBaseContext().getPackageName())
or
DATA_ServerControlledParametersManager.data. +
getBaseContext().getPackageName())
Seems in every app Google Map creates ZoomTables.data file.
This file was malformed, malformed version of it that could be downloaded from comment.
To reproduce the issue remove ZoomTables.data from the app packages on the device and insert malformed one. The app should crash.
Currently, the issue was solved on google's side, but the apps still contain a cached version of that data file.
To fix the issue we should remove that file right on the app start in Application onCreate Method.
private void fixGoogleMapBug() {
try {
SharedPreferences hasFixedGoogleBug154855417 = getSharedPreferences("google_bug_154855417", Context.MODE_PRIVATE);
if (!hasFixedGoogleBug154855417.contains("fixed")) {
File corruptedZoomTables = new File(getFilesDir(), "ZoomTables.data");
File corruptedSavedClientParameters = new File(getFilesDir(), "SavedClientParameters.data.cs");
File corruptedClientParametersData =
new File(
getFilesDir(),
"DATA_ServerControlledParametersManager.data."
+ getBaseContext().getPackageName());
File corruptedClientParametersDataV1 =
new File(
getFilesDir(),
"DATA_ServerControlledParametersManager.data.v1."
+ getBaseContext().getPackageName());
corruptedZoomTables.delete();
corruptedSavedClientParameters.delete();
corruptedClientParametersData.delete();
corruptedClientParametersDataV1.delete();
hasFixedGoogleBug154855417.edit().putBoolean("fixed", true).apply();
}
} catch (Exception e) {
}
}
Update 1
I've updated workaround, base on the latest google developers comment:
The workarounds provided here covers all available flavors and versions of our SDKs for Android. To clarify further (in case you released an earlier version of the workaround that did not delete as many files):
Applications that use Maps Android SDK v2 should only need to delete one file: ZoomTables.data.
Applications that use Maps Android SDK v3 beta should only need to delete one file, either DATA_ServerControlledParametersManager.data.v1. + getBaseContext().getPackageName()) or DATA_ServerControlledParametersManager.data. + getBaseContext().getPackageName())
This solution worked for me
First open "App Info"
Choose "Storage"
Click "Clear data"
Open app again and check if the issue fixed.
Below are suggestions just to help your customers.
Send an email to your all users for the inconvenience and describe them the issue they faced and give them above mentioned steps to resolve their issue.
You can also send Push Notification to all your users with Firebase Push Notifications, if your app have the push notifications service.
Screenshots demonstration:
Drawbacks of solutions above:
ZoomTables.data is deleted on every device, regardless of whether the device is affected by the crash or not
Workaround only works once, is it sure that this problem never happens again?
Drawbacks of my solution:
on first execution of maps activity on affected device map is empty. After rotation of device or second execution map is shown up
My solution catches the Exception thrown by the Maps SDK, call this in onCreate of the Application class:
public static void catchGoogleMapsException(final Context context)
{
final Thread.UncaughtExceptionHandler defaultHandler =
Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(
(#NonNull final Thread thread, #NonNull final Throwable ex) ->
{
if (thread.getName().contains("ZoomTableManager"))
{
new File(context.getFilesDir(), "ZoomTables.data").delete();
Log.w("Maps Bug 154855417", "Caught exception and deleted ZoomTables.data");
}
else
if (defaultHandler!=null)
defaultHandler.uncaughtException(thread, ex);
else
throw new RuntimeException(
"No default uncaught exception handler.", ex);
});
}
Solution Offered for iOS & Android:
https://issuetracker.google.com/issues/154855417#comment509
Maps SDK for Android v2 (included in Google Play Services)
The updates to Google Play Services to fix the crash has been published to all devices with Google Play Services version 17.4.55 and newer. There is no change to the version number of Google Play Services on the device after the update is installed. No action is required from developers or end users to receive the updated Maps module; however, developers can verify that the module is present on a given device with the following adb command:
adb shell dumpsys activity provider com.google.android.gms.chimera.container.GmsModuleProvider
You should see the line Module Set ID: maps listed in the Module Sets section.
Module Set ID: maps, Module Set Version: 2015120015120000
The crash rates of Maps SDK for Android v2 are back to normal.
As of now, if you have not updated your app with the client-side code
workarounds mentioned below, you do not need to take further action.
If you have already updated your app with the workarounds, you can
remove the workaround in a subsequent update of your app (but keeping
the workaround is safe).
Code workaround for Android:
The productive version was fixed (on google's side) but if you still have problems with your emulator you have to run the following code only once.
The recommended placement for the code is in Application.onCreate():
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
fixGoogleMapBugTemp() //TODO: Then clean this line
// ...
}
/**
* Observation: Invoke this method only once
*/
private fun fixGoogleMapBugTemp() {
val googleBug = getSharedPreferences("google_bug_154855417", Context.MODE_PRIVATE)
if (!googleBug.contains("fixed")) {
val corruptedZoomTables = File(filesDir, "ZoomTables.data");
corruptedZoomTables.delete();
googleBug.edit().putBoolean("fixed", true).apply();
}
}
Workaround: Clear application data (not just the cache).
Note: A copy of the problematic file from the app packages on the device if anyone needs it for repro.
Source
GL
For Android, multiple developers mentioned a workaround consisting in deleting the ZoomTable.data file directly from their application. After review, this fix seems safe, and you could try it in your application.
Please refer to
https://issuetracker.google.com/154855417#comment179
If you want your users to continue using your app without re-installing,
The sample code is copy-pasted here for your convenience. In Application.onCreate():
SharedPreferences googleBug = getSharedPreferences("google_bug_154855417", Context.MODE_PRIVATE);
if (!googleBug.contains("fixed")) {
File corruptedZoomTables = new File(getFilesDir(), "ZoomTables.data");
corruptedZoomTables.delete();
googleBug.edit().putBoolean("fixed", true).apply();
}
reference: Google Maps SDK is crashing -- partially resolved
Complete & official answer for all :
Diagnosis: Crash of the Google Maps Platform mobile SDKs (iOS & Android) at load.
Workaround: * Clear the affected app's data (not just the cache), or uninstall then reinstall the affected app(s).
Code workaround for iOS:
Recommended placement for the code is before GMSServices initialization in the application(_:didFinishLaunchingWithOptions:) (Swift) or application:didFinishLaunchingWithOptions: (Objective-C) method. Specifically:
Swift:
let key = "GoogleMapsServerControlledParamsKey_bug_154855417"
if !UserDefaults.standard.bool(forKey: key) {
let urls = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)
if urls.count > 0 {
let paramUrl = urls[0].appendingPathComponent("com.google.GoogleMaps/ServerControlledParams", isDirectory: false)
try? FileManager.default.removeItem(at: paramUrl)
}
UserDefaults.standard.set(true, forKey: key)
}
Objective-C:
NSString *key = #"GoogleMapsServerControlledParamsKey_bug_154855417";
BOOL keyExists = [[NSUserDefaults standardUserDefaults] boolForKey:key];
if (!keyExists) {
NSArray<NSURL *> *array =
[[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory
inDomains:NSUserDomainMask];
if (array.count > 0) {
NSURL *url =
[array[0] URLByAppendingPathComponent:#"com.google.GoogleMaps/ServerControlledParams"
isDirectory:NO];
if (url) {
[[NSFileManager defaultManager] removeItemAtURL:url error:NULL]);
}
}
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:key];
}
Once you have deployed it in your app, you can file a Maps Support case if you would like us to help expedite its approval. Please make sure to include your application's ID, Bundle ID, and the version you want reviewed in your case.
Code workaround for Android:
The recommended placement for the code is in Application.onCreate():
Java
try {
SharedPreferences hasFixedGoogleBug154855417 = getSharedPreferences("google_bug_154855417", Context.MODE_PRIVATE);
if (!hasFixedGoogleBug154855417.contains("fixed")) {
File corruptedZoomTables = new File(getFilesDir(), "ZoomTables.data");
File corruptedSavedClientParameters = new File(getFilesDir(), "SavedClientParameters.data.cs");
File corruptedClientParametersData =
new File(
getFilesDir(),
"DATA_ServerControlledParametersManager.data.v1."
+ getBaseContext().getPackageName());
corruptedZoomTables.delete();
corruptedSavedClientParameters.delete();
corruptedClientParametersData.delete();
hasFixedGoogleBug154855417.edit().putBoolean("fixed", true).apply();
}
} catch (Exception e) {
}
Kotlin
try {
val sharedPreferences = getSharedPreferences("google_bug_154855417", Context.MODE_PRIVATE)
if (!sharedPreferences.contains("fixed")) {
val corruptedZoomTables = File(filesDir, "ZoomTables.data")
val corruptedSavedClientParameters = File(filesDir, "SavedClientParameters.data.cs")
val corruptedClientParametersData = File(filesDir, "DATA_ServerControlledParametersManager.data.v1.${packageName}")
corruptedZoomTables.delete()
corruptedSavedClientParameters.delete()
corruptedClientParametersData.delete()
sharedPreferences.edit().putBoolean("fixed", true).apply()
}
} catch (exception: Exception) {
}
Source : https://issuetracker.google.com/issues/1548554
You should call the follow method on the onCreate of your Android app to avoid the crash.
private fun clearCorruptedGMapsPreference() {
try {
val sharedPreferences = getSharedPreferences("google_bug_154855417", Context.MODE_PRIVATE)
if (!sharedPreferences.contains("fixed")) {
val corruptedZoomTables = File(filesDir, "ZoomTables.data")
val corruptedSavedClientParameters = File(filesDir, "SavedClientParameters.data.cs")
val corruptedClientParametersData = File(filesDir, "DATA_ServerControlledParametersManager.data.${packageName}")
val corruptedClientParametersDataV1 = File(filesDir, "DATA_ServerControlledParametersManager.data.v1.${packageName}")
corruptedZoomTables.delete()
corruptedSavedClientParameters.delete()
corruptedClientParametersData.delete()
corruptedClientParametersDataV1.delete()
sharedPreferences.edit().putBoolean("fixed", true).apply()
}
} catch (exception: Exception) {
LogUtil.e(this#CourierApplication::class.java.name, "An error has happened. Error: ".plus(exception.cause?.message
?: ""))
}
}
This is working code for Xamarin. You need to install Xamarin.Essentials nuget package.
if (!Preferences.Get("google_bug_fixed", false))
{
var corruptedZoomTables = new File(FileSystem.AppDataDirectory, "ZoomTables.data");
corruptedZoomTables.Delete();
Preferences.Set("google_bug_fixed", true);
}
Workaround suggested will only work one time:
I suggest to send a silent push notification to your app about Google Map Zoom Data Corrupted or make an API call to check the status of the Google Map Zoom Data. If you think this as un-necessary server call every time, you can either use push notification to trigger this logic or integrate with one of your existing calls where you check status of your servers. Leaving this to your app specific logics.Doing so, if Google Maps again throws this error you can re-trigger your work-around.
If server call, this will reset ZoomData for all your users.
If push-notifications, you can send notifications to some users.
fun receivedPushNotificationZoomDataCorrupted() {
try {
val corruptedZoomTables = File(filesDir, "ZoomTables.data")
val corruptedSavedClientParameters = File(filesDir, "SavedClientParameters.data.cs")
val corruptedClientParametersData = File(filesDir, "DATA_ServerControlledParametersManager.data.v1.${packageName}")
corruptedZoomTables.delete()
corruptedSavedClientParameters.delete()
corruptedClientParametersData.delete()
}
} catch (exception: Exception) {
}
}
We are getting IncompatibleClassChangeError in Samsung device when user update app from Play Store. Please check below log.
java.lang.IncompatibleClassChangeError: Couldn't find com.google.gson.annotations.SerializedName.value
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:659)
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641)
at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:170)
at java.lang.reflect.Field.getAnnotation(Field.java:242)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldName(ReflectiveTypeAdapterFactory.java:71)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldName(ReflectiveTypeAdapterFactory.java:67)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:142)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:83)
at com.google.gson.Gson.getAdapter(Gson.java:359)
at com.google.gson.Gson.fromJson(Gson.java:809)
at com.google.gson.Gson.fromJson(Gson.java:775)
at com.google.gson.Gson.fromJson(Gson.java:724)
at com.google.gson.Gson.fromJson(Gson.java:696)
at com.cubii.utils.SessionManager.getUserID(SessionManager.java:70)
at com.cubii.BluetoothLeService.broadcastUpdate(BluetoothLeService.java:188)
at com.cubii.BluetoothLeService.access$400(BluetoothLeService.java:47)
at com.cubii.BluetoothLeService$1.onCharacteristicChanged(BluetoothLeService.java:139)
at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:443)
at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:399)`enter code here`
at android.os.Binder.execTransact(Binder.java:446)
And code is as below:
public int getUserID(){
try {
String json = preferences.getString("User", "");
LoginResponse loginResponse = new Gson().fromJson(json, LoginResponse.class);//getting error from this line
Integer id = 0;
if (loginResponse != null) {
if (loginResponse.getId() != null) {
id = loginResponse.getId();
} else {
id = loginResponse.getUserId();
}
}
return (id == null) ? 0 : id;
}catch (Exception e){
Logger.dump(e);
}
return 0;
}
LoginResponse is my POJO class.
preferences.getString("User", "")
will return JSON String which is Server response.
Looks like a Samsung Issue .. Lot of people are having the same issue not only with gson lib but also with other libs as well .I think you can't do much about it ,only wait for Samsung developers to fix this.. Already this question is raised on samsung developer forum http://developer.samsung.com/forum/board/thread/view.do?boardName=General&messageId=280930
There are more reports of the problem here and it only affects samsung devices.
https://code.google.com/p/android/issues/detail?id=172339
Edit
Some of them are also having this issue on devices other than Samsung so it may not be completly Samsungs fault. This issue is already assigned to the Google team .And as one of the Google team member mentioned if someone can share the bug report to the team they can fix this ASAP.
After reproducing the issue, navigate to developer settings, ensure
‘USB debugging’ is enabled, then enable ‘Bug report shortcut’. To take
bug report, hold the power button and select the ‘Take bug report’
option.
Note: Please upload the bug report to google drive and share the
folder to android-bugreport#google.com, then share the link here.
Yes, this happens in most of Samsung's phones. I also got the same issue.
I got the alternative solution of it.
At first all phone's company was ignoring comments ( // or / / ) in .json File.
But now Samsung developers are not ignoring it.
So The best Solution is that you have to remove all comment ( // or / / ) lines in your .json file
Note:- this is not a perfect solution but maybe this will help someone.
i cant figure out why the following happens:
I am running an embedded apache felix from a small android application. I programmatically install 2 bundles after starting the framework, but both never enter the "resolved" state. Thereby the Bundle "MyBundle1" imports "MyBundle2".
This is what Logcat tells me:
05-17 20:21:56.514: ERROR/MainActivity(384): org.osgi.framework.BundleException:
Unresolved constraint in bundle de.xy.MyBundle1 [1]: Unable to resolve 1.11: missing
requirement [1.11] package; (package=de.xy.MyBundle2) [caused by: Unable to resolve 2.0:
missing requirement [2.0] package; (&(package=org.osgi.framework)(version>=1.5.0))]
I totally understand what the error-message says (well...org.osgi.framework in version 1.5+ cant be resolved) but i cant figure out why this happens. Why cant the framework resolve "himself"?! I tried to run the same felix.jar as standalone with the adb shell , and both bundles work. Ofcourse, the felix.jar is up to date (3.2)
Thanks for your advice!
Daniel
FelixSetup
m_configMap = new StringMap(false);
try {
m_cache = File.createTempFile("felix-cache", null);
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
m_cache.delete();
boolean mkdirs = m_cache.mkdirs(); // works (=true)
m_activator = new HostActivator(); // implements BundleActivator
List list = new ArrayList();
list.add(m_activator);
m_configMap.put(FelixConstants.LOG_LEVEL_PROP, "1");
m_configMap.put(BundleCache.CACHE_ROOTDIR_PROP, ".");
m_configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
m_configMap.put(FelixConstants.FRAMEWORK_STORAGE, m_cache.getAbsolutePath());
m_felix = new Felix(m_configMap);
try {
m_felix.start();
} catch (BundleException ex) {
Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
}
I dont know if it has something to do with the previous problems:
05-18 08:52:59.149: VERBOSE/out(363): Problem creating boot delegation class loader: java.lang.reflect.InvocationTargetException
05-18 08:52:59.209: VERBOSE/out(363): ERROR: Error parsing system bundle export statement: (java.lang.IllegalArgumentException:A header cannot be an empty string.)
05-18 08:52:59.209: VERBOSE/out(363): java.lang.IllegalArgumentException: A header cannot be an empty string.
I install and start the bundles with
myBundle1= bundleContext.installBundle("file:/data/felix/MyBundle1.jar");
myBundle2= bundleContext.installBundle("file:/data/felix/MyBundle2.jar");
myBundle1.start();
they were previously dx'ed and moved to /data/felix with adb push.
The same code I used in the android-application also works inside a regular java console-app.
The way you build up the framework looks okay to me. You could consider
replacing the FRAMEWORK_SYSTEMPACKAGES by a list that is specific for Android, if your bundles will e.g. be using Activities), or
not using a temp file, but point to some directory you know exists.
We have used 3.0.1 in the past successfully, and I do have the idea that the error message you posted has something to do with it. You could try that version of Felix, and if that works, you may have found a regression in Felix, which you can then report to users#felix.apache.org .
Today I tried including the apache.commons.codec package in my Android application and couldn't get it running. Android could not find method ord.apache.commons.codec.binary.* and output the following errors in DDMS
01-12 08:41:48.161: ERROR/dalvikvm(457): Could not find method org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString, referenced from method com.dqminh.app.util.Util.sendRequest
01-12 08:41:48.161: WARN/dalvikvm(457): VFY: unable to resolve static method 10146: Lorg/apache/commons/codec/binary/Base64;.encodeBase64URLSafeString ([B)Ljava/lang/String;
01-12 08:41:48.161: WARN/dalvikvm(457): VFY: rejecting opcode 0x71 at 0x0004
Any clue on how to solve this problem ? Thanks a lot.
I had a similar problem while using android with an OAuth library I'm developing.
I also got from android that, although I had included apache.commons.codec in the classpath, a particular method (encodeBase64String) was not found.
Checking the javadocs, both methods claim to be 1.4 and greater only, so my guess is that android already includes an older version of commons.codec where these methods are indeed undefined.
My solution was to use an older method, like this:
String encodedString = new String(Base64.encodeBase64('string to encode'));
The method you want to use is different since it replaces + and / with url-safe values - and _. So you probably might use something like:
String encodedString = new String(Base64.encodeBase64('string to encode'));
String safeString = encodedString.replace('+','-').replace('/','_');
You don't have to use apache commons, on android you can use android.util.Base64 instead.
I experienced the exact same problem. So i started browsing the android source code, and as it turns out Pablo Fernandez's guess about Android having an implementation of org.apache.commons.code.binary is correct. However, its version 1.2 of the apache commons, not version 1.4 or even 1.5.
You can see for your self in the android source.
as a note this is question is a duplicate of this post
You can use the following function:
private static String encodeBase64URLSafeString(byte[] binaryData) {
return android.util.Base64.encodeToString(binaryData, Base64.URL_SAFE);
}
source + listing of other possible flags: http://developer.android.com/reference/android/util/Base64.html
My solution to the same problem was to rename the problematic class org.apache.commons.codec.binary.Base64.java into org.apache.commons.codec.binary.ApacheBase64.java. I did it using Eclipse refactor-rename.
That way, the latest and greatest apache solution is preserved and used, and there is no chance for accidental problem recurrence when my app is eventually being lifted from android 1.6 lowest denominator.
Note I had the entire apache commons source tree already set as separate Eclipse java project, next to my Android project. My Android project used many of Apache Commons classes, but failed on Base64 because of above described problems...
You could simply copy this code bit from the apache library (it is pretty isolated)
http://www.java2s.com/Open-Source/Android/Blog-Twitter/twitspeak/org/apache/commons/codec/binary/Base64.java.htm
Edit:
Updated link from the Wayback Machine as the original is gone:
http://web.archive.org/web/20130610025148/http://www.java2s.com/Open-Source/Android/Blog-Twitter/twitspeak/org/apache/commons/codec/binary/Base64.java.htm
Please note that this answer was made by Dylan Watson in the comments above:
Be aware that you need to use Base64.encode("foobar".getBytes(),
Base64.Base64.NO_WRAP); to get exactly the same result as the apache
commons library. See: stackoverflow.com/questions/17912119
This answer was the only which worked after hours of trying to communicate my android app with a java "desktop" app.
So here is some source code, maybe it will help others:
Code from the desktop applet:
private static String convertToBase64(String s) {
byte[] bytes = new byte[0];
try {
bytes = (s.getBytes());
} catch (Exception e) {
e.printStackTrace();
}
return DatatypeConverter.printBase64Binary(bytes);
}
This snippet is used in the android app:
public static String convertToBase64(String password) {
byte[] bPwd = new byte[0];
try {
bPwd = (password.getBytes("UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
try {
password = new String(Base64.encode(bPwd, Base64.NO_WRAP), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return password;
}
You can simply import the following library under Gradle dependency
dependencies {
implementation "commons-codec:commons-codec:1.11"
}
It will work
did you include apache commons project lib,like
org.apache.commons:commons-compress
org.apache.commons:commons-email
org.apache.commons:commons-io
org.apache.commons:commons-lang3
org.apache.commons:commons-parent
org.apache.commons:commons-pool2
the commons-codec 's GAV is
commons-codec:commons-codec
but it's package name is
org.apache.commons.codec
this package name will be conflict with apache commons project libs,try to change the package name of commons-codec,then generate it as a jar or import the source code had changed the package name;
Knowing that this is an old question, but I faced this problem recently when compiling for API Level 23, and found another solution for the problem: use guava project.
// Encoding
String encodedString = BaseEncoding.base64().encode(text.getBytes(UTF_8));
System.out.println("encodedString: " + encodedString);
// Decoding
byte[] decodedString = BaseEncoding.base64().decode(encodedString);
System.out.println("decodedString: " + new String(decodedString, UTF_8));
The guava library (18.0) was the version that I've used, and the change was smooth. The code works as expected.
Solution found in here: https://memorynotfound.com/encode-decode-base64-string-using-native-java/
This works for me:
import org.apache.commons.codec.binary.Base64;
/**
* This is used to get the base64 from the bytes
*
* #param rawBytes the raw bytes
* #return the base64 encoded string
*/
public static String getBase64String(byte[] rawBytes) {
String base64Str = "";
if (rawBytes!= null) {
base64Str= new String(Base64.encodeBase64(rawBytes));
}
return base64Str;
}
public static byte[] getBase64DecodedString(String base64EncodedStr) {
byte[] base64Bytes = Base64.decodeBase64(base64EncodedStr.getBytes());
return bitmap;
}