How can I include an external library while building app?

In Compiler.class, I want to include an external library(.jar) while building app.

I seen SUPPORT_JARS variable in Compiler.class but it doesn't seems to include external lib. I think it lists libs which can be compiled in apk(all jar libraries). Is there any other way to do this ?

Thanks

Sir @ewpatton, Kindly have a look here

Sir @ewpatton , Please help

The support jars list is only for those libraries required by all App Inventor apps due to transitive dependencies from Android library such as appcompat. For per-component libraries. you need to add the library under lib/ and then include the libraries in components/build.xml in the CopyComponentLibraries target. You will then need to include the library using the @UsesLibraries annotation on the component class. For an example, see how CloudDB imports jedis.jar.

2 Likes

Thanks but I actually want to know how can i include an .jar while compiling the app in Compiler.java in buildserver. Is there any way to do it ?

Is the .jar file intended for a specific component or the entire app? It's fairly rare outside of the AndroidX libraries to need to add a library that applies to every application built with App Inventor.

1 Like

I have two jars. I want to include one of them in building process if app have status bar visible I need to include the first jar and if it's invisible then, I want to include the other jar. I know how to get ShowStatusBar value in compiler.java in buildserver. But I don't know how can I include the jars in compilation process ?

This post was flagged by the community and is temporarily hidden.

This post was flagged by the community and is temporarily hidden.

I believe it's possible. I think what you would need to do is add the library conditionally to uniqueLibsNeeded in generateClasses. You'll also need to append it to the classpath variable in that function as well, which is used as part of the compiler call.

1 Like

Thanks sir @ewpatton :heart_eyes:

Sir @ewpatton , I tried but I only know the jar name which is stored in libs. When I tried to print the uniqueLibsNeeded. it gives this path

C:\Users\user\AppData\Local\Temp\core-1.9.0774445760271285672.jar

This is not working

uniqueLibsNeeded.add(getResource(RUNTIME_FILES_DIR + "custom.jar"));

You still use useslibraries annotaion?

If you have an enrivonment with unzip (e.g., Cygwin), what is the output of:

unzip -l buildserver/build/run/lib/BuildServer.jar

Do you see your JAR file in the list?

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