How do I add a jar file on extension?

How to add jar file on extension please help me.

Are you using extension template or ai2 sources for your extension??

1 Like

Ai2 sources

1 Like

Hi @Mia_Khalifa welcome to our community!

Before adding a library to your extension, make sure you already have an offline extension builder such as appinventor-source, extension-template-repository or Rush.

For the extension template you need to add the library in lib/deps folder.
For the app Inventor Sources add the library in the lib/JarFolder folder ( create the JarFolder folder of it isn't created )
For the app Inventor Sources you will need to edit the appinventor/components/build.xml file and add this line:

<copy toFile="${public.deps.dir}/JarName.jar" file="${lib.dir}/JarFolder/JarName.jar" />

In both cases you will need to add the UsesLibraries annotation:

@UsesLibraries(libraries = "JarName.jar")

Before the extension class definition:

public Class extends AndroidNonVisibleComponent {

Adding it before or after the @SinpleObject annotation or the @DesignerComponent annotation shouldn't matter.