Unable to integrate OpenCV in android studio - java

I am trying to integrate openCV in Android studio for my latest project. I followed the following steps:
Imported new module ..\OpenCV-android-sdk\java\
Added dependancy OpenCVLibrary320
Changed compilesdk and targetsdk versions to 23 and buildToolsVersion to 25.0.0 in the build.gradle of OpenCVLibrary320
Copied the contents of ..\OpenCV-android-sdk\sdk\native to app\main\src\jniLibs (After creating a jni folder)
Wrote a snippet of code to test if it was working
But I got the error:
Error:Execution failed for task ':app:compileDebugNdk'.
Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
https://developer.android.com/studio/build/experimental-plugin.html.
How can I fix this problem?
Note: In step 4, I created the jniLibs folder but it did not show up in the 'Android' view so I had to copy the contents to the jniLibs folder in the 'Project' view.

In gradle add module dependency:
include ':libraries:opencv'
add in build.gradle with this content
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0.0"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['src']
}
}
}

Manualy add the jar file in the lib folder,
app -> libs -> xyz.jar
This will also create duplicate jar issue, remove from the previous folder, because it gets compiled twice if you do not remove

Related

How can I use MultiDexApplication in libGDX for Android

I read many discussions about this topic but no any an exact answer I found. One says you should use Android Studio instead of Eclipse because it supports Gradle and uses Maven building. But I develop games in Eclipse using libGDX and it supports Gradle and Maven building too. Another says you should add multidex.jar from your path SDK tools or from Gradle then enable it inside gradle then extends MultiDexApplication instead of Application then install it inside attachBaseContext method. Nice, but it doesn't work.
And how can I extend MultiDexApplication instead of AndroidApplication?.
Does libGDX has modification class on Application like AndroidApplication but in MultiDexAndroidApplication case?
Another says you shoud convert your project into Maven project or add some lines in pom.xml file to build many dex files!!.
I read more about this topic, but no any answer of their answers solve this problem (In libGDX using Eclipse case).
Any help!!
You can set multi dex enabled in Gradle (android/build.gradle) like so:
android {
buildToolsVersion "23.0.2"
compileSdkVersion 23
defaultConfig {
multiDexEnabled = true
applicationId = package_name
}
dexOptions {
javaMaxHeapSize "4g"
}
lintOptions {
disable 'ExportedContentProvider', 'IconColors'
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
instrumentTest.setRoot('tests')
}
}
I believe the only lines you need to add are:
defaultConfig {
multiDexEnabled = true
applicationId = <your_package_name>
}

How import eclipse project to android studio 0.4.6 ?

I have project in eclipse and use android 2.3.3(API 10), but when I need import this project to android studio 0.4.6 thin android show me massage to fixed my project after I click fixed show me error `"Execution failed for task ':preBuild'.> Build Tools Revision 19.0.0+ is required."
please how I can fixed this error.
That my gredle-wrapper .properties:
#Thu Apr 17 01:07:57 PDT 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
That my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 8
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['use','src']
resources.srcDirs = ['use','src']
aidl.srcDirs = ['use','src']
renderscript.srcDirs = ['use','src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
Please till me, any version eclipse I can export project to import in android studio.
All version eclipse is true to export.
You need to update the Build Tools Revision to version 19.0.0
open your sdk manager and update ( use the sdk directory associated with android studio not eclipse)
You might as well try to migrate your project from eclipse to make it easier when importing it in eclipse.
Let me know if this is not working

Importing Facebook library in Android Studio: Could not find property 'ANDROID_BUILD_SDK_VERSION'

I want to import a library project into my app but whenever I try to do so , Android Studio doesn't recognise it
It also gives me errors in build.gradle ..
The Library is : PagerSlidingTabStrip ....
Here are some pictures :
I have been trying to make it work for 3 days so far !!
Please Help Me :)
EDIT:
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:19.0.0'
}
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion 8
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
EDIT2 :
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':Sahertoday'.
> Could not resolve all dependencies for configuration ':Sahertoday:_debugCompile'.
> Could not find com.astuetz:pagerslidingtabstrip:1.0.1.
Required by:
Saher-3:Sahertoday:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
First of all, you can add this dependency to your project, without compiling the lib locally.
dependencies {
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
}
Otherwise if you would like to compile this lib locally, you have to define these keys in gradle.properties in the root.
ANDROID_BUILD_TARGET_SDK_VERSION=19
ANDROID_BUILD_TOOLS_VERSION=19
ANDROID_BUILD_SDK_VERSION=19
EDIT
There is also a GUI way for doing this. It is accessed by selecting the module facebook in the project tree and pressing f4. Also you can just right-click the facebook and go to Open Module Settings near the bottom. It is shown in the pictures. The numbers in the picture are top sdk version at the time of writing.
There is a simpler solution.
The constants like ANDROID_BUILD_SDK_VERSION can be replaced with normal version "numbers". So instead of
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion 8
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
..file can look like this:
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
}
Go the facebook folder which you have imported in your project. Copy the gradle.properties file and paste in into your facebook module.It will remove the errors.
For those who ran into same problems while adding libraries and still can't get it work. The following local include of the .aar file worked for me:
Just download the .aar file from the maven repo manually.
In Android Studio go to File -> new Module -> import .JAR or
.AAR package and select your downloaded .aar file.
Android Studio does the rest (in the build.gradle) for you. Maybe clean and rebuild your project.
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 4
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:22.2.1'
}

Using Android Studio Facebook SDK

I am following the instructions here, however I am running into problems at step 3 "Import the SDK into an Android Studio Project". I imported the Module and set to compile as specified however, when I try to modify the settings.gradle I am running into problems. It keeps giving me Gradle 'MyApplicationProject' project refresh failed: You are using an old, unsupported version of Gradle please use 1.6 or higher. I am build the app with version 4.3 compiler while supporting all the way to 4.0(Android).
This is my settings.gradle
include ':MyPeeps'
include ':libraries:facebook', ':MyApplicationProject'
after is wasn't auto populating I added
dependencies {
compile files('libs/android-support-v4.jar')
compile project(':libraries:facebook')
}
Also put this into the build.gradle
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
When I go to put in the onCreation command for facebook errors with all the commands that use the facebook api. Does anyone know how I can fix my gradle issues?
Change 'com.android.tools.build:gradle:0.4' to 'com.android.tools.build:gradle:0.5.+'
I decided to drop android studio and just go back to adt plugin got it work quickly at that point. Thanks for the help.

transferred computers with Android Studio and now have Gradle error

I had a gradle error at first where I needed to change the version. I read about this problem on the android studio website, and I followed there directions and changed this line in the gradle file:
classpath 'com.android.tools.build:gradle:0.5.0'
My error didnt go away and my main was full of red underlines. I then restarted Android Studio and everything seemed fixed.
But when I tried to compile and run on my phone from my mac book air I got this error:
Gradle: A problem occurred evaluating root project 'BeerPortfolioPro'.
> The SDK directory '/Users/Mike/Library/Caches/AndroidStudioPreview/compile-server/"/Applications/Android Studio.app/sdk"' does not exist.
my gradle build file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.0'
}
}
apply plugin: 'android'
dependencies {
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 11
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
You can change the dependency to 'com.android.tools.build:gradle:0.5.4'.
Also, add a local.properties file in the project root folder with a line pointing to the Android Studio sdk directory. I had to put this line:
sdk.dir=/Applications/Android Studio.app/sdk

Categories

Resources