ClassNotFoundException: android.hardware.camera2.CameraAccessException with OpenCV 3.1.0 - android

I am working in an android project with Android Studio 2.2 that uses OpenCV 3.1.0 library. I imported the library according to this answer. The situation is the following:
When I compile the project for a device with API >= 21 (exactly API 23), everything goes well.
When I compile the project for a device with API < 21 (exactly API 19, the minimum API that I want to support), I get the following compilation error:
Gradle log
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
> java.lang.ClassNotFoundException: android.hardware.camera2.CameraAccessException
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)...
I found these similar questions:
Error: package android.hardware.camera2 does not exist OpenCV
Can't import import android.hardware.camera2 classes
In both of them the solution was to set the compileSdkVersion to minimum 21 (the version where camera2 API was introduced) and make sure that build.gradle files of the project and OpenCV match.
Unfortunately, it does not work for me. I still get the same error. Any idea?
My code is available here: Github repository.
Thanks for your help!

Finally, I found a temporal solution thanks to #JavierMollá.
Switching off Instant Run solved the issue. Go to File > Settings > Build, Execution, Deployment > InstantRun and uncheck Enable Instant Run to hot swap code....
Instant Run is a major feature of Android Studio, but unfortunately it seems that it is still work-in-progress... As #AndreKR suggests, it can be related with this issue #212672.

Related

Android Execution failed for task ':app:compileDebugJavaWithJavac'. - React Native

I am working on a react native application. when I try to build the applications using react-native run-android the build fails. Here is the output of the error that occurs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* 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 8s
253 actionable tasks: 5 executed, 248 up-to-date
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: ./gradlew app:installDebug
debug Error: Command failed: ./gradlew app:installDebug
at checkExecSyncError (child_process.js:607:13)
at execFileSync (child_process.js:627:13)
at runOnAllDevices (/Users/FaisalHussain/mobile/node_modules/#react-native-community/cli/build/commands/runAndroid/runOnAllDevices.js:58:39)
at buildAndRun (/Users/FaisalHussain/mobile/node_modules/#react-native-community/cli/build/commands/runAndroid/runAndroid.js:142:41)
at then.result (/Users/FaisalHussain/mobile/node_modules/#react-native-community/cli/build/commands/runAndroid/runAndroid.js:104:12)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
The application was on a old version of react native (0.48.x) I have updated it to 0.59.10.
What I have done so far:
used jetifier to resolve issues with the plugins.
checked that the build tools version matches the compile sdk version
checked if the emulator is running.
Hence I have tried everything I could to resolve this but had no luck. Please do guide me on how to resolve this issue. Looking forward to your answers.
make sure you have followed all the necessary steps from the upgrade helper https://react-native-community.github.io/upgrade-helper/?from=0.48.0&to=0.59.10
also i would suggest you to upgrade to v0.60+ because there are breaking changes after v0.59.10.
having said that
before you run the app make sure your gradle is clean
run the following command to clean your gradle cd android && ./gradle clean
then later you can navigate back to your app folder cd .. and try and run again react-native run-android
Looks like your packages not working stable with Android side. It's better be update all packages and react native version to their last stable versions.
If you face with too much error while update, you can create fresh new react native project (with same package name with your current project), install all packages (and their dependencies) and copy your current project's source code to your new project.
Android in React Native does not allow similar packages to reside in the project.
In my case I had react-native-cookies and #react-native-cookies/cookies packages that add similar code to the Kotlin file upon build. This causes issue of similar imports in java JDK.
I removed one and it worked.
SOLVED at the same issue:
My solution was at /android/build.gradle file.
Somehow, the buildscript versions were wrong.
Follow the exact same step of RN documentation and make a totally new & clean project.
And compate the /android/build.gradle file > buildscript & dependencies part.
There should be some version differences.
It matters by your own local env settings.
After changing buildToolsVersion, ndkVersion, classpath, it worked fine again!!
also, remove duplicated libraries, as #Nimantha said.

The specified Android SDK Build Tools version is ignored in flutter

My flutter project was working properly, but when i tried to start the project recently, i got the android error below.
WARNING: The specified Android SDK Build Tools version (25.0.0) is ignored, as it is below the minimum supported version (26.0.2) for Android Gradle Plugin 3.0.1.
Android SDK Build Tools 26.0.2 will be used.
To suppress this warning, remove "buildToolsVersion '25.0.0'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
:app:properties FAILED
1 actionable task: 1 executed
FAILURE: Build failed with an exception.
*What went wrong:
null value in entry: outputFile=null
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I checked my app/build.gradle file but could not find buildToolsVersion '25.0.0'.My compileSdkVersion and targetSdkVersion are both 27.
I tried adding buildToolsVersion '26.0.2' , 27.0.3 and 28.0.1 which have already been installed, but i still get the same 25.0.0 error.
I can't tell what i'm doing or did wrong. Any help will be greatly appreciated.Thank you.
Really dumb suggestion, but have you tried a File->Invalidate Caches/Restart?
The error is in this bit:
FAILURE: Build failed with an exception.
*What went wrong:
null value in entry: outputFile=null
This likely has to do with updating the Gradle version in the project (perhaps unintentionally by click the "Upgrade gradle now" button), which caused a different parse of your Gradle script due to some form of backwards incompatibility.
If the project has source code control this would be pretty easy to check.

Gradle Android task crashing with unclear error

I am trying to run a Gradle Android task generated by libGDX utility (the desktop task runs fine) in IntelliJ IDEA, but I'm only getting this nonspecific error message. What is the issue, or where are the logs, or how to enabled logs?
Information:Gradle: Executing tasks: [:core:assemble, :android:assembleDebug]
Information:24. 10. 2015 16:58 - Compilation completed with 1 error and 0 warnings in 9s 415ms
Error:Gradle: Execution failed for task ':android:proguardDebug'.
> java.io.IOException: Please correct the above warnings first.
PS: Not sure if it is relevant, but I have modified build files and ProGuard file to support Scala as described there.
I did not find a way of getting any useful logs from IntelliJ IDEA. I solved the problem by running Gradle from console.
gradlew assemble --stacktrace --info
Problem was Gradle could not find tools.jar. Adding system environment variable JAVA_HOME pointing to Java SDK directory fixed the issue.

Could not find com.android.support:support-v4:21.0.2

I m using Android Studio v0.8.6
I have an Android app using google-play-service and I get this error when I try to build:
Executing tasks: [clean, :libraries:BaseGameUtils:generateDebugSources, :app:generateDebugSources]
Configuration on demand is an incubating feature.
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.android.support:support-v4:21.0.2.
Required by:
RIGHTER-android:app:unspecified
RIGHTER-android:app:unspecified > com.google.android.gms:play-services:6.1.11
RIGHTER-android:app:unspecified > RIGHTER-android.libraries:BaseGameUtils:unspecified > com.android.support:appcompat-v7:20.0.0
> Could not find com.android.support:support-v4:21.0.2.
Required by:
RIGHTER-android:app:unspecified > RIGHTER-android.libraries:BaseGameUtils:unspecified
> Could not find com.android.support:support-v4:21.0.2.
Required by:
RIGHTER-android:app:unspecified > com.github.filippudak.progresspieview:library:1.0.4
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 3.405 secs
This Error just happened recently and I didn't update a thing.
Any help will be appreciated, Thanks in advance!
Don't forget to update the Android SDK Manager once in a while :-}
AS I can understand my comment: "Can you check in Android SDK Manager if you have installed Android Support Library 21.0.2?" helped you.
But coming to core of issue. I think, that core of your issue was dependencies part in build.gradle. I strongly believe, that in:
compile 'com.google.android.gms:play-services:x.y.z'
you had somewhere '+', and it means, that version of library, that you are using is not set once, and can change, and this happened with Google Play Services Library.
Always try to put full version number of library, to not have this kind of issues in feature.
Just open the Android SDK manager and install the Android Support Library and the Android Support Repository.

Android Fit API Basic Sensors Sample Fails to Build

I'm unable to build the Android Fit basic sensors sample due to a missing dependency. I'm new to gradle so I don't know how to fix the build issue. How do I add this missing dependency?
Pre-requisites says:
Android API Level >v9
Android Build Tools >v19
Android Support Repository
My environment:
Android SDK Build-tools: 23.0.5
Android 5.0 (API 21)
Android Support Repository 7
Android Support Library 21
Google Play services 21
Build:
$ gradlew build
Relying on packaging to define the extension of the main artifact has
been deprecated and is scheduled to be removed in Gradle 2.0
FAILURE: Build failed with an exception.
What went wrong: A problem occurred configuring project ':app'.
Could not resolve all dependencies for configuration
':app:_debugCompile'.
Could not find any version that matches
com.google.android.gms:play-services:6.1.+.
Required by: BasicSensorsApi:app:unspecified Try: Run with
--stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.582 secs
You need to install the Google Repository as well:
https://developer.android.com/sdk/installing/adding-packages.html

Categories

Resources