This example shows you how to import and build a project generated from a Simulink® model in the Google Android Studio IDE.
Download and install Google Android Studio IDE.
As part of the Google® Android™ Studio installation process, you can optionally choose to install the following components:
Android SDK Platform
Android Virtual Device
These components provide extra functionality within the Android Studio IDE but are not required to build projects created with the Simulink Support Package for Android Devices.
This installation process requires you to download and install a version of the Java runtime environment (JRE).
Open the Simulink model Getting Started with Samsung® GALAXY® Android® Devices.
Press the Deploy to Hardware button to build and deploy the Simulink model to your Android device. For additional instructions on how to configure a model for deployment to an Android device, see the Getting Started with Samsung® GALAXY® Android® Devices example.
The Android Studio IDE requires the same tools that Simulink used to build the
project. Execute the function
getAndroidSLSupportPkgToolPaths at the MATLAB® command line to get the tool paths.
ans = AndroidSDKLocation: 'F:\share\apps\RTT\Android\v003\win64\android-sdk-24.3.4' JDKLocation: 'F:\share\apps\RTT\Android\v003\win64\jdk1.7.0_79' AndroidNDKLocation: 'F:\share\apps\RTT\Android\v003\win64\android-ndk-r12' GradleHome: 'F:\share\apps\RTT\Android\v003\gradle-2.4' OpenCVLocation: 'F:\share\apps\RTT\Android\v003\opencv-android-sdk'
Open Android Studio and select Import project (Eclipse ADT, Gradle, etc).
The first time you open Android Studio, you must select a UI Theme.
Select the second-level project folder with the same name as the project. For
example, in the
Click OK to open and import your project into the Android Studio IDE.
When the project first loads, ignore any errors shown in the Android Studio IDE. These errors are resolved in the following steps.
In the Android Studio IDE window, select File > Project Structure.
In the Project Structure window, select SDK
Location from the left pane. Then set the Android
SDK location and JDK location fields to the
values returned by
On Windows®, in the Android Studio IDE, select File > Settings.
On Mac, in the Android Studio IDE, select Android Studio > Preferences.
In the Settings (Windows) or Preferences (Mac) window, select Build, Execution, Deployment > Build Tools > Gradle.
Select Use local gradle distribution and set
Gradle home to the Gradle path returned by
getAndroidSLSupportPkgToolPaths previously. Then click
Android Studio will prompt you to update the Gradle and SDK tools. Do not update these tools. The Simulink Support Package for Android Devices requires specific versions of these tools to guarantee the supported features.
In the Android Studio IDE, select Build > Clean Project to clear the original project and path settings.
After the project clean completes, select Gradle tab on the right side to expand the Gradle projects pane.
If you cannot see any files or folders in the Gradle projects pane, click the Refresh button .
In the Gradle projects pane, double-click androidGettingStartedExample > androidGettingStartedExample (root) > Tasks > build > assembleDebug to build the Android application package (APK).
In the Android Studio IDE, from the Run/Debug
configuration list in the tool bar, select
Click the Run button to open the Choose Device window.
In the Choose Device window, select your connected device. Click OK to deploy and run the app on the selected device.