1 | initial version |
Android Studio uses gradle as the build system for Android projects. Until the OpenCV Android SDK ships with support for gradle out-of-the-box, I find it easiest to first convert the SDK to a gradle project from Eclipse before using it from Android Studio. To do this:
OpenCV-2.4.6-android-sdk/sdk/java
sub-directory and not the top-level OpenCV-2.4.6-android-sdk
directory as the instructions on that site suggest.Your copy of the OpenCV Android SDK should now be properly configured to be built by gradle. To use it from a new project in Android Studio:
OpenCV-2.4.6-android-sdk/sdk/java
directory to MyApplicationProject/opencv-android
).Open MyApplicationProject/settings.gradle
and add ':opencv-android'
to the include line. The new line should look similar to this:
include ':MyApplication', ':opencv-android'
Open MyApplicationProject/MyApplication/build.gradle
and add "compile project(':opencv-android')
" to the dependencies
section. Make sure this is the top-level dependencies
section and not the one inside of the buildscript
section at the top of the file. The new dependencies
section should look similar to this:
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile project(':opencv-android')
}
Your new project can now use the OpenCV Android SDK from Android Studio. For example, you should be able to implement the "Hello World" example from the OpenCV Android tutorial (skip all of the Eclipse setup instructions and just make the layout, Android manifest, and main activity changes inside MyApplication).
2 | No.2 Revision |
Android Studio uses gradle as the build system for Android projects. Until the OpenCV Android SDK ships with support for gradle out-of-the-box, I find it easiest to first convert the SDK to a gradle project from Eclipse before using it from Android Studio. To do this:
Make sure you have the latest version of the Eclipse ADT plugin installed.
Download and extract the OpenCV Android SDK (e.g. OpenCV-2.4.6-android-sdk-r2.zip)
Open Eclipse and import the OpenCV Android SDK using the instructions on the OpenCV website. Note: When selecting the root directory to import, use the OpenCV-2.4.6-android-sdk/sdk/java
sub-directory and not the top-level OpenCV-2.4.6-android-sdk
directory as the instructions on that site suggest.
Select File > Export. In the window that appears, open Android and select Generate Gradle build files.
Your copy of the OpenCV Android SDK should now be properly configured to be built by gradle. To use it from a new project in Android Studio:
Copy/move your copy of the OpenCV Android SDK into the new project directory (e.g. copy the OpenCV-2.4.6-android-sdk/sdk/java
directory to MyApplicationProject/opencv-android
).
Open MyApplicationProject/settings.gradle
and add ':opencv-android'
to the include line. The new line should look similar to this:
include ':MyApplication', ':opencv-android'
Open MyApplicationProject/MyApplication/build.gradle
and add "compile project(':opencv-android')
" to the dependencies
section. Make sure this is the top-level dependencies
section and not the one inside of the buildscript
section at the top of the file. The new dependencies
section should look similar to this:
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile project(':opencv-android')
}
Your new project can now use the OpenCV Android SDK from Android Studio. For example, you should be able to implement the "Hello World" example from the OpenCV Android tutorial (skip all of the Eclipse setup instructions and just make the layout, Android manifest, and main activity changes inside MyApplication).