Problems with adding a new component

I am currently playing with some ideas for expanding Canvas component, so I decided to just clone it, and then toy with its code.

TL;DR of what I have done (it might serve as reference to others):

  1. Copy Canvas.java to CanvasClone.java, I’ve renamed class to CanvasClone

  2. In YaVersion.java:

2.1 increase YOUNG_ANDROID_VERSION = 198 (+1 from 197)

2.2 add CANVASCLONE_COMPONENT_VERSION = 1

  1. In CanvasClone.java (the new component, exact clone of Canvas.java), update code to use version=YaVersion.CANVASCLONE_COMPONENT_VERSION

  2. Copy MockCanvas.java to MockCanvasClone.java, rename class name to MockCanvasClone.java

  3. In SimpleComponentDescriptor.java:

5.1 add “import com.google.appinventor.client.editor.simple.components.MockCanvasClone”

5.2 update function public static MockComponent createMockComponent() to identify MockCanvasClone

Source file references:

Canvas.java in com.google.appinventor.components.runtime

CanvasClone.java in com.google.appinventor.components.runtime

YaVersion.java in com.google.appinventor.components.common

MockCanvas.java in com.google.appinventor.client.editor.simple.components

MockCanvasClone.java in com.google.appinventor.client.editor.simple.components

SimpleComponentDescriptor.java in com.google.appinventor.client.editor.simple.palette

Basically, I’ve done the same as Topo wrote in 2014 I believe, his post can be found on GoogleGroups, now obsolete gathering point for MIT App Inventor2.

It compiled flawlessly, but when I tried to create a new project and check, this is mistake I got:

faultData = java.lang.UnsupportedOperationException: unknown component: CanvasClone

More verbosely:

notes = Browser: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0

foundIn = v181-36-g27fec76c-dirty

faultData = java.lang.UnsupportedOperationException: unknown component: CanvasClone

projectId = -1

After I reread how to add component/ property to component from documentation site here:

https://mit-cml.github.io/appinventor-sources/ I’ve found out that from September 19th 2019, one has to (semi)manually change corresponding Documentation.html, actually found here:

… appinventor/docs/html/reference/components/animation.html (component-doc.html)

It didn’t help, same mistake showed after trying to create a new project with the new component included.

I’ve then checked ComponentsTranslation.java, and CanvasClone is there. I’ve also checked following files too: simple_components.json

simple_components.txt

simple_components_permissions.json

ya_lang_def.xml

Everything was all right as I was able to discern.

Just in case, I did the same with WebViewer component, (I’ve made WebViewerClone.java etc.), in case there is something special with Canvas. Same thing happened.

Please note, if one intends to do so with WebViewer. java component, one is advised to create a new helper method setupWebViewGeoLoc in EclairUtil.java in com.google.appinvnetor.components.runtime.util where WebViewerClone is the caller.

Same mistake appeared when I was checking, trying to make a new project with a new/cloned component:

notes = Browser: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0

foundIn = v181-48-gb4bbaa77-dirty

faultData = java.lang.UnsupportedOperationException: unknown component: WebViewerClone

projectId = -1

For completeness sake, I should mention that both time I was working on a new, local branch based on a newest master at the time of the writing. In case someone is wondering, I am interested to found out how feasible is to have a possibility to add new sprites from designer. I know it is dumb, considering all the hardware/software limitations, but I ,for one reason or another, just want to find out how far they go ;).

I am sure I am missing something obvious, but clearly, atm I do not know what :). Perhaps it is Blockly related, since it compiles?

Thank you all in advance, and greetings to you all, it has been awhile since I had time for MIT App Inventor 2, I am really glad that community has grown so much.

2 Likes

As I see, everything is alright with Blockly. Thus, I am missing, hopefully, only one place where “new” AndroidVisualComponent has to be added.

Above in TL;DR is what I have done so far. Ideas?

Hi @Tomislav_Tomsic,

The error you’re seeing is generated in appengine/.../SimpleComponentDescriptor.java. Visible components need to have their own mocks, and there is a function there that maps the component type name to the class that needs to be instantiated for it. You’ll need to add a branch for your new clone component.

Thanks for the reply :). I presume function’s name is createMockComponent in SimpleComponentDescriptor.java? If so, I did that, in both cases (Canvas and WebViewer), and there in that method, “unknown component” is thrown, which explains my confusion.

But now, while I am writing this, it occurred to me that I may use incorrect Java version. Once I had problem with visibility of components in designer, and that was the problem lol. Currently I have at least 5 versions of Java on my system (from Oracle and OpenJDK). I do hope that is the problem, and tomorrow (CET timezone) I’ll have some time to play with that, and I’ll write the result here.

Once again, thanks for the reply :).

You’ll want Java 8 to build App Inventor.