Using Android SDK and external libraries

326 views
Skip to first unread message

Red Panda

unread,
Feb 14, 2018, 6:22:51 AM2/14/18
to App Inventor Open Source Development
Hello,
I'm having a hard time figuring out how to include some Android SDK features. Note that I'm not familiar with Android SDK, but with Java. Maybe I can try putting together an overview in this thread. Here are some assumption I have, please reply if there is anything wrong. I will mainly focus on those features which can be put in an extension (that's what I'm aiming for)
  • The document here is up-to-date and everything is described there
  • One can add Android SDK features, but they only work if the device has the specified minSDK
  • One can add Java libraries with the @UsesLibraries and @UsesNativeLibraries annotations. The .jar or .so file has to be placed in the appinventor/lib/ folder
  • One can add Android aar packages
  • If the new component uses external classes, the class' Java file has to be put in the same folder as the component's file
  • One can add permissions with the @UsesPermissions annotation
Here are some questions I still have
  • I'm getting the error "The package android.support.design.widget does not exist". Is that because I did not add the file to appinventor/lib/android/support/ ?
  • Where do I have to put aar packages if I have some?
- Greetings, Red Panda

Evan Patton

unread,
Feb 14, 2018, 5:43:52 PM2/14/18
to App Inventor Open Source Development
Hi Red Panda,

AARs are only currently supported as part of the core system, so assuming this question isn't with the intention of using an AAR for an extension, you should consider the following:

Handling of AAR libraries is a bit of a hack in our build system since they bundle code and other assets together, but the ant build system requires the code on the classpath to be accessible as JAR files. To do this, I extract the classes.jar file from the AAR and rename it to the same stem, but with .jar instead of .aar, and delete the classes.jar from the .aar (e,g., foo.aar becomes foo.jar and foo.aar - foo.jar). You add the .jar file as a dependency in components/build.xml. There will also need to be copy rules added to buildserver/build.xml for both the jar and aar. The buildserver will extract and merge all of the AAR files to create the final set of resources bundled in the compiled app. In the @UsesLibrary annotation, include both the aar and jar filenames.

If you would like to see a specific example, look at the Map component's annotations and the components/build.xml and buildserver/build.xml for references to osmdroid.

Regards,
Evan

Red Panda

unread,
Feb 15, 2018, 7:34:22 AM2/15/18
to App Inventor Open Source Development
Thank you for your explanation, I'll take a look at it.

Red Panda

unread,
Feb 22, 2018, 7:38:02 AM2/22/18
to App Inventor Open Source Development
I added this library and it seems to work now, although I have to address the libraries with their full name, e.g. android.support.design.widget.Snackbar instead of just Snackbar. I still haven't found an easy way to get the aar and jar packages, if someone has some tips, please write them here so we can all benefit from your knowledge.

Evan Patton

unread,
Feb 22, 2018, 9:27:53 AM2/22/18
to App Inventor Open Source Development
Could you clarify what exactly you mean by "an easy way to get the aar and jar packages"? If you are attempting to obtain them, they are typically found in the extras/ directory in the Android SDK. If you are looking to get your hands on the JAR that is associated with the AAR, I just use the following command:

unzip -p library.aar classes.jar  > library.jar

If there is something more specific you need information on, please provide more details.

Cheers,
Evan

Red Panda

unread,
Feb 23, 2018, 11:31:03 AM2/23/18
to App Inventor Open Source Development
This is what I meant and it's very useful for me. Thank you!

- Red Panda


Am Mittwoch, 14. Februar 2018 12:22:51 UTC+1 schrieb Red Panda:
Reply all
Reply to author
Forward
0 new messages