I was trying to use opencv library, so I imported one of its projects in Android Studio and when I tried to run it I got this error:
Error:Execution failed for task ':openCVSamplefacedetection:compileDebugNdk'.
NDK not configured.
Download the NDK from http://developer.android.com/tools/sdk/ndk/.Then add ndk.dir=path/to/ndk in local.properties.
(On Windows, make sure you escape backslashes, e.g. C:\ndk rather than C:\ndk)
So I downloaded the ndk and I addes this line to the local.properties file where it became:
sdk.dir=C\:\\Users\\skoon\\AppData\\Local\\Android\\sdk
ndk.dir=C\:\\Users\\skoon\\AppData\\Roaming\\IDM\\android-ndk-r10d
but I still got this error which I didn't understand:
Error:Execution failed for task ':openCVSamplefacedetection:compileDebugNdk'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\skoon\AppData\Roaming\IDM\android-ndk-r10d\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\Android.mk APP_PLATFORM=android-14 NDK_OUT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj NDK_LIBS_OUT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\lib APP_ABI=all
Error Code:
2
Output:
make.exe: *** No rule to make target 'C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/detection_based_tracker/C_\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\src\main\jni', needed by `C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/detection_based_tracker/C_\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\src\main\jni\DetectionBasedTracker_jni.o'. Stop.
I didn't change anything in the code, so what should I do? do I need to change or add any variables to point to the ndk?
P.S. This is my first time trying to build Android application so I don't have any experience.
Thank you in advance.
UPDATE:
To import the project I just used import project from file, then I synced the gardle, and run the project.
the package that I downloaded from opencv was the Android one, and I tried to use the face detection sample.
when I run it I got the error above.
You need to setup OpenCV librairies for your project. You can follow the instruction here.
OpenCV sample projects haven't support gradle officially. I think it will be easier if you start a new project and configure it to work as in examples.
I have implemented a tutorial project using Android Studio + NDK + OpenCV. You may have a look. https://github.com/quanhua92/NDK_OpenCV_AndroidStudio
Install NDK in your SDK manager, if you already installed open app's "build.gradle" replace these lines
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/', 'src/main/jni/'] } }
to
sourceSets.main {
jniLibs.srcDir 'src/main/jniLibs' // mention your JNI lib path(where ".so" files contains)
jni.srcDirs = [] //disable automatic ndk-build call
}
I'm tried to configure OpenCV and its fixed
Related
I am getting error 'Caused by: org.gradle.process.internal.ExecException: Process 'command '/home/ec2-user/jdk1.8.0_45/bin/java'' finished with non-zero exit value 2' when submitting an Android build request.
I suspect it has got to do with Flurry CN1Lib
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':transformClassesWithDexForRelease'.
Caused by: java.lang.RuntimeException: com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.dx.command.Main with arguments {--dex --verbose --force-jumbo --num-threads=4 --output
The flurry cn1lib needs to be updated to use the newer Android API level 28 for location which is our current default. That's the right thing to do for the long term.
As a short term patch you might be able to define: android.playServicesVersion=8.3.0 in the build hints to work around this. Notice that this might impact the functionality of your app such as location services support etc.
Well, I finally managed to fix this issue. I was only interested on getting the analytics bit working but I believe Ads should work too. Here is how I did it:
Cloned/downloaded the current CN1Flurry project from GitHub here https://github.com/chen-fishbein/flurry-codenameone. This allowed me to access the source files and use them for reference.
Importing the project as is into my Netbeans was bringing some 'resolve project' issues so I just went ahead and created a new project with similar name and package/class structure as CN1Flurry then copied classes from old project into the new one.
Open the FlurryNative class and delete the onPageView(), setLogEvents() and setCrashReportingEnabled() as these aren't supported by current Flurry Android SDK. Once done, right-click on the FlurryNative class and choose 'Generate Native Access'. This will allow you to create native implementations for Android, iOS, Windows etc in the 'native' folder of the project.
Chen's project uses version 5.3.0 of Flurry SDKs but the recommended SDK version is version 12.1.0. Download the latest aar files from your Flurry portal under the 'Admin' section and copy them to the 'android' folder. For me these were flurryAds_12.1.0.aar and flurryAnalytics_12.1.0.aar
Switch to the Files view of your Netbeans project and open the FlurryNativeImpl class. You can copy most of the implementations from Chen's project the only thing you need to change is the initFlurry() method to - new FlurryAgent.Builder().build(AndroidNativeUtil.getActivity(), apiKey); Flurry is initialized differently in the new SDK - https://developer.yahoo.com/flurry/docs/integrateflurry/android/
That's it. Switch back to the 'Projects' view then clean and build your CN1Flurry project to generate the .cn1lib file which you can then add to your UI project in the 'libs' folder. Remember to refresh cn1Libs files.
Finally, add the following build hints to your UI project:
android.min_sdk_version=16
android.multidex=true
android.xapplication=\<activity android:name="com.flurry.android.FlurryFullscreenTakeoverActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"> \</activity>
Chen suggests a whole lot of other build hints to add but I didn't find them useful for my case.
Still learning the ropes on how GitHub works; will make a pull request once I get comfortable. Meanwhile, you can get the entire project here - https://drive.google.com/open?id=1GGygaVelmMhMUX9Deik9W72hXkw_detG
Repro steps:
Start a new project in Android Studio (with the latest update);
Make a new class and add main() as usual;
Right-click class to run main() as a test.
package test;
public class Test {
public static void main(String[] args) {
}
}
Usually I expect I can just System.out.printLn("Hello World") but this time, no matter if it's a new project, I get the following error:
2:34:23 PM: Executing task 'Test.main()'...
Executing tasks: [Test.main()] in project C:\Users\regan\Desktop\events\MyApplication
FAILURE: Build failed with an exception.
* Where:
Initialization script 'C:\Users\regan\AppData\Local\Temp\Test_main__2.gradle' line: 20
* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:Test.main()'.
> SourceSet with name 'test' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 0s
2:34:24 PM: Task execution finished 'Test.main()'.
I am fairly new to Java after years of C# in Unity and have no idea what all this stuff is trying to tell me. I have googled but the closest I found was a way to HIDE this error (assuming code was still compiling). I need this code to at least compile.
Quick Fix : You can run using Run with Coverage.. See Image Below.
Permanent Solution: Add <option name="delegatedBuild" value="false" /> and sync project.
inside File gradle.xml under path E:\Project\.idea\gradle.xml. See Image below.
Open "gradle.xml" File in this path :
.idea/gradle.xml
Add the following line before </GradleProjectSettings/>
<option name="delegatedBuild" value="false" />
That is it , it worked for me.
The app module is an android library and expects android lifecycle methods such as onCreate() etc for successful execution. If you want to execute plain java code one option is to add a java library to the project using File -> New Module -> Java Library and add the main method there:
package com.example.lib;
public class MyClass {
public static void main(String[] args) {
System.out.println("Hello");
}
}
This would work as you expect it to.
Try to run it with "coverage". I don't have any explanation, but it works!
I'm currently using Android Studio Version 4.0.1
after creating the project, you should go to tab
File ==> New ==> New Module...
on "Create New Module/ Selecte Module Type":
Select Java or Kotlin Library
After it finish, go to javalib folder/ module that you have created.
Create Java file on there.
try to run it
I had this problem momentarily as well
I found when I changed Gradle to offline and then back online again then updated Gradle and made sure the connection and proxy settings were correct, things started working normally
Avoid naming the class name as Test, Android studio somehow will get screwed when you name class as Test.
If the module is from an android application or library it is not allowed to run the main; because what is expected is navigate transitions between stages of the activity lifecycle.
In the following cases of modules with these plugins applied, the main can NOT be run.
build.gradle.kts (:appAndroid)
plugins {
id("com.android.application")
id("kotlin-android")
}
build.gradle.kts (:libraryAndroid)
plugins {
id("com.android.library")
id("kotlin-android")
}
build.gradle.kts (:kmmShared)
plugins {
kotlin("multiplatform")
id("com.android.library")
}
If the purpose of running the main was to test things, what you really have to do is use the sourceSets of test.
If the module is from a Java or Kotlin library, running the main is allowed so the error would not exist.
The following applied plugins describe a JVM library:
build.gradle.kts (:jvmLibrary)
plugins {
id("java-library")
id("kotlin")
}
Finally, if using the test sourceSets or creating a JVM module was not enough for you, there is a 'hack' which is weak because it depends on the IDE (It does not work in KMM modules).
.idea/gradle.xml
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="delegatedBuild" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
GL
I have not much idea about it as I am very new in Android development and Android Studio. But after reading some solution over the internet and watchin some Youtube Videos, I have fixed it.
In app/build.gradle under dependencies for me
implementation 'androidx.appcompat:appcompat:1.4.1' - this was there
I changed it to
implementation 'androidx.appcompat:appcompat:1.2.0'
rebuilt the project and run, it worked for me..
I guess there must be some android studio update (in the latest version) was causing the problem.
I also got stuck in this problem. I am using Android Studio Arctic Fox in Macbook Pro M1. I have also tried to add New Module and Select Java and Kotlin Library and edited the configuration but it did not work for me. But it did work on my Windows System.
In macbook, I simply downgraded the dependancy in my App level build.gradle file
from
implementation 'androidx.appcompat:appcompat:1.5.0'
to
implementation 'androidx.appcompat:appcompat:1.2.0'
and run my Java Class as Run as Coverage and it worked.
I'm trying to make an application with opencv that is able to recognize a person's face in an image, so I'm trying to use the FacemarkKazemi function of opencv. My problem is that as soon as I switch to class initialization, my application crashes instantly.
You can find the code I'm trying to run here :
https://github.com/opencv/opencv_contrib/blob/master/modules/face/samples/Facemark.java
The application crashes at line 29 here :
Facemark fm = Face.createFacemarkKazemi();
And i have this error :
java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.face.Face.createFacemarkKazemi_0() (tried Java_org_opencv_face_Face_createFacemarkKazemi_10 and Java_org_opencv_face_Face_createFacemarkKazemi_10__)
Also, if you know a better way to make FacialMarks, I would be happy to know it.
EDIT : I added this line to my gradle to import opencv contrib, do you think the error could be due to this?
implementation 'com.quickbirdstudios:opencv:3.4.4-contrib'
Before I integrated opencv directly into my project, when I wanted to add opencv-contrib I had to add the gradle to my project (but that never gave me the.so for android) that's why it wasn't able to find the functions, there were no pre-compiled files.
So I downloaded an opencv sdk with opencv contrib and added the.so in the jnilibs folder.
I try to add the facebook sdk to my delphi android project. I add to the libraries the file facebook-android-sdk.jar, however when i run the app and try to launch for exemple :
package com.wrapper.facebook;
import com.facebook.share.widget.AppInviteDialog;
public class FaceBookAppInvite {
public static boolean canShow() {
return AppInviteDialog.canShow();
}
}
when i call from delphi canShow i receive the error: java.lang.noClassDefFoundError: Failed resolution of: Lcom/facebook/R$style;
what did i miss ? where to find and how to add R$style ?
Android development tools will generate [your package].R.java from your android project resources when you compile your project.
And then some resources would be parts of inner class of R class.
I think you know this well.
After looking your question, the Lcom/facebook/R$style may be the R class generate from facebook sdk resource.
but i have no any experience of using facebook sdk, however i have some sugestion for you:
1.Decompile the facebook-android-sdk.jar. Make sure that there is no any R class in it.
2.Read the facebook sdk tutorial again.Try to find out which stup you have miss.
3.What kind of ide do you use? may be your project output apk does not include any facebook sdk, because your ide compile script does not output sdk with your codes.so check it out.
4.Do you have more runtime log?
I'm currently trying to do the hello-jni sample in android studio and I have encountered an issue.
In the static constructor the System.loadLibrary doesn't work. This is understandable as I currently haven't added the lib path to java.library.path. So I decided to replace it with System.load and using the absolute path and now I get the following error:
java.lang.UnsatisfiedLinkError: Cannot load library: load_library[1093]: Library 'C:/Users/Public/Documents/AndroidStudioProjects/hello-jni/app/src/main/libs/armeabi/libhello-jni.so' not found
I'm a pretty stumped now and would greatly appreciate a push in the right direction.
Try this.
Place your library here:
hello-jni/app/libs/armeabi/yourlib.so
Add in your activity:
static {
System.loadLibrary("yourlib");
}
Add in your build.gradle:
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>()
pkgTask.jniFolders.add(new File(projectDir, 'libs'))
}
Make sure libs folder exists and you have .so files present in them. If your .so files exist in the jni/libs folder then you need to inform the build system to look for the .so files there. Add the following to your build.gradle
sourceSets.main
{
jniLibs.srcDir 'src/main/libs'
}
Do not use absolute path in your static loadlibrary method
Check this video for how to create NDK apps with Android studio https://www.youtube.com/watch?v=kFtxo7rr2HQ&list=UUkbLy9aj5IBXfS6WqLy5Qmw
So the issue I had was to do with the CPU of my emulator.
I ended up using an emulator with an ARM cpu instead of an Intel Atom (x86) and it worked.
Although this solves the immediate problem I am confused about why this is an issue in the first place. I have the .so file in the x86 libs folder. Any reasoning to why it doesn't work would be greatly appreciated.