Import Project into Google Android Studio

This example shows you how to import and build a project generated from a Simulink® model in the Google Android Studio IDE.

  1. 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

    • Android SDK Platform

    • Android Virtual Device

    • Performance

    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.

    Note

    This installation process requires you to download and install a version of the Java runtime environment (JRE).

  2. Open the Simulink model Getting Started with Samsung® GALAXY® Android® Devices.

    androidGettingStartedExample

  3. 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.

  4. 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.

    getAndroidSLSupportPkgToolPaths
    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'
  5. Open Android Studio and select Import project (Eclipse ADT, Gradle, etc).

    Note

    The first time you open Android Studio, you must select a UI Theme.

  6. Select the second-level project folder with the same name as the project. For example, in the androidGettingStatedExample_ert_rtw project, select the androidGettingStartedExample_ert_rtw\androidGettingStartedExample folder.

  7. Click OK to open and import your project into the Android Studio IDE.

    Note

    When the project first loads, ignore any errors shown in the Android Studio IDE. These errors are resolved in the following steps.

  8. In the Android Studio IDE window, select File > Project Structure.

  9. 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 getAndroidSLSupportPkgToolPaths. Click OK.

  10. On Windows®, in the Android Studio IDE, select File > Settings.

    On Mac, in the Android Studio IDE, select Android Studio > Preferences.

  11. In the Settings (Windows) or Preferences (Mac) window, select Build, Execution, Deployment > Build Tools > Gradle.

  12. Select Use local gradle distribution and set Gradle home to the Gradle path returned by getAndroidSLSupportPkgToolPaths previously. Then click OK.

    Warning

    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.

  13. In the Android Studio IDE, select Build > Clean Project to clear the original project and path settings.

  14. After the project clean completes, select Gradle tab on the right side to expand the Gradle projects pane.

    Note

    If you cannot see any files or folders in the Gradle projects pane, click the Refresh button .

  15. In the Gradle projects pane, double-click androidGettingStartedExample > androidGettingStartedExample (root) > Tasks > build > assembleDebug to build the Android application package (APK).

  16. In the Android Studio IDE, from the Run/Debug configuration list in the tool bar, select androidGettingStartedExample.

  17. Click the Run button to open the Choose Device window.

  18. In the Choose Device window, select your connected device. Click OK to deploy and run the app on the selected device.