JDK installation not found by flutter starter app - flutter

I have cloned the flutter repo and installed the Android SDK command-line tools, setting them up in $HOME/Android. I then made flutter aware of the SDK installation by setting $ANDROID_HOME to $HOME/Android. Things seem to have worked out, with <path-to-flutter> doctor finding
Android SDK
my Java JDK 8 installation (openjdk-8-jdk package on Ubuntu 18.04), and
a connected Android phone with USB debugging
I am now trying to follow the test-run instructions for building a first app on the command line. <path-to-flutter> create myapp works and produces a myapp directory. I then try to run the resulting starter app:
cd myapp
~/myapp$ ANDROID_HOME=~/Android JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 <path-to-flutter> run
This results in the following error:
Launching lib/main.dart on ONEPLUS A6013 in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Kotlin could not find the required JDK tools in the Java installation '/usr/lib/jvm/java-8-openjdk-amd64/jre' used by Gradle. Make sure Gradle is running on a JDK, not JRE.
* 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
BUILD FAILED in 10s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 11.0s
Exception: Gradle task assembleDebug failed with exit code 1
I have seen this issue discussed before, but none of those replies seem to address it (in my case, at least). You can see from the command that I am exporting the right $JAVA_HOME, and besides, running
./android/gradlew build
inside the myapp directory does work:
~/myapp$ ./android/gradlew build
> Task :buildEnvironment
------------------------------------------------------------
Root project
------------------------------------------------------------
classpath
No dependencies
A web-based, searchable dependency report is available by adding the --scan option.
BUILD SUCCESSFUL in 319ms
1 actionable task: 1 executed
So this seems to be specific to flutter itself somehow, rather than gradle.

It turns out this must have been a path issue. The Flutter starter app builds (and pops up on my device) after inserting the following snippet in a file sourced in my profile (my .bashrc):
# Java
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
# Android
export ANDROID_HOME=${HOME}/Android
export ANDROID_SDK_ROOT=${HOME}/Android
# Flutter
export FLUTTER_HOME=${HOME}/repos/flutter
PATH=${FLUTTER_HOME}/bin:$PATH; export PATH

you can do like this -->
sudo apt-get remove --auto-remove openjdk*
sudo apt-get install openjdk-8-jre
now goto to home and visible your hidden folder by pressing ctrl+h
Now open .bashrc or your .rc
paste these on last
export PATH="$PATH:/snap/bin/flutter/bin"
export PATH="$PATH:/usr/bin/java"
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
export ANDROID_SDK_ROOT=/home/<YOUR USER NAME>/Android/Sdk
then run
source ~/bashrc
flutter doctor -v

Related

ionic - BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 63

I am working ionic angular
while run this comment cordova build android --release
am getting this error
PS C:\Users\Nirali\Documents\nmhapp> cordova build android --release
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=C:\Users\Nirali\AppData\Local\Android\Sdk (recommended setting)
ANDROID_HOME=C:\Users\Nirali\AppData\Local\Android\Sdk (DEPRECATED)
Using Android SDK: C:\Users\Nirali\AppData\Local\Android\Sdk
FAILURE: Build failed with an exception.
What went wrong:
Could not open settings generic class cache for settings file 'C:\Users\Nirali\Documents\nmhapp\platforms\android\settings.gradle' (C:\Users\Nirali.gradle\caches\7.5.1\scripts\7e15adv812akcxkuh6ist7or8).
BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 63
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 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 771ms
Command failed with exit code 1: C:\ProgramData\chocolatey\bin\gradle.EXE -p C:\Users\Nirali\Documents\nmhapp\platforms\android wrapper -b C:\Users\Nirali\Documents\nmhapp\platforms\android\wrapper.gradle
PS C:\Users\Nirali\Documents\nmhapp>
How to fix this issue.
Upgrade to a snapshot of gradle 7.6, or wait for the 7.6 release
https://services.gradle.org/distributions-snapshots/gradle-7.6-20221021231540+0000-bin.zip
Solved this issue by opening my project in Android Studio, and it began building Gradle, then it recommended I upgrade Gradle. After the upgrade in Android Studio, I can now run my app.
Windows user:
Go to C:\Users\arpan.gradle\caches and delete all the gradle cache.
then,
Go to "C:\Program Files\Android\Android Studio" there you will see jbr and jre folder then copy the content of jbr and paste the content into jre folder.
ss:
and run flutter doctor again and run your App.

Could not find a package configuration file provided by "openssl"

I'm trying to use OpenSSL with Flutter using dart:ffi, but when i run the project on Ubuntu 20.04 the error message as below comes out. I tested the project on Windows 10 and it worked.
Project repository
CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(flutter_openssl_crypto)
find_package(openssl REQUIRED CONFIG)
add_library(${PROJECT_NAME} SHARED empty.c)
target_link_libraries(${PROJECT_NAME} PRIVATE openssl::crypto)
Error
CMakeLists.txt:6 (find_package):
Could not find a package configuration file provided by "openssl" with any
of the following names:
opensslConfig.cmake
openssl-config.cmake
Add the installation prefix of "openssl" to CMAKE_PREFIX_PATH or set
"openssl_DIR" to a directory containing one of the above files. If
"openssl" provides a separate development package or SDK, be sure it has
been installed.
* 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
BUILD FAILED in 4s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 5.3s
Exception: Gradle task assembleDebug failed with exit code 1
How can i run the project on Ubuntu?
I found the problem.
I had installed Android Studio and Flutter SDK for Ubuntu software, that's the problem.
When I reinstalled both from the official websites, the project work's.

Exception: Gradle task assembleDebug failed with exit code 1 (runs at web but doesn't at emulator)

I'm having this issue when I try to run the standard flutter new project app:
Launching lib\main.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...
FAILURE: Build failed with an exception.
* Where:
Build file 'E:\AndroidStudioProjects\good_heart\android\app\build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.internal.version-check']
> Minimum supported Gradle version is 6.5. Current version is 4.10.2. If using the gradle wrapper, try editing the distributionUrl in E:\AndroidStudioProjects\good_heart\android\gradle\wrapper\gradle-wrapper.properties to gradle-6.5-all.zip
* 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
BUILD FAILED in 16s
Exception: Gradle task assembleDebug failed with exit code 1
This happens when I try to run it in a android emulator (one provided by android studio), doesn't happen when I run it in Edge(web) though, it runs smoothly.
Any thoughts? Already tried installing older versions of JDK (such as 11 and 8). Reinstalling Android Studio and flutter... Running it from VScode outputs the same error.
If you Use Android Studio Emulator
Open AVD Manager then select your Emulator right click it and select or click on Wipe data or Cold Boot Now and then run or launch your app your project
hope its help to you
you need to update your Gradle wrapper
go to android/gradle/wrapper/gradle-wrapper.properties and change the last line to: distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip Android Studio will download the necessary library.

Flutter : Could not create service of type ResourceSnapshotterCacheService using GradleUserHomeServices.createResourceSnapshotterCacheService()

I was working on react native but now i decided to learn flutter so first I learnt dart using dartpad.dev
and now I was installing flutter. So I followed steps given in docs. I cloned sdk with git, added path in environment variables, installed flutter & dart extensions in vs code, ran flutter doctor. Also i created a new dart project. Till then everything was working fine but when i tried to run my app (without chaging any code) it took few minutes and throw me this error -
What went wrong:
Gradle could not start your build.
> Could not create service of type ResourceSnapshotterCacheService using GradleUserHomeServices.createResourceSnapshotterCacheService().
> Timeout waiting to lock file hash cache (C:\Users\HP\.gradle\caches\6.7\fileHashes). It is currently in use by another Gradle instance.
Our PID: 12348
Owner Operation:
Our operation:
Lock file: C:\Users\HP\.gradle\caches\6.7\fileHashes\fileHashes.lock
* 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
BUILD FAILED in 1m 4s
Exception: Gradle task assembleDebug failed with exit code 1
I tried to run it from android studio also but got same error everytime.
Don't know why i am getting this error even my emulators are working fine
All what you have to do is to remove the *.lock files by running this command:
find ~/.gradle -type f -name "*.lock" -delete
This happens usually because you installed more than one instance of Android Studio.
Ps: Take into consideration changing the ~/.gradle if your gradle isn't located in your home

How to properly import Open Source projects in Flutter?

I am learning Flutter and I would like to import an Open Source project to learn some of the structure etc.
The project is: https://github.com/matthewtory/trinity-orientation-2018
I am using Android Studio, and so far I can create my own projects and run them via my phone but when I want to import this project I am getting a lot of errors and warnings. The app is finished and also on the play store, so why doesn't it run in my IDE? Am I missing something?
Error message is:
Launching lib\main.dart on SM G960F in debug mode...
Initializing gradle...
Resolving dependencies...
* Error running Gradle:
ProcessException: Process "C:\Users\marcs\AndroidStudioProjects\trinity-orientation-2018-master\android\gradlew.bat" exited abnormally:
firebase_storage
firebase_messaging
url_launcher
camera
path_provider
cloud_firestore
shared_preferences
image_picker
firebase_core
firebase_auth
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\marcs\AndroidStudioProjects\trinity-orientation-2018-master\android\app\build.gradle' line: 16
* What went wrong:
A problem occurred evaluating project ':app'.
> versionCode not found. Define flutter.versionCode in the local.properties file.
* 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
BUILD FAILED in 2s
Command: C:\Users\marcs\AndroidStudioProjects\trinity-orientation-2018-master\android\gradlew.bat app:properties
Finished with error: Please review your Gradle project setup in the android/ folder.
I downloaded the project and imported the folder in Android Studio. It first asked to get the dependencies which I did and immediately, I tried to run it on my phone.
Feel free to check the code on the Github project. I have not changed anything. I hope to run this project to learn about animation and navigation concepts.
The error message says you have to define version code. Try to add below lines to your local.properties file (under android folder)
flutter.versionName=1.0.0
flutter.versionCode=1
You may get other errors but at least this will fix the error in your question. Share other error message if you get.