Extension behave differently in companion mode

I've experienced some strange behaviour lately as I've been trying to fix some issues with one of my extensions in the last couple of weeks. I always test my extensions in a small demo app, to make sure it is working properly. I thought I had it fixed, because everything seems to work, but as I returned today to check again, the bug was there again. I did not upload anything since then. Does the platform has some kind of cache or when are the files from an extension loaded onto the phone? I've gone crazy over this behaviour the last days. Has anyone experienced similar behaviour?

Which plattform are you talking about?
Did you test with Companion or APK?

PS: Of course I know that you are an experienced developer, but I try to understand your question, because sometime I also get strange results ... (using Companion). So I always test (my extensions) with the APK.

I don't know whether to call it cache or not but sometimes I need to reconnect to companion 2-3 times to get latest version working.

I'm trying to test new extension versions with the App Inventor companion. I have similar problems to what @vknow360 reports and I will try his solution of reconnecting a few times. I really want to get behind this, because it's really annoying. I'm not sure what's causing this

How about deleting the AppInventor or the assets folder (in which the extensions are saved) beforehand (before testing).

For devices with API < 29:

/storage/emulated/0/AppInventor/assets/

for devices with API ≥ 29 (the assets or external_comps folder):

/storage/emulated/0/Android/data/<packageName>/files/assets/

Example (Pixel 2XL, Android 11 (Beta), API 30:

There is a dex/art cache on newer versions of Android. It's in the app private directory and I'm not clear that we are able to clear it. Assuming you're absolutely certain that you're using the right version of the extension (double check by bumping the version number to something unique for testing), you may want to try using the clear caches button for the companion app in settings and reconnect your project. If that doesn't work, you can try uninstalling and reinstalling the companion app and see if that fixes it.

1 Like

Now it gets really weird. I assured that I'm using the correct extension version and deleted the external_comps directory. My function works as expected on my Android 6 device, but not on my Android 10 device. The function only uses YailLists.

After adding some Android 10 specific code, the function works in both versions. I will check in the next days, if the behaviour changes

The behaviour was most likely a combination of both problems. I have two key takeouts here:

  1. If you are testing extensions and upload at a fast pace, better delete the external_comps folder to assure that you are testing the newest version
  2. The YailList behaves different with different Android versions, so keep that in mind when developing extensions. Although I don't think that the problem appears in a regular use case

Can you explain what your observed differences are with YailList? There's no reason for it to behave differently on different version. It's written to be version agnostic and works even on regular Java since we use it in unit tests.

1 Like

I have a comparing function that takes a walkingPath similar to the dictionary walking path.

public int compare(Object o1, Object o2) {
      int result = 0; //failsafe
      if (walkingPath != null) {
        for (int i = 0; i < walkingPath.size(); i++) {
          try {
            final int idx = ((gnu.math.IntNum) walkingPath.getObject(i)).intValue() - 1;
            o1 = ((YailList) o1).getObject(idx);
            o2 = ((YailList) o2).getObject(idx);
          } catch (ClassCastException e) {
            throw new RuntimeException("Class cast failed. The error Message was " + e.getLocalizedMessage());
          } catch (IndexOutOfBoundsException e) {
            throw new RuntimeException("Index out of bounds. The error message was " + e.getLocalizedMessage());
          }
        }
      }
      return new YailListComparator().compare(o1, o2);
    }

I tested this with Android 6 and 10. On Android 6, the following error is thrown: Class cast failed. The error Message was gnu.mapping.SimpleSymbol cannot be cast to com.google.appinventor.components.runtime.util.YailList

I suspect that it has to do something with the YAIL_HEADER

Yes, the first element of a YailList is always the Scheme symbol *list*. This makes it so that the 1-based indexing works in the blocks language and keeps things somewhat consistent between the Java and Scheme sides of the code. The Android 6 error message is correct and what I would expect. Modulo dex caching issues, etc. I would expect the exact same error on Android 10. This may be more apparent if you build the APK and install it fresh rather than reloading the app in the companion.

I checked and it works the same if I install the APK. It even gets weirder: Calling SortBy(list, YailList.makeEmptyList()); from the extension behaves differently than calling grafik
from the blocks

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.