App Inventor build extension fails to import Android class in helpers subdirectory

Please check the documentation

Adding Helper Blocks to a Component and How to add a Dropdown Block to a Component
Taifun

1 Like

Thanks! I can import classes from the helpers directory correctly but I'm not succeeding when I try to import classes from Android (import android)..

There is no need to do this
Just folliw the examples

Taifun

Out of curiosity, is there a way to do this in helpers?

import android.content.Context;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

No.

Thanks

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

Context

  • Recently I researched how to import Android classes into classes that are in the helpers directory, look here. Not finding a solution, I went searching and modified the build.xml file. So, to be able to import the classes, follow the steps below:

  • Change the code below:

   <ai.javac destdir="${CommonConstants-class.dir}">
      <include name="**/helpers/*.java" />
      <include name="${components.pkg}/common/*.java" />
      <exclude name="${components.pkg}/common/HtmlEntities.java" />
    </ai.javac>
  • per:
    <ai.javac destdir="${CommonConstants-class.dir}">
      <include name="**/helpers/*.java" />
      <include name="${components.pkg}/common/*.java" />
      <exclude name="${components.pkg}/common/HtmlEntities.java" />
 
	        <classpath>
	            <pathelement location="${android.lib}" />
	        </classpath>
    </ai.javac>

Can you write what is the purpose of this? What do you really want to achieve?

I asked the community a question about importing the Android libraries into the helpers directory. I tried to send the solution via the original post, but it was already closed.

Then why didn't you remove the solution marker?

I understand, but I'm asking about programming, what are you trying to do with the helpers?

2 Likes

I was trying to import classes of the type below in the helpers directory:

import android.media.MediaRecorder;

By default, when using "ant extensions" it gives an error, classes of this type are not found in the helpers directory, but only in the main file.

Yes, but why do you think, you need this there?

Taifun

It is not necessary to return values ​​from other classes. Just return invented Integer values ​​from the helpers, and in the main extension code use the "Switch Case" to use the appropriate values ​​from the MediaRecorder class.

I understand, it was a class example. The tip applies as a general rule.

1 Like

Have you checked your method with companion and apk?

Yes!

The extensions system follows many of the rules from the main build system. For this particular example, helpers are defined in the components/common portion of the App Inventor code base, and these classes are shared between both the Android code and the client side code that runs in the browser. Therefore, it was never intended that the Android classes be available (since the web browser is not an Android environment). This will "fix" your issue at the expense of not being able to build the whole of App Inventor.