i'm using imageComparator to compare two images with OpenCV library but i can't import DMatch class in my app org.opencv.features2d.DMatch any one knows how should i fix this problem ?
I got the imageComparator project working in Android Studio with openCV 3.1 by following this SO answer
and to fix the failed to import error replace:
import org.opencv.features2d.DMatch;
with
import org.opencv.core.DMatch;
well finally I've found my answer by my self :D
if you guys have this problem too u should download OpenCV library version 2.4.9
EDIT
if you are using newer versions the package name is changed to core
so after a quick research you are right implementing OpenCV with Android Studio requires a few steps to actually get it working properly.
Adding OpenCV to your new project
Create a folder called “libraries” inside your Android Studio
project, and copy there entire content of sdk/java out of your OpenCV
Android folder.
Rename that folder to “opencv”, so that you will end up having your Android Studio project with subfolder “libraries/opencv”.
Now, inside this “opencv” folder, create a build.gradle file, with the following content:
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
versionCode 3000
versionName "3.0.0"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['src']
}
}
}
** Weird bug Code tag change indentation on the code.
Edit your settings.gradle file in your application’s main directory and add this line:
include ':libraries:opencv'
Open Android Studio
Do this in Android Studio: Tools/Android/Sync Project with Grade files
Go to File/Project Structure, inside Modules pick your ‘app’, then from the Tab pick: Dependencies, click + to add new dependency, pick Module Dependency, and add :library:opencv dependency to your project. Click OK.
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 Android SDK/native/libs folder.
Make sure that you do have Android SDK 19 installed (as per above gradle files), or use a version that you have installed.
Try to sync Gradle again, after adding the dependency. You may need to delete section “android” from your top-level build.gradle if the sync complains.
Build the project.
Source :: https://blog.hig.no/gtl/2015/10/01/android-studio-opencv/
EDIT 1:
https://www.youtube.com/watch?v=OTw_GIQNbD8 - Youtube video with all the steps required to do from scratch by Md. Zakir Hossen.
I have a project that I already run in Android Studio.
After I've opened the project in Android Studio I got the message:
Migrate Project to Gradle?
This project does not use the Gradle build system. We recommend that you migrate to using the Gradle build system.
More Information about migrating to Gradle
Don't show this message again.
Following the link of More Information about migrating to Gradle although I'm already on Android Studio I've followed the option Migrating from IntelliJ Projects .
Since I've already have a build.gradle file at the root of my project I've modified to include some dependencies.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile "com.android.support:support-v4:18.0.+"
compile "com.android.support:appcompat-v7:18.0.+"
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.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']
}
// 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')
}
}
As instructed, i've ran gradle assembleDebug on the Android Studio terminal windows but was getting some errors. To solve this errors I had to create a local.properties with sdk.dir=C:\\Program Files (x86)\\Android\\android-sdk and remove the android-support-v4.jar file from the /libs folder and from the Libraries->libs from the Project Structure.
I now ran again gradle assembleDebug and this time it finishes without any errors.
I've restarted Android Studio but after restarting I've saw that on the External Libraries of the project there were no support-v4 and appcompat-v7 and in one of my classes I have the import android.support.v4.widget.CursorAdapter; marked as error since Cannot resolve symbol Cursor Adapter.
If I press the button Sync project with gradle filesi got the message: The project MyProject is not a Gradle-based project
Can someone help me figuring out how to solve this?
Here is my project Structure
The project thinks it's still a non-Gradle based project; it's not the presence of the build.gradle file that makes it Gradle-based, but it's how the project was set up in the first place. You'll need to re-import your project to finish the conversion to Gradle.
First, though, it looks like you don't have a settings.gradle file; it looks like you need one. Since you've set up your project as a single-module project, then you can put the file in your project's root directory, next to build.gradle. It should contain this:
import ':'
In the future if you add more modules to your project you may want to convert it to a multi-module directory structure, but you don't need to worry about that now. In any event, now you need to do the re-import in Android Studio:
Close your project
Back up your project
Delete the .idea folder in the root directory of the project
Delete all the .iml files in your project
Import your project in Android Studio, and in the dialog that prompts you for a file, choose the build.gradle file.
After this you should be good to go.
In my case, when I tried to open an existing gradle project and AS didn't recognize it like a gradle project, the problem was inside settings.gradle file. settings.gradle was corrupt because, for some reason, the semicolon was missing. The right structure is include ':app'; where app is the name of the project's module.
Also, if you need, you can put more than one module, like this: include ':module1', ':module2', ':module3';
I hope it could help someone.
In my case: Step 1: Project Structure > Settings.gradle (Open it and add-- include ':app'; .
Step 2: Goto Gradle Tab (It normally present in Left or Right of Android Studio) > Then click to Refresh All Gradle Project
Step 3: Bang....... I hope its work.(Its works for me)
All I did was to try importing the project with the "import Gradle, Eclipse ETC" option at the start window of Android Studio, selected my gradle-incompatible project to import, and then it did import by asking me automatically if I wanted to make a gradle build project and voila it did import correctly this time with no errors.
The process is pretty straightforward, nothing to fiddle around with nasty settings, just follow the IDE auto-fixes and it will work.
At last that worked for me!
Just check if you are importing the right folder which contains .gradle and .idea folder
click on File
Click on Import Projects
Click on Users then AndroidStudioProjects
Choose your Project then Click OK
NOTE: If you are moving from eclipse to Android Studio then you have do exactly same thing but choose the eclipse projects.
The android tools team made a huge step when introducing android studio 0.3.0 with the new user interface for modifying the build.grade file using the project structure.
But how can I import an android library project into my general project? When I press the '+' button in the Project structore -> Modules section I can only create NEW module.
The way I just did it was by copy pasting the library project in the root of your project (not using android studio, this gives a 'cannot create class-file error', but just using the file manager of your operating system. When using android studio for this it didn't copy some of the files).
Then mark the java folder of the library project as 'source root' (right mouse on the folder).
Then to settings.gradle add your lib project like this:
include ':youApp', ':yourLibrary'
then to build.gradle of yourApp add dependancy:
dependencies {
compile project(':yourLibrary')
}
Now rebuild your project.
Now add a function of the library project (showing red) when you click on it and press Alt-Enter it should say "add dependancy on module yourAppProject"
In android studio 0.3.1 they fixed it.
Project structure -> Modules -> "+" -> Import module.
It's still broken 0.3.6...
The manual way can be a good solution. For example, to import a library like Android-Validator (https://github.com/throrin19/Android-Validator) in your project "Test":
The structure will be:
Test
build.gradle
Android-Validator (the library sources)
build.gradle
src
res
settings.gradle
And now, let's gonna edit the files...
In Test/build.gradle add:
dependencies {
compile project(':Android-Validator')
}
Android-Validator/build.gradle (remember to change xx and yy):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion XX
buildToolsVersion "XX.0.0"
defaultConfig {
minSdkVersion YY
targetSdkVersion XX
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
settings.gradle:
include ':Test', ':Android-Validator'
I had a very similar issues with gradle builds / adding .jar library. I got it working by a combination of :
Moving the libs folder up to the root of the project (same directory as 'src'), and adding the library to this folder in finder (using Mac OS X)
In Android Studio, Right-clicking on the folder to add as library
Editing the dependencies in the build.gradle file, adding: compile fileTree(dir: 'libs', include: '*.jar')}
But annoyingly, HOURS after I get it working, Android Studio have just released 0.3.7, which claims to have solved a lot of gradle issues such as adding .jar libraries
http://tools.android.com/recent
Hope this helps!
I am having problems compiling my app with Android Studio (0.1.5).
The app uses 2 libraries which I have included as follows:
settings.gradle
include ':myapp',':library',':android-ColorPickerPreference'
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile project(':library')
compile project(':android-ColorPickerPreference')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
When compiling I get this message:
Gradle: A problem occurred configuring project ':myapp'.
> Failed to notify project evaluation listener.
> Configuration with name 'default' not found.
Could you help me with this message? Thanks!
In my case, after compiling with gradle tasks --info, the log was there :
Evaluating project ':libraries:VolleyLibrary' using empty build
file.
So it failed to find build.gradle file of the library.
Reason is the folder structure.
It was
-libraries
--volley
---VolleyLibrary
It is supposed to be
-libraries
--VolleyLibrary
I forgot to pull all submodules. So my
compile project(':something')
could not be resolved.
Solution
git submodule update --init
compile fileTree(dir: '//you libraries location//', include: ['android-ColorPickerPreference'])
Use above line in your app's gradle file instead of
compile project(':android-ColorPickerPreference')
Hope it helps
The following procedure solved my issue:
Go to your sub-project-module/library-module settings. (press F4 after selecting the module)
Right Click on Add > Android-Gradle.
Add build.gradle to your module.
Add the following script
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
add include ':yourModuleName' in your settings.gradle
I've also faced with this error - I forgot to create build.gradle script for library project.
Yet another cause - I was trying to include a module in settings.gradle using
include ':MyModule'
project(':MyModule').projectDir = new File(settingsDir, '../../MyModule')
Only problem was, I had just imported the module from Eclipse an forgot to move the directory outside my application project, i.e. the path '../../MyModule' didn't exist.
My solution is to simply remove a line from the settings.gradle file, which represents a module that doesn't exist:
include ':somesdk'
and also remove the corresponding line from the main project's build.gradle:
compile project(':somesdk')
I had a git submodule problem when getting this error. Try running gradle tasks --info for a more detailed problem description. I first used gradle tasks --debug, which was not nearly as helpful as --info.
Suppose you want to add a library (for example MyLib) to your project, You should follow these steps:
Prepare your library as a gradle Android library if your library's type is Eclipse ADT
For this job it's enough to import it in Android Studio
Copy your library folder, in this case MyLib folder, and paste it in your main project folder. It's a good practice to create a new folder in your main project folder and name it Libraries
Go to Android Studio and open Settings.gradle file, there you should include your library in your main project. For example include ':MyPrj', 'Libraries:MyLib'. Note: Current directory for this include statement is your main project folder. If you paste your project into a folder you must mention it's address relative to the main project directory. In my case I paste MyLib into Libraries folder. This Libraries name is not a keyword and you can choose other names for it
Open your Project Structure page(File->Project Structure...) click on modules then click on your main project go to dependencies tab click on + then choose Module dependency and there is your libraries and you can select them as you want
Hope it help
In my case I was using Gradle files that work under Windows but failed on Linux. The include ':SomeProject' and compile project(':SomeProject') were case sensitive and were not found.
For me folder was missing which was declared under settings.gradle.
Everything looks fine at first blush, but some poking around on here found an answer that could be helpful: https://stackoverflow.com/a/16905808/7944
Even the original answer writer doesn't sound super confident, but it's worth following up on. Also, you didn't say anything about your directory structure and so I'm assuming it's boring default stuff, but can't know for sure.
One other potential cause of this precise error: I found this error was resolved by commenting some unused libraries in build.gradle dependencies section. Make sure these paths and such are all correct.
I'd look real close at your compile project(':android-ColorPickerPreference') entry in the build.gradle - try commenting out the related code and this line in build.gradle and see if that compiles - then go from there resolving the path or library issue.
I had similar issue and found very simple way to add a library to the project.
Create folder "libs" in the root of your project.
Copy JAR file into that folder.
Go back to Android Studio, locate your JAR file and right click it, choose "Add As Library...", it will ask you only to which module you want to add it, well choose "app".
Now in your "app" module you can use classes from that JAR, it will be able to locate and add "import" declarations automatically and compile just okay. The only issue might be is that it adds dependency with absolute path like:
compile files('/home/user/proj/theproj/libs/thelib-1.2.3.jar')
in your "app/build.gradle".
Hope that helps!
I solved this issue by fixing some paths in settings.gradle as shown below:
include ':project-external-module'
project(':project-external-module').projectDir = file('/project/wrong/path')
I was including an external module to my project and had the wrong path for it.
I had this issue when I manually pasted google-play-services_lib into my project. Obviously, play-services didn't have a build.gradle file in it. The solution, I learned, is to put this dependency in my project's build.gradle (instead of hard-copying the play-services directory):
compile 'com.google.android.gms:play-services:4.0.+'
When i import my library manually i had same issue. I tried to add my library with file > import module and it solved my issue.
In my case I received this error when I misspelled the module name of the library (dependency) in build.gradle file.
So remember to check if the name of the module is correct.
build.gradle
dependencies {
compile project(':module-name-of-the-library')
}
I recently encountered this error when I refereneced a project that was initiliazed via a git submodule.
I ended up finding out that the root build.gradle file of the submodule (a java project) did not have the java plugin applied at the root level.
It only had
apply plugin: 'idea'
I added the java plugin:
apply plugin: 'idea'
apply plugin: 'java'
Once I applied the java plugin the 'default not found' message disappeared and the build succeeded.
Also... check if you have the module files inside your project.
For example, I have an app which uses the Volley module. During my studies on Android development, I accidentally removed the files which were inside the "volley" directory..
~/git/Sandbox/android/HelloWorld/volley $ ll
total 8
drwxrwxr-x 2 ivanleon ivanleon 4096 Jun 16 22:26 ./
drwxrwxr-x 6 ivanleon ivanleon 4096 Jun 17 01:51 ../
I just cloned the project (see bellow) and then, I made the Sync of the project at Android Studio (Tools > Android > Sync Project with Gradle Files), and Gradle build finished normally (Gradle Console: bottom right corner of Android Studio) ;).
~/git/Sandbox/android/HelloWorld/volley $ git clone https://android.googlesource.com/platform/frameworks/volley
Cloning into 'volley'...
remote: Counting objects: 164, done
remote: Finding sources: 100% (164/164)
remote: Total 3222 (delta 307), reused 3222 (delta 307)
Receiving objects: 100% (3222/3222), 1.22 MiB | 114.00 KiB/s, done.
Resolving deltas: 100% (307/307), done.
Checking connectivity... done.
~/git/Sandbox/android/AndroidGetJSON $ ls volley
Android.mk build build.xml pom.xml
proguard-project.txt src bintray.gradle build.gradle
custom_rules.xml proguard.cfg rules.gradle volley.iml
Your build.gradle for the module/library could be as simple as:
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
If your module is just a collection of .java POJO classes.
If it's model / entity classes and you're using annotations and have some dependencies you could add those in:
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
repositories {
mavenCentral()
}
dependencies {
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.j256.ormlite:ormlite-jdbc:4.48'
}
This happens when you are compiling imported or copied folder/project as module in libraries folder. This issue was raising when I did not include the build.gradle file. when I added the file all went just fine.
For me it turned out to be an relative symbolic link (to the referenced project) that couldn't be used by grade. (I was referencing a library). Thats a pretty edgy edge-case but maybe it helps someone in the future.
I solved it by putting a absolute symbolic link.
Before ln -s ../library after ln -s /the/full/path/to/the/library
I also faced the same issue and it resolved by changing one flag (gradle.ext.set("allowLocalEdits", true)) to false in settings.xml.
For me, one of dependent library does not exist in correct path, but the error message does not point THAT library correctly.
For example, what I missed is :library-3 but the error throws at :library-1.
poor gradle.
Try adding Volley library and sync and run the program. if one has pulled and i has volley usage and the error shows as -Android Studio Gradle Configuration with name 'default' not found then follow the step of adding the volley library in your gradle. hope it helps. I cleared my problem this way.
I'm new in Gradle and Android Studio(Intellij Idea based IDE). My problem is to correct import holoeverywhere to project. I read many similar topics but they dign't give my solution on my problem.
Similar topics:
Android Studio not working with HoloEverywhere and ActionBarSherlock
Building Android Studio project with HoloEverywhere fails
How do I add a library project to Android Studio?
Below put screens of my method of operation:
1 First create new project from scratch
2 Create directory for libs
3 Import new module
4 Import holoeverywhere using Maven model
5 Import settings
6 Add dependencies to main application module
7 Move Holoeverywhere dir to libraries
8 Change parent module name
9 Add dependence to gradle files
10 Change imports in Activity
11 Run result
12 Another attempt to set dependent
Please give me same idea how to correct import holoeverywhere
I agree with #7wonders , but importing mine project to HoloEverywhere would make bigger problem than importing HoloEverywhere in it.
After cloning HoloEverywhere, inside of project you have folder named "library".
Firstly, I copied it to mine folder "libraries" in project's root and renamed it to "HoloEverywhere".
Secondly, I've edited "build.gradle" file in HoloEverywhere folder like this:
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 7
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
dependencies {
compile files('libs/support-v4-18.0.4.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
}
Thirdly, added to "settings.gradle" in project`s root folder
include ":libraries:HoloEverywhere"
before line with include of your project.
After all we should add library HoloEveryWhere to our main project dependencies in "build.gradle" file inside YourProjectName folder.
dependencies {
compile project(':libraries:HoloEverywhere')
}
Don't forget to remove from project dependencies support-v4 & support-v7 libraries.
Finally don't forget to clean project. Choose from Android Studio's Menu Build>Clean Project.
I recommend to do it via Terminal, because you can't see all errors in Run window.
so choose Tools>Open Terminal
firstly you should navigate to project root(command "cd ..") and call:
UNIX:
./gradlew clean
Windows:
gradlew.bat clean
After successful cleaning build your project.
While build I've got error that there is no "application" tag in AndroidManifest.xml
in HoloEverywhere library. So just add it and now everything is OK.
One small, maybe the worst, thing left to do: read basic migration and change all imports, resources(layouts) and override methods with classes from HoloEverywhere library to ignore ClassCastException.
ENJOY :)
To get it working on the most basic of levels just follow the advice given here:
https://github.com/Prototik/HoloEverywhere/wiki/Import-in-IDE
Basically close all projects so you get to the welcome screen. Then:
-> Checkout from Version Control - Git
-> Type in Repository URL: https://github.com/Prototik/HoloEverywhere.git
-> Press 'Clone', wait until repository checkout
-> click 'Yes' on the proposal to open a project.
This should give you a HoloEverywhere project thats ready to work with.
Open up File > Project structure and check for any errors with missing libraries (for example I had to download manually the v4 r18 file).
Click apply > ok to make sure changes are saved and return to the project. Click on demo and then click Run > Edit configurations. Click + then Android Application. Call it demo or whatever. Select demo as module, launch default activity checked, deploy checked, USB device checked.
Hitting the little debug dude should now get you running the demo. From here its simply a case of refactoring the demo to your own project or creating a new Android Application module within the HoloEverywhere project.
In other words, instead of trying to add HoloEverywhere to your project, add your project to HoloEverywhere :)