###Set up your Android Studio environment
Install the latest version of Android Studio from http://developer.android.com/sdk/installing/studio.html. You may have to update to the latest version after launching Android Studio for the first time. Next, make sure that you have an appropriate SDK (version 2.3 to 4.2) installed and that the Android Support Repository and Android Support Library are installed. You can install these components from the Android SDK Manager. You can launch the SDK manager by opening a new project in Android Studio and then click Tools -> Android -> SDK Manager in the main menu.
###Building with Android Studio
- Download and extract Gradle (http://services.gradle.org/distributions/gradle-1.7-bin.zip) somewhere on your computer.
- Download and install the latest version of Android Studio (http://developer.android.com/sdk/installing/studio.html)
- Open Android Studio and click 'Check out from Version Control' -> 'Git'.
- In the next dialog, put
https://github.com/kl/ANTLightController.gitin the 'Git Repository URL' field and click 'Clone'. - When it asks if you want to open the project click 'Yes'.
- In the next dialog uncheck 'Use auto-import' and enter the folder where you extracted Gradle in the 'Gradle home' field. Click next and the project will now open and attempt to compile, but it will fail to do so at this point.
- Now there will be a new folder called
ANTLightControllerin your working directory. Open this folder and create a new folder in it calledlibs. - Download
android_antlib.jarand put it in thelibsfolder - http://www.thisisant.com/resources/android-ant-sdk-package/ (the jar is in theAPI/ANT v4.0.0folder) - Back in Android Studio rebuild the project by selecting 'Build' -> 'Rebuild Project' from the main menu. The build should now succeed.
###Running the application on a physical Android device
To run the app on a physical device the following prerequisites must be met:
- The device must have built in ANT support or if an ANT USB stick is to be used have the ANT USB Service Android application installed (https://play.google.com/store/apps/details?id=com.dsi.ant.usbservice)
- The ANT Radio Service Android application must be installed on the device (https://play.google.com/store/apps/details?id=com.dsi.ant.service.socket)
- The device must run an Android version between 2.1 to 4.1. Android versions lower than 2.1 are not supported by the application code, and Android versions higher than 4.1 are not currently supported by the ANT Radio Service. If an ANT USB stick is used, the device must run Android 3.1 or higher.
Once the prerequisites have been met create a run-configuration that targets the physical device like this:
- Click the button with the green Android icon to the left of the 'Play' button in the Android Studio menu.
- Select 'Edit configurations...'
- Click the + icon and select 'Android Application'.
- Under 'Module' select 'ANTLightController' and under 'Target Device' select 'USB device'. Click OK.
- Click the 'Play' button and the application will be built and then run on the USB device.
###Pulling changes to your local machine from within Android Studio
If you have cloned the repository and set up the Android Studio project as described you can easily download changes made to this repository to your local machine from within Android Studio, without using Git from the command line. To do so, click 'VCS' -> 'Update Project' in the main menu. In the next dialog select 'Merge' and 'Using Stash' and then click OK.
###Running the application on the Android emulator
- Open the SDK Manager (from Android Studio click 'Tools' -> 'Android' -> 'SDK Manager' in the main menu).
- In the SKD Manager, click 'Tools' -> 'Manage Add-on Sites...' in the main menu.
- Click 'User Defined Sites' -> 'New...'.
- Enter the following URL in the URL field and click OK:
http://thisisant.com/android/emulator/repository.xml - Back in the main SDK Manager window look under 'Android 2.3.3 (API10)' and check the 'ANT Radio' checkbox. Also make sure that the SDK platform has been installed, if not check it's box too.
- Next click 'Install packages...' and wait for the installation to finish. You can now close the SDK Manager.
- Open the AVD Manager (from Android Studio click 'Tools' -> 'Android' -> 'AVD Manager' in the main menu).
- Click the 'New...' button.
- In the next dialog select one of the pre-defined device profiles, for example 'Nexus One'. In the 'Target' field make sure to select 'ANT Radio (ANT Wireless) - API Level 10'. Click 'OK'.
- Start the emulator by selecting it and clicking the 'Start...' button.
- Once the emulator has booted, open the pre-installed app 'ANT Emulator Configuration'.
- In the 'IP Address' field enter the local IP address of your computer (on Windows you can get this info by running the
ipconfigcommand on the command line). In the 'Port' field enter9050. - Click 'Reconnect' and then click the home button to get back to the startup screen.
- If you have not done so already, download the ANT Android SDK package (http://www.thisisant.com/resources/android-ant-sdk-package/). In the SDK package folder, locate the file 'Android_ANTRadioService_4-0-0.apk' in the 'Services' folder.
- Go back to Android Studio and start the 'Monitor' tool ('Tools' -> 'Android' -> 'Monitor (DDMS included)').
- If the emulator is still running, you should see it the left side of the screen under the 'Devices' tab. Select the emulator and then click the 'File Explorer' tab. Expand the 'data' folder by clicking the arrow to the left of it, and select the 'app' folder. Next click the button with an arrow pointing right in the upper right corner of the screen labeled 'Push a file unto the device'.
- In the next dialog, navigate to the 'Android_ANTRadioService_4-0-0.apk' file and select 'Open'. You can now close the 'Monitor' tool.
- Download and extract the ANT Emulator Bridge Tool (http://www.thisisant.com/resources/ant-android-emulator-bridge-tool/).
- Start the bridge tool and click 'Connect to USB' (make sure that an ANT USB stick is connected to the computer first). Now the bridge tool should find the emulator and it should say "Found emulator" in the status window. If not, try disconnecting and connecting from the USB stick a couple of times and/or restarting the emulator.
- Finally go back to Android Studio and click the 'Play' button. In the next dialog select the emulator and click 'OK'. The app should now be uploaded to and started on the emulator.