NEON API with Android Studio

Sarah Blaszak -

Neon API with Android Studio

This guide covers the process of using the Neon API with Android Studio.

Get Required Software

  • Download & Install the latest version of Android Studio & the Android SDK.
  • Download & Upzip the "Neon API" zip file from the Neon Downloads website.

Create a New Project

  • Create a new project in Android Studio by selecting File -> Create New Project.
  • Enter an Application name, and choose your package name appropriately. Set or take note of the Project location on disk, you will need it in a moment.
    • Tip: To avoid issues down the road, you may want to restrict your application name and chosen project location to alphanumeric values. Depending on the platform and the build tools, spaces and various other characters may need to be escaped through multiple build layers.
  • Select Phone and Tablet as the form factor for your app. We recommend keeping the Minimum SDK at its default value.
  • Choose Add Empty Activity, and name the activity MainActivity for now.
  • These steps will bring up the project view of Android Studio to show you the code of your new project.

Add NeonAPISample to Project

  • Right-click your module in Android Studio and select Show In Explorer.
  • Navigate to src/main/java/.
    • You should see a folder here named with the first part of your chosen package name (e.g. com).
    • Delete this folder and replace it with the com folder in NeonAPISample/src.
  • Navigate to src/main/.
    • Replace the res/ folder with the NeonAPISample/res folder.
    • Replace AndroidManifest.xml file with the NeonAPISample/AndroidManifest.xml file.
  • Within your module, you should now see a package, com.trx.neon.sample with two Activities, MainActivity and NeonMock.

Import NeonAPI

  • Create a new module in Android Studio by selecting File -> New -> New Module.
  • Select Android Library.
  • Name the module "NeonAPI".
  • Right-click the NeonAPI module in Android Studio and select Show In Explorer.
  • Navigate to src/main/java.
  • Delete the folder here (e.g. com) and replace it with the com folder in NeonAPI/src.
  • When you switch back to Android Studio, you should now see a com.trx.neon package with a number of packages beneath it containing the code of the NeonAPI.

Configure Gradle

  • If you looked closely at the files within the NeonAPI, you would see that there is a mix of .java and .aidl files.
  • Android Studio needs to be told to compile .aidl files at this location.
  • Within the build.gradle file for the NeonAPI module (accessible in the Gradle Scripts section at the bottom of the Project window) we must add a new section.
  • Inside of the android { } section of the file, copy this snippet to let Android Studio know to search for and compile these .aidl files.

    sourceSets { main { aidl.srcDirs = ['src/main/java'] } }

  • Inside of the dependencies { } section of the file, copy this snippet

    compile 'com.google.code.gson:gson:2.4'

  • Tip: Now is a good time to double check that your NeonAPI module is laid out in the expected way on disk. It should appear asProjectName/ModuleName/src/main/java/.... If this is not the case, or if gradle cannot open the src/main/java directory for any reason, you will get a number of obscure gradle build errors.
  • You can now select the NeonAPI module, and build it from the build menu at Build -> Make Module 'NeonAPI'.
  • Within the build.gradle file for your application, we must add a dependency.
  • Inside the dependencies { } section of the file, copy this snippet to let Android Studio know to link the project

    compile project(':NeonAPI')

 

Have more questions? Submit a request

Comments

Powered by Zendesk