Generating AAR file for use in android studio

1,841 views
Skip to first unread message

Egbert Boer

unread,
May 28, 2015, 10:23:15 AM5/28/15
to ioio-...@googlegroups.com

Generating AAR file for use in android studio.

I did a small write up for people who want to use IOIO library in android studio.

Open android studio and open a new project.

Application name IOIO

Add no activity.

Select file new module  > android library.

Application name and module name : ioio

Add no activity.

Now download the latest package from IOIO website and extract.

Goto \IOIOLib\src\ioio\lib select directorys api, impl, spi, util.

In android studio in the project tree

Drag the selected folders from explorer into android studio in the re.ioio directory.

Next goto IOIOLib\target\android\src\ioio\lib\util select all file and folders inside util.

Drag the selected folder & files from explorer into android studio in the re.ioio\util directory.

Next goto IOIOLib\target\android\src\ioio\lib\spi select all file and folders inside util.

Drag the selected folder & files from explorer into android studio in the re.ioio\spi directory.

Now do the same for the directory: IOIOLibAccessory, IOIOLibAndroidDevice, IOIOLibBT

In IOIOLib\target select target android or pc and drag and drop files in your project tree

Select the ioio top folder int the project tree and right click on it. Select replace in path.

Fill in the fields as shown on the picture, don’t forget to select scope > whole project

A dialog will appear select > all files.

Make sure you have google API installed in the SDK manager.

Now your ready to build. Select Build > Make project.

Your AAR file will be in \IOIO\IOIO\ioio\build\outputs\aar.

 

How to use the aar file:

In android studio create new project, with blank activity.

Copy the AAR file to \MyApplication\app\libs.

In build.gradle (module) add:

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:appcompat-v7:22.0.0'

        compile(name:'ioio-debug', ext:'aar')

    }

    repositories{

        flatDir{

            dirs 'libs'

        }

    }

 

In AndroidManifest.xml add:

    <uses-permission android:name="android.permission.BLUETOOTH" />

    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

    <uses-permission android:name="android.permission.INTERNET"/>

Library path use re.ioio instead of ioio.lib

 

Troubles: android app future.usb.usbmanager not found.

the solution is using android.hardware.usb instead of com.android.future.usb

.getInstance(wrapper); not found. In Adapter.java

 

If i test my app is says my firmware is incompatible. What am i doing wrong here?

 

Ytai Ben-Tsvi

unread,
May 28, 2015, 2:38:50 PM5/28/15
to ioio-...@googlegroups.com
Thanks for sharing that.
I'm actually in the middle of converting everything to Gradle, then adding AS support and upload packages to Maven, so hopefully your tutorial will not be needed for much longer.
As for your questions:
  • android app future.usb.usbmanager not found: you need to use the "Google-API" version of the SDK. For example, in my (yet unpublished) Gradle scripts, I'm building IOIOLibAccessory with compileSdkVersion "Google Inc.:Google APIs:12".
  • my app is says my firmware is incompatible: This is pretty self-explaining. Upgrade your firmware...

--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Egbert Boer

unread,
May 29, 2015, 6:30:41 AM5/29/15
to ioio-...@googlegroups.com
This is pretty self-explaining. Upgrade your firmware... :  

ioiolib: ioio0504
aplicationfirmware: ioio0400
bootloaderfirmware: ioio0411
hardware: SPRK0016

according to the tables of your download page this should be compatible ;)


Ytai Ben-Tsvi

unread,
May 29, 2015, 7:26:32 AM5/29/15
to ioio-...@googlegroups.com

How so?
The major version of the firmware always needs to be >= major version of IOIOLib. In your case you're using a v5.x IOIOLib with a v4.x firmware.

Egbert Boer

unread,
May 29, 2015, 8:40:43 AM5/29/15
to ioio-...@googlegroups.com
oops! update the firmware to 0500 and now it works! thank you

Mohnish Kumar

unread,
Jun 4, 2015, 10:24:56 AM6/4/15
to ioio-...@googlegroups.com
Cant see any images?

Karim Virani

unread,
Jun 5, 2015, 2:13:41 PM6/5/15
to ioio-...@googlegroups.com
Ytai, I'm looking forward to your impending AS support - do you have a timeline on it?  Should we be able to build a working app from your gradle branch as it is now?

In the meantime, Egbert, I'd really love to follow your process, but the images are not visible to us.  Inspecting the source it looks like you may have pasted from a word doc?  Anyhow, the image sources point to files on your local windows system, so you are the only one who can see them at the moment.  Hope you get a chance to update your writeup.

Thanks.

Ytai Ben-Tsvi

unread,
Jun 6, 2015, 1:41:21 AM6/6/15
to ioio-...@googlegroups.com
I pushed the current state of my work to GitHub under the 'gradle' branch.

Status summary:
  • Complete Gradle build support for everything, including generating the software release bundle. If you run 'gradle build' from the software directory you'll get all the libraries and software apps generated, including the AAR you were asking about. 'gradle bundle' would create a zip file in the release directory containing all the artifacts, sample apps, javadoc, etc.
  • Eclipse support is now not great. All the projects have been converted to Gradle projects, but it seems like Eclipse doesn't work seamlessly with Gradle, so it is more convenient to build from command line.
  • Haven't yet tried to import into AS, though it should be close to trivial now. I recommend importing the entire software directory as one project for now. In the future I'll make it simpler.
  • Haven't yet uploaded the JAR/AAR to Maven Central, although I intend to. At the end of this process it will be fairly easy to write a IOIO app from scratch without having to download much or anything at all.
  • I can't promise to answer any question you might have about this. It is all work in progress still. There's also still no documentation on the Wiki yet on how to work with the new stuff. I believe you should be fine if you have some experience with AS/Gradle.
  • There might be non-compatible changes by the time I actually release this. Probably nothing radical though.
  • I would highly appreciate any feedback, as most of this stuff is new to me and I might have done things in a suboptimal way.

Karim Virani

unread,
Jun 7, 2015, 9:58:48 PM6/7/15
to ioio-...@googlegroups.com

Thanks for pushing this forward! With my feedback you get a noob perspective with regard to AS and gradle.  Hopefully this will help you harden your solution against beginner mistakes. I'm also responsible mentoring a couple of high school robotics teams into developing with IOIO and AS. So I'll be pulling more noobs along with me. 

I followed your advice and began with importing the entire software folder as a gradle project.  From there I just accepted any defaults it recommended. It needed a lot of old and/or deprecated android or google APIs downloaded. I had to download API levels 7, 10 and 12.  Perhaps this transition to AS is a good time to update some of the older references scattered throughout the project.  I plan to target a minimum API of 14 or 15 which gets us into ICS and supporting over 95% of all active android phones. By getting us to android 4+ we also get the more robust software fusion sensors that improve motion estimation.  This is helpful in robotics and potentially reduces the number of external sensors required. 

It couldn't build IOIOManager because it's defined as a release build, but (appropriately) you didn't include your keystore properties in the repo:

> Could not find property 'RELEASE_STORE_FILE' on SigningConfig_Decorated{name=r...

I toyed with supplying info for my own keystore, but then thought maybe I shouldn't be building IOIOManager since it's a utility you already publish in Google Play and it isn't really meant to be the foundation of a user app?  So instead I removed:
 'applications/IOIOManager',
from the android section in settings.gradle in the software folder.

This allowed gradle to proceed building.

The next hurdle I ran into was a problem with git:

Error:(56) A problem occurred evaluating root project 'software'.
> Cannot run program "git": CreateProcess error=2, The system cannot find the file specified

As a github for windows user, I was content with using the git shell it provided.  I even had the path to the portable git bin folder configured in AS.  But I think the gradle build wants the system path to be able to find git in the regular cmd shell.

After restarting AS I was able to continue the build and it finally completed the gradle build with only the warning about file encoding settings.

It then popped up a dialog to add a bunch of generated .iml files to git.  I'm not sure if these should be added or gitignored?  I cancelled that dialog.

The AAR files for the main libraries were successfully created!

But none of the android apps were built. If I try running the gradle build for a specific app (either run or debug from within AS), it reports the build is successful but doesn't generate an apk or even create a build folder. It's like it doesn't think it needs to do anything.  

I'm not sure where to go from here.

Thanks for any guidance you can provide.

Egbert Boer

unread,
Jun 8, 2015, 4:50:18 AM6/8/15
to ioio-...@googlegroups.com
Is anyone still in need for the images? As i understand it is no longer needed?

You received this message because you are subscribed to a topic in the Google Groups "ioio-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ioio-users/Q9RsTm7ic_8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ioio-users+...@googlegroups.com.

Karim Virani

unread,
Jun 8, 2015, 1:32:37 PM6/8/15
to ioio-...@googlegroups.com
I'm still curious about the images but that's not a good enough reason, I withdraw my request

I am now able to build the applications - noob issue.  I found that if you browse in the project explore to each application's build.gradle file and open it, you'll get a message at the top:

This folder does not belong to a Gradle project. Make sure it is registered in settings.gradle.

To right of this there is an Add Now... link that will do this for you.

Click the link and it will start a Gradle sync and create a run/debug configuration for you. After that the application name will appear bolded in project explorer and you can run it on your phone.

For HelloIOIO, the settings.gradle line appended looks like this:

project(':HelloIOIO').projectDir = new File('applications/HelloIOIO')


I tried directly adding similar lines for the other sample apps, but that did not work - it would say the project could not be found.  But the Add Now... link does work and also generates a new iml file for the subproject which has a different name than the one generated by the original import to AS.

I'm still trying to understand how to enable debugging while connected to the board via usb.  I have a wifi adb connection established with the phone, but it dies when I disable usb debugging on the phone so the IOIO can connect.  But I'll open that as a separate thread if research fails me.

Ytai Ben-Tsvi

unread,
Jun 13, 2015, 6:39:40 PM6/13/15
to ioio-...@googlegroups.com
I'm not going to answer the AS questions, since as I said this is not yet completed. You asked for AARs and you got them. If you want more help, use Eclipse for now.
Regarding debugging, you have several options. The easiest one is using Bluetooth for the Android : IOIO connection and then USB for debugging. Alternatively, connect the IOIO to a PC over USB and run IOIOBridge (more info on the Wiki).
 

Karim Virani

unread,
Jun 15, 2015, 6:54:13 PM6/15/15
to ioio-...@googlegroups.com
Thanks for the ability to build the AARs.  I am happily up and running with IOIO on Android Studio - I was just sharing my experiences so others new to this development model could benefit from it and maybe it might help inform your efforts to formalize AS support.  I was not trying to create new workload for you.  I've also been able to get opencv for android incorporated so that their color blob detector example can drive servos through the ioio to track a moving object.

I am mostly using Bluetooth to communicate with the IOIO while debugging.  I was just looking for a lower latency solution for when I move to direct PID motor control in my robot's android app for balance control.  I've looked at your Shoebot project and hope to do something similar.

Again, thanks for making and continually improving this platform.

Karim
 

Message has been deleted

Raymundo Cornejo

unread,
Aug 3, 2015, 4:26:29 PM8/3/15
to ioio-users
Hi, great steps to follow. I only ran into the following problem: "Error:(265, 11) cannot find symbol variable Version"
I think this is due to the JDK that I am using. If so, which JDK should I use to compile the project?

Also, I tried the Add Now link and for some projects it keeps saying that the folder does not belong to the Gradle project.

Thank you
Reply all
Reply to author
Forward
0 new messages