aidl is missing android studio - android

Environment:
Mac OS 10.10.3
Android studio:1.2.11
grandle:2.2.1
the log:
Information:Gradle tasks [:generateDebugSources, :generateDebugTestSources]
:preBuild
:preDebugBuild
:checkDebugManifest
:prepareDebugDependencies
:compileDebugAidl FAILED
Error:Execution failed for task ':compileDebugAidl'.
> aidl is missing
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import org.gradle.internal.os.OperatingSystem
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
String SDK_DIR = System.getenv("ANDROID_HOME")
if(SDK_DIR == null) {
Properties props = new Properties()
props.load(new FileInputStream(project.rootProject.file("local.properties")))
SDK_DIR = props.get('sdk.dir');
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
proguardFiles 'proguard.cfg'
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
provided files("${SDK_DIR}/platforms/android-17/data/layoutlib.jar")
//compile files('libs/pass-v1.1.3.jar')
// compile files('libs/sdk-v1.0.0.jar')
}
before this, I had compile the android resource 4.4 on my Mac, and modified some files in OS system, I think it is the reason is that, but I've forget which file, Someone encountered this problem yet

In my case I downloaded version 22 of Android M and Android 5.1.1 using Android Studio 1.2.1.1 but when I try to do a Hello World this same error showed me
So the solution was go to do right click in app like the image below and choose "Open Module Settings".....
then there you have 2 options. I've changed both with the last version I had.
Compile SDK version to API 21 Lollipop
and Build Tools Version to 21.1.2
Finally clean the project and Build
UPDATE
Here is my build.gradle to compare with your build.gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.android.bmi"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
UPDATED
TO Get Android Studio 1.3 follow this steps
Open the Settings window by choosing File > Settings.
Choose the Appearance & Behavior > System Settings > Updates panel.
On the Updates panel, choose the option Automatically check updates for: Canary Chanel.
On the Updates panel, select Check Now to check for the latest canary build. 5. Download and install the build when you are prompted.
Then you'll have something like this to update your Android Studio to 1.3 and with this you can test Android M

I solve my issue, set the build tools version from 21.1.2 to 22.0.1, hope it can help who meet the same.

For those you are still getting the "aidl is missing" error:
To me, setting back the build tools version is not a solution at all.
On your top level build.gradle file, try setting:
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:1.3.1'
and then use buildToolsVersion '23.0.1'.
It worked perfectly for me. I hope it helps others.

Following the screen shots from Jorge's post all you have to do is make sure you do not select Build Tools Version 23.0.0 rc1. I have not fully investigated that version in the IDE or on Google's bug tracker but all I had to do was pick the previous tool version and it worked just fine after doing a clean build. I tried this out with various SDK min versions.
I am running OSX 10.10.3 with Android Studio 1.2.1.1 running on Oracle JDK 1.8.0_45-b14
UPDATED WITH SOLUTION
This issue is identical in nature to Execution failed for task ':app:compileDebugAidl': aidl is missing. Please read my post for the proper solution and references to the genesis of the solution.

people who are building apps with android studio 1.3 preview might get Debug AIDL missing error
Solution:(Follow in sequence)
1) Download all the tools under preview channel (i.e. revision no 23.0.0 rc1)
2) Download play servies and android support repo support under extras
3)Restart Android Studio
4)Press F4 and set compile SDK version to API 22+ and Build tool version 23.0.0 rc1
5)open build.gradle(Project:******) and change classpath line with classpath 'com.android.tools.build:gradle:1.3.+'

I followed screenshots from Jorge's post. But did not have API 21 as an option. So I kept Compiled SDK Version 'API 22: Android 5.1 (Lollipop)' as it is and changed Build Tool Version from 23.0.0 rc1 to 22.0.1
I also had to install JDK 7 since 22.0.1 did not support JDK 6. After that gradle build succeded.

In my experience, there is not about Compile Sdk Version or Build Tool Version, is about the New Project Structure. According to this issue, Aidl files are supposed to be in src/main/aidl, once you put *.aidl at the supposed directory, Android Studio would serve it as expect.
And If you want to have them in src/main/java, then you need the remapping instruction as you've specified, like below :
sourceSets {
main {
aidl.srcDirs = ['src/main/java']
}
}
btw, in my situation, the remapping approach work only by Gradle 2.4(also probably above version).

Related

Error:The SDK Build Tools revision (24.0.3) is too low for project ':app'. Minimum required is 25.0.0

I'm getting this error when I build the android app:
Error:The SDK Build Tools revision (24.0.3) is too low for project ':app'. Minimum required is 25.0.0
I've looked at other posts, and their solutions didn't work for me. I tried editing build.gradle and changed buildToolsVersion.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '24.0.3'
defaultConfig {
applicationId "com.appsofdave.karen"
minSdkVersion 15
targetSdkVersion 23
versionCode 10
versionName "1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
res.srcDirs = ['src/main/res', 'src/main/res/values-v21']
java.srcDirs = ['src/main/java', 'src/main/aidl/com/android/vending/billing']
}
}
repositories {
mavenCentral() // jcenter() works as well because it pulls from Maven Central
}
}
How do I tell gradle to use the Build Tools 23 if it's already installed?
I was successful. First, you have to download the latest version of SDK (25.0.0), save it to a folder. In android studio, select Tools -> android -> SDK manager -> Edit. Select the path to the latest downloaded SDK file. Then run Gradle again!
If it still does not work then you have to download a new Android studio. During the installation process, save the SDK in another folder. In android studio, select Tools -> android -> SDK manager -> Edit. Select the path to the latest downloaded SDK file. Then run Gradle again!

The project is using an unsupported version of Gradle

I am following this tutorial in Android Studio.
When trying to Import the project, I get a dialog saying:
"The project is using an unsupported version of Gradle."
Please point to a supported Gradle version in the project's Gradle settings or in the project's Gradle wrapper (if applicable.)"
It also fails if I select the wrapper method by stating:
"Plugin with id 'com.android.application' not found.
Here is what Parse's gradle looks like:
apply plugin: 'com.android.application'
repositories {
mavenCentral() }
dependencies {
compile 'com.parse.bolts:bolts-android:1.1.3'
compile fileTree(dir: 'libs', include: 'Parse-*.jar') }
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
My project's Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "id.goes.here"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
} }
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
You generally have two build.gradles in your project:
A top level build.gradle in your project's root that contains buildscript {} and allprojects {} sections. This contains the project-wide configuration.
An app module build.gradle (located in your app's module folder) that contains the configuration for your android application. This one contains the android {} section.
Open up your top level build.gradle, and look at the Android Gradle plugin version (it will look something like classpath 'com.android.tools.build:gradle:1.0.0-rc3').
If the plugin is at version 0.13.0 or higher, you need to make sure you are using Gradle 2.1 or newer.
If the plugin is below version 0.14.4, you cannot use Gradle 2.2+.
Before going further, you need to find out whether you are using a local gradle distribution or the wrapper. To do so, go to File > Settings, then search for "Gradle." If "Use local Gradle distribution" is selected, either update your local Gradle to a supported version or switch to using the wrapper.
If you are using the wrapper, the configuration for the Gradle version is located under <your-project>/gradle/wrapper/gradle-wrapper.properties. This file contains a line that will look something like this: distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
. Simply change the version at the end to a supported version.
Studio typically will offer to update the wrapper for you if you click on the error telling you that it is not a supported version.
I resolve this issue by syncing project with gradle files.
In android studio from menu open File option and click option sync project with gradle files.
In the project build,gradle file
Replace
runProguard false
With
minifyEnabled true

Upgraded Android Studio - Project no longer builds gradle build tools version

I have just upgraded my Android Studio but when I try to build/compile the project, I get the following error:
`Error:Execution failed for task ':libraries:facebook:preBuild'.
Build Tools Revision 19.0.0+ is required.`
My gradle looks like this:
Dependencies
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
Android
compileSdkVersion 19
buildToolsVersion "19.0.3"
SDK Manager:
As you can see, I have installed pretty much every Android SDK Build-tools version. yet still, the error persists.
Any ideas?
Update
Dependies - which is at the bottom of the gradle file:
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile 'com.google.maps.android:android-maps-utils:+'
compile project(':libraries:facebook')
compile 'com.google.android.gms:play-services:3.2.25'
compile files('libs/TestFlightLib.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/svg-android.jar')
}
I tried changing the support version to 19.0.+ but it still didn't work.
I was looking in the wrong Gradle. The error specified that the error is coming from the "Facebook" gradle and not the gradle which belongs to the app. Each library has it's own gradle. So, the facebook's gradle's builTolsVersion was 18.0.0 instead of 19.0.0.
Duh!
Have you tried right-clicking your project-> Android Tools->Add Support Library-> select Android Support Library, revision 19, click on Accept Licence and Install.
Try to invalidate caches / restart , it fixed this like this after updated AS.
File-> Invalidate caches/restart -> Invalidate And restart.
The file <YourProject>/app/build.graddle should be changed to match version of the files you have in the SDK Manager (green icon of the robot with arrow pointing down - just under Help menu). You have two options:
1) download the version you need (in SDK Manager) for which Android Studio shows links to click on them to download proper version)
2) modify the file above to match version(s) of the files you have in your SDK Manager (ie probably version numbers matching your updated-to-latest-greatest-version)
Then rebuild your project.
The way I fix this problem was by pasting the code, into the android of your graddle file
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

How to set up gradle and android studio to do release build?

I want to build android app and start signing it.
For that I need to have Release version of apk. Google documentation suggests only Eclipse and ant ways to have release builds: http://developer.android.com/tools/publishing/app-signing.html#releasecompile
However I cannot find how to force gradle build release version of apk. build.gradle does not give any hints either. gradlew tasks suggests, that there is no install Release configuration, but uninstall release exists:
Install tasks
-------------
installDebug - Installs the Debug build
installTest - Installs the Test build for the Debug build
uninstallAll - Uninstall all applications.
uninstallDebug - Uninstalls the Debug build
uninstallRelease - Uninstalls the Release build
uninstallTest - Uninstalls the Test build for the Debug build
My build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile files('libs/android-support-v4.jar')
compile project(":libraries:ActionBarSherlock")
compile project(":libraries:CollabsibleSearchMenu")
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
}
What I am missing?
open the Build Variants pane, typically found along the lower left side of the window:
set debug to release
shift+f10 run!!
then, Android Studio will execute assembleRelease task and install xx-release.apk to your device.
in the latest version of android studio, you can just do:
./gradlew assembleRelease
or aR for short. This will produce an unsigned release apk. Building a signed apk can be done similarly or you can use Build -> Generate Signed Apk in Android Studio.
See the docs here
Here is my build.gradle for reference:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
release {
}
}
No need to update gradle for making release application in Android studio.If you were eclipse user then it will be so easy for you. If you are new then follow the steps
1: Go to the "Build" at the toolbar section.
2: Choose "Generate Signed APK..." option.
3:fill opened form and go next
4 :if you already have .keystore or .jks then choose that file enter your password and alias name and respective password.
5: Or don't have .keystore or .jks file then click on Create new... button as shown on pic 1 then fill the form.
Above process was to make build manually. If You want android studio to automatically Signing Your App
In Android Studio, you can configure your project to sign your release APK automatically during the build process:
On the project browser, right click on your app and select Open Module Settings.
On the Project Structure window, select your app's module under Modules.
Click on the Signing tab.
Select your keystore file, enter a name for this signing configuration (as you may create more than one), and enter the required information.
Figure 4. Create a signing configuration in Android Studio.
Click on the Build Types tab.
Select the release build.
Under Signing Config, select the signing configuration you just created.
Figure 5. Select a signing configuration in Android Studio.
4:Most Important thing that make debuggable=false at gradle.
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.txt'
debuggable false
jniDebuggable false
renderscriptDebuggable false
zipAlignEnabled true
}
}
visit for more in info developer.android.com
To activate the installRelease task, you simply need a signingConfig. That is all.
From http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Android-tasks:
Finally, the plugin creates install/uninstall tasks for all build
types (debug, release, test), as long as they can be installed (which
requires signing).
Here is what you want:
Install tasks
-------------
installDebug - Installs the Debug build
installDebugTest - Installs the Test build for the Debug build
installRelease - Installs the Release build
uninstallAll - Uninstall all applications.
uninstallDebug - Uninstalls the Debug build
uninstallDebugTest - Uninstalls the Test build for the Debug build
uninstallRelease - Uninstalls the Release build <--- release
Here is how to obtain the installRelease task:
Example build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId 'demo'
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName '1.0'
}
signingConfigs {
release {
storeFile <file>
storePassword <password>
keyAlias <alias>
keyPassword <password>
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
This is a procedure to configure run release version
1- Change build variants to release version.
2- Open project structure.
3- Change default config to $signingConfigs.release
To compile with release build as shown below:

How to use opencv in using Gradle?

I want to use Android Studio to develop an app using Gradle build tool. I can not insert the OpenCV repo and library on build.gradle. My .gradle file is like below:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
How can I add OpenCV in my project?
You can do this very easily in Android Studio.
Follow the below steps to add Open CV in your project as library.
Create a libraries folder underneath your project main directory. For example, if your project is OpenCVExamples, you would create a OpenCVExamples/libraries folder.
Go to the location where you have SDK "\OpenCV-2.4.8-android-sdk\sdk" here you will find the java folder, rename it to opencv.
Now copy the complete opencv directory from the SDK into the libraries folder you just created.
Now create a build.gradle file in the opencv directory with the following contents
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 2480
versionName "2.4.8"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['src']
}
}
}
Edit your settings.gradle file in your application’s main directory and add this line:
include ':libraries:opencv'
Sync your project with Gradle and it should looks like this
Right click on your project then click on the Open Module Settings then Choose Modules from the left-hand list, click on your application’s module, click on the Dependencies tab, and click on the + button to add a new module dependency.
Choose Module dependency. It will open a dialog with a list of modules to choose from; select “:libraries:opencv”.
Create a jniLibs folder in the /app/src/main/ location and copy the all the folder with *.so files (armeabi, armeabi-v7a, mips, x86) in the jniLibs from the OpenCV SDK.
Click OK. Now everything done, go and enjoy with OpenCV.
Since the integration of OpenCV is such an effort, we pre-packaged it and published it via JCenter here: https://github.com/quickbirdstudios/opencv-android
Just include this in your module's build.gradle dependencies section
dependencies {
implementation 'com.quickbirdstudios:opencv:3.4.1'
}
and this in your project's build.gradle repositories section
repositories {
jcenter()
}
You won't get lint error after gradle import but don't forget to initialize the OpenCV library like this in MainActivity
public class MainActivity extends Activity {
static {
if (!OpenCVLoader.initDebug())
Log.d("ERROR", "Unable to load OpenCV");
else
Log.d("SUCCESS", "OpenCV loaded");
}
...
...
...
...
As per OpenCV docs(1), below steps using OpenCV manager is the recommended way to use OpenCV for production runs. But, OpenCV manager(2) is an additional install from Google play store. So, if you prefer a self contained apk(not using OpenCV manager) or is currently in development/testing phase, I suggest answer at https://stackoverflow.com/a/27421494/1180117.
Recommended steps for using OpenCV in Android Studio with OpenCV manager.
Unzip OpenCV Android sdk downloaded from OpenCV.org(3)
From File -> Import Module, choose sdk/java folder in the unzipped opencv archive.
Update build.gradle under imported OpenCV module to update 4 fields to match your project's build.gradle a) compileSdkVersion b) buildToolsVersion c) minSdkVersion and 4) targetSdkVersion.
Add module dependency by Application -> Module Settings, and select the Dependencies tab. Click + icon at bottom(or right), choose Module Dependency and select the imported OpenCV module.
As the final step, in your Activity class, add snippet below.
public class SampleJava extends Activity {
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
#Override
public void onManagerConnected(int status) {
switch(status) {
case LoaderCallbackInterface.SUCCESS:
Log.i(TAG,"OpenCV Manager Connected");
//from now onwards, you can use OpenCV API
Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0));
break;
case LoaderCallbackInterface.INIT_FAILED:
Log.i(TAG,"Init Failed");
break;
case LoaderCallbackInterface.INSTALL_CANCELED:
Log.i(TAG,"Install Cancelled");
break;
case LoaderCallbackInterface.INCOMPATIBLE_MANAGER_VERSION:
Log.i(TAG,"Incompatible Version");
break;
case LoaderCallbackInterface.MARKET_ERROR:
Log.i(TAG,"Market Error");
break;
default:
Log.i(TAG,"OpenCV Manager Install");
super.onManagerConnected(status);
break;
}
}
};
#Override
protected void onResume() {
super.onResume();
//initialize OpenCV manager
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
}
}
Note: You could only make OpenCV calls after you receive success callback on onManagerConnected method. During run, you will be prompted for installation of OpenCV manager from play store, if it is not already installed. During development, if you don't have access to play store or is on emualtor, use appropriate OpenCV manager apk present in apk folder under downloaded OpenCV sdk archive .
Pros
Apk size reduction by around 40 MB ( consider upgrades too ).
OpenCV manager installs optimized binaries for your hardware which could help speed.
Upgrades to OpenCV manager might save your app from bugs in OpenCV.
Different apps could share same OpenCV library.
Cons
End user experience - might not like a install prompt from with your
application.
If you don't want to use JavaCV this works for me...
Step 1- Download the Resources
Download OpenCV Android SDK from http://opencv.org/downloads.html
Step 2 - Copying the OpenCV binaries into your APK
Copy libopencv_info.so & libopencv_java.so from
OpenCV-2.?.?-android-sdk -> sdk -> native -> libs -> armeabi-v7a
to
Project Root -> Your Project -> lib - > armeabi-v7a
Zip the lib folder up and rename that zip to whatever-v7a.jar.
Copy this .jar file and place it in here in your project
Project Root -> Your Project -> libs
Add this line to your projects build.gradle in the dependencies section
compile files('libs/whatever-v7a.jar')
When you compile now you will probably see your .apk is about 4mb bigger.
(Repeat for "armeabi" if you want to support ARMv6 too, likely not needed anymore.)
Step 3 - Adding the java sdk to your project
Copy the java folder from here
OpenCV-2.?.?-android-sdk -> sdk
to
Project Root -> Your Project -> libs (Same place as your .jar file);
(You can rename the 'java' folder name to 'OpenCV')
In this freshly copied folder add a typical build.gradle file; I used this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral();
}
android {
compileSdkVersion 19
buildToolsVersion "19"
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
In your Project Root settings.gradle file change it too look something like this:
include ':Project Name:libs:OpenCV', ':Project Name'
In your Project Root -> Project Name -> build.gradle file in the dependencies section add this line:
compile project(':Project Name:libs:OpenCV')
Step 4 - Using OpenCV in your project
Rebuild and you should be able to import and start using OpenCV in your project.
import org.opencv.android.OpenCVLoader;
...
if (!OpenCVLoader.initDebug()) {}
I know this if a bit of hack but I figured I would post it anyway.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
maven {
url 'http://maven2.javacv.googlecode.com/git/'
}
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile 'com.googlecode.javacv:javacv:0.5'
instrumentTestCompile 'junit:junit:4.4'
}
android {
compileSdkVersion 14
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 14
}
}
This is worked for me :)
I have posted a new post about how to build an Android NDK application with OpenCV included
using Android Studio and Gradle. More information can be seen here, I have summarized two methods:
(1) run ndk-build within Gradle task
sourceSets.main.jni.srcDirs = []
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
ndkDir = project.plugins.findPlugin('com.android.application').getNdkFolder()
commandLine "$ndkDir/ndk-build",
'NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=src/main/jniLibs',
'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
'NDK_APPLICATION_MK=src/main/jni/Application.mk'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
(2) run ndk-build with an external tool
Parameters: NDK_PROJECT_PATH=$ModuleFileDir$/build/intermediates/ndk NDK_LIBS_OUT=$ModuleFileDir$/src/main/jniLibs NDK_APPLICATION_MK=$ModuleFileDir$/src/main/jni/Application.mk APP_BUILD_SCRIPT=$ModuleFileDir$/src/main/jni/Android.mk V=1
More information can be seen here
It works with Android Studio 1.2 + OpenCV-2.4.11-android-sdk (.zip), too.
Just do the following:
1) Follow the answer that starts with "You can do this very easily in Android Studio. Follow the steps below to add OpenCV in your project as library." by TGMCians.
2) Modify in the <yourAppDir>\libraries\opencv folder your newly created build.gradle to (step 4 in TGMCians' answer, adapted to OpenCV2.4.11-android-sdk and using gradle 1.1.0):
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
versionCode 2411
versionName "2.4.11"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['src']
}
}
}
3) *.so files that are located in the directories "armeabi", "armeabi-v7a", "mips", "x86" can be found under (default OpenCV-location): ..\OpenCV-2.4.11-android-sdk\OpenCV-android-sdk\sdk\native\libs (step 9 in TGMCians' answer).
Enjoy and if this helped, please give a positive reputation. I need 50 to answer directly to answers (19 left) :)
The OpenCV Android SDK has an example gradle.build file with helpful comments: https://github.com/opencv/opencv/blob/master/modules/java/android_sdk/build.gradle.in
//
// Notes about integration OpenCV into existed Android Studio application project are below (application 'app' module should exist).
//
// This file is located in <OpenCV-android-sdk>/sdk directory (near 'etc', 'java', 'native' subdirectories)
//
// Add module into Android Studio application project:
//
// - Android Studio way:
// (will copy almost all OpenCV Android SDK into your project, ~200Mb)
//
// Import module: Menu -> "File" -> "New" -> "Module" -> "Import Gradle project":
// Source directory: select this "sdk" directory
// Module name: ":opencv"
//
// - or attach library module from OpenCV Android SDK
// (without copying into application project directory, allow to share the same module between projects)
//
// Edit "settings.gradle" and add these lines:
//
// def opencvsdk='<path_to_opencv_android_sdk_rootdir>'
// // You can put declaration above into gradle.properties file instead (including file in HOME directory),
// // but without 'def' and apostrophe symbols ('): opencvsdk=<path_to_opencv_android_sdk_rootdir>
// include ':opencv'
// project(':opencv').projectDir = new File(opencvsdk + '/sdk')
//
//
//
// Add dependency into application module:
//
// - Android Studio way:
// "Open Module Settings" (F4) -> "Dependencies" tab
//
// - or add "project(':opencv')" dependency into app/build.gradle:
//
// dependencies {
// implementation fileTree(dir: 'libs', include: ['*.jar'])
// ...
// implementation project(':opencv')
// }
//
//
//
// Load OpenCV native library before using:
//
// - avoid using of "OpenCVLoader.initAsync()" approach - it is deprecated
// It may load library with different version (from OpenCV Android Manager, which is installed separatelly on device)
//
// - use "System.loadLibrary("opencv_java3")" or "OpenCVLoader.initDebug()"
// TODO: Add accurate API to load OpenCV native library
//
//
//
// Native C++ support (necessary to use OpenCV in native code of application only):
//
// - Use find_package() in app/CMakeLists.txt:
//
// find_package(OpenCV 3.4 REQUIRED java)
// ...
// target_link_libraries(native-lib ${OpenCV_LIBRARIES})
//
// - Add "OpenCV_DIR" and enable C++ exceptions/RTTI support via app/build.gradle
// Documentation about CMake options: https://developer.android.com/ndk/guides/cmake.html
//
// defaultConfig {
// ...
// externalNativeBuild {
// cmake {
// cppFlags "-std=c++11 -frtti -fexceptions"
// arguments "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni" // , "-DANDROID_ARM_NEON=TRUE"
// }
// }
// }
//
// - (optional) Limit/filter ABIs to build ('android' scope of 'app/build.gradle'):
// Useful information: https://developer.android.com/studio/build/gradle-tips.html (Configure separate APKs per ABI)
//
// splits {
// abi {
// enable true
// reset()
// include 'armeabi-v7a' // , 'x86', 'x86_64', 'arm64-v8a'
// universalApk false
// }
// }
//
apply plugin: 'com.android.library'
println "OpenCV: " + project.buildscript.sourceFile
android {
compileSdkVersion 27
//buildToolsVersion "27.0.3" // not needed since com.android.tools.build:gradle:3.0.0
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
sourceSets {
main {
jniLibs.srcDirs = ['native/libs']
java.srcDirs = ['java/src']
aidl.srcDirs = ['java/src']
res.srcDirs = ['java/res']
manifest.srcFile 'java/AndroidManifest.xml'
}
}
}
dependencies {
}
These are the steps necessary to use OpenCV with Android Studio 1.2:
Download OpenCV and extract the archive
Open your app project in Android Studio
Go to File -> New -> Import Module...
Select sdk/java in the directory you extracted before
Set Module name to opencv
Press Next then Finish
Open build.gradle under imported OpenCV module and update compileSdkVersion and buildToolsVersion to versions you have on your machine
Add compile project(':opencv') to your app build.gradle
dependencies {
...
compile project(':opencv')
}
Press Sync Project with Gradle Files
I've imported the Java project from OpenCV SDK into an Android Studio gradle project and made it available at https://github.com/ctodobom/OpenCV-3.1.0-Android
You can include it on your project only adding two lines into build.gradle file thanks to jitpack.io service.
The following permissions and features are necessary in the AndroidManifest.xml file without which you will get the following dialog box
"It seems that your device does not support camera (or it is locked). Application will be closed"
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>
OpenCV, Android Studio 1.4.1, gradle-experimental plugin 0.2.1
None of the other answers helped me. Here's what worked for me. I'm using the tutorial-1 sample from opencv but I will be doing using the NDK in my project so I'm using the gradle-experimental plugin which has a different structure than the gradle plugin.
Android studio should be installed, the Android NDK should be installed via the Android SDK Manager, and the OpenCV Android SDK should be downloaded and unzipped.
This is in chunks of bash script to keep it compact but complete. It's also all on the command line because on of the big problems I had was that in-IDE instructions were obsolete as the IDE evolved.
First set the location of the root directory of the OpenCV SDK.
export OPENCV_SDK=/home/user/wip/OpenCV-2.4.11-android-sdk
cd $OPENCV_SDK
Create your gradle build files...
First the OpenCV library
cat > $OPENCV_SDK/sdk/java/build.gradle <<'==='
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
minSdkVersion.apiLevel = 8
targetSdkVersion.apiLevel = 23
}
}
android.buildTypes {
release {
minifyEnabled = false
}
debug{
minifyEnabled = false
}
}
android.sources {
main.manifest.source.srcDirs += "."
main.res.source.srcDirs += "res"
main.aidl.source.srcDirs += "src"
main.java.source.srcDirs += "src"
}
}
===
Then tell the tutorial sample what to label the library as and where to find it.
cat > $OPENCV_SDK/samples/tutorial-1-camerapreview/settings.gradle <<'==='
include ':openCVLibrary2411'
project(':openCVLibrary2411').projectDir = new File('../../sdk/java')
===
Create the build file for the tutorial.
cat > $OPENCV_SDK/samples/tutorial-1-camerapreview/build.gradle <<'==='
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "org.opencv.samples.tutorial1"
minSdkVersion.apiLevel = 8
targetSdkVersion.apiLevel = 23
}
}
android.sources {
main.manifest.source.srcDirs += "."
main.res.source.srcDirs += "res"
main.aidl.source.srcDirs += "src"
main.java.source.srcDirs += "src"
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
debug {
minifyEnabled = false
}
}
}
dependencies {
compile project(':openCVLibrary2411')
}
===
Your build tools version needs to be set correctly. Here's an easy way
to see what you have installed. (You can install other versions via the
Android SDK Manager). Change buildToolsVersion if you don't have 23.0.2.
echo "Your buildToolsVersion is one of: "
ls $ANDROID_HOME/build-tools
Change the environment variable on the first line to your version number
REP=23.0.2 #CHANGE ME
sed -i.bak s/23\.0\.2/${REP}/g $OPENCV_SDK/sdk/java/build.gradle
sed -i.bak s/23\.0\.2/${REP}/g $OPENCV_SDK/samples/tutorial-1-camerapreview/build.gradle
Finally, set up the correct gradle wrapper. Gradle needs a clean directory
to do this.
pushd $(mktemp -d)
gradle wrapper --gradle-version 2.5
mv -f gradle* $OPENCV_SDK/samples/tutorial-1-camerapreview
popd
You should now be all set. You can now browse to this directory with Android Studio and open up the project.
Build the tutoral on the command line with the following command:
./gradlew assembleDebug
It should build your apk, putting it in ./build/outputs/apk

Categories

Resources