Error when running new flutter installation - flutter

I'm using Flutter from stable channel, v1.9.1+hotfix.6, on Linux), Android SDK version 29.0.2 and Android Studio version 3.5. on ubuntu 18.4. All necessary PATHs are set.
The doctor summary shows no problems.
When I run "flutter build" I get the error:
Initializing gradle...
Resolving dependencies...
* Error running Gradle:
ProcessException: Process "/.../flutter/raw/android/gradlew" exited abnormally:
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to
/.../android-sdk/ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
BUILD FAILED
Total time: 7.627 secs
Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
java.lang.IllegalStateException: buildToolsVersion is not specified.
at com.google.common.base.Preconditions.checkState(Preconditions.java:173)
at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.java:558)
...
...
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
FAILURE: Build failed with an exception.
* Where:
Script '/.../flutter/packages/flutter_tools/gradle/flutter.gradle' line: 27
* What went wrong:
A problem occurred evaluating script.
> Could not find method google() for arguments [] on repository container.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Command: /... /flutter/raw/android/gradlew app:properties
Please review your Gradle project setup in the android/ folder.
How can the problem be fixed?

Per https://github.com/flutter/flutter/issues/53657#issuecomment-795808016, the recommended solution is now to simply upgrade your gradle version to 4.1.2 or higher.
classpath 'com.android.tools.build:gradle:4.1.2'

It appears that NDK is not on your PATH or the project is looking in the wrong place.
First verify you have NDK installed/.
Install NDK
Tick this box.
If NDK is indeed installed you will need to change project structure to point to the correct location.

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.

Flutter says Execution failed for task ':sqflite:compileDebugJavaWithJavac'

I used to have this sqflite in my pubspec.yaml file but recently I removed the dependence seeing I won't be making use of it, then I run the app on my android device and emulator I got a strange error and have googled for the solution, it seems I can't find any help and as well check stackoverflow.
What have done so far:
As a rule of thumb, i ran flutter clean to see if issue will be
resolved but it did not worked either
Invalidate and Restart Android Studio
Here is the Error am having
Launching lib/main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
/Users/zionnite/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.0+3/android/src/main/java/com/tekartik/sqflite/SqflitePlugin.java:910: error: cannot find symbol
database.deleteDatabase(path);
^
symbol: variable database
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':sqflite: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
BUILD FAILED in 58s
Exception: Gradle task assembleDebug failed with exit code 1
Dependency of Interest
# sqflite: ^2.0.0+3
# path_provider: ^2.0.1
At this time even if I enable the dependency, the issue still persists.
However, everything is working out great on my ios simulator except android device and emulator
The issue caused by Java version 8. So you should use Java version 11.
Add this to build.gradle file (android/app/build.gradle)
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
Change JDK of Gradle in Android studio
Finally, Clean and rebuild.
That's it.
Issue resolved after downloading Java 11,also check the gradle and wrapper version you're using
I was encountering the same issue.I have done everything which is mentioned on stackoverflow .but the problem is in my new added package which is cached_network_image .I just remove this package and every thing start working.So you just check which new package you added and which create fuss..
I was able combat the enemy of death fighting for the progress of my code and obtain victory through the magical touch of flutter pub cache repair.
what i mean to say is that, when i ran flutter pub cache repair, Flutter was able to build and run on my android device and emulator

I am using VS Code for Flutter. I have downloaded Android SDK platform 30. But it tells me to download 29 version

I am new to flutter. Here is a list of available tools on SDK Manager -
As you can see I've downloaded the tools. But debugging in the ide shows an error and tells me download a tools that are not installed -
'''
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Failed to install the following SDK components:
build-tools;28.0.3 Android SDK Build-Tools 28.0.3
platforms;android-29 Android SDK Platform 29
Install the missing components using the SDK manager in Android Studio.
2
* 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 51s
[!] Gradle threw an error while downloading artifacts from the network. Retrying to download...
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
'''
Please help me out.
There seemed to be errors in installing certain dependencies ( sdk 30 ). Might be a technical glitch. Try installing again using flutter doctor.
I think you have to accept the licenses before building.
Try this command in the terminal
flutter doctor --android-licenses
Try flutter doctor command in your terminal. which helps us diagnose issues with your setup
flutter doctor
to learn more https://stackoverflow.com/a/55641042/7904389
Please share the android/app/build.gradle, it is probably targeting API level 29 (targetSdkVersion 29 and compileSdkVersion 29). Change them to 30 or download the API level 29 SDKs.
If it still doesn't work after that, the SDK might be missing, go to the ANDROID_HOME directory and ensure it contains an sdk directory with the stuff you want.
I couldn't figure out what the error was, but creating a new project worked for me.

flutter build apk --release command not work

TYSONs-MacBook-Air:chats jeshurun$ flutter build apk --release
You are building a fat APK that includes binaries for android-arm, android-arm64, android-x64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
To generate an app bundle, run:
flutter build appbundle --target-platform android-arm,android-arm64,android-x64
Learn more on: https://developer.android.com/guide/app-bundle
To split the APKs per ABI, run:
flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi
Learn more on: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
Plugin project :firebase_core_web not found. Please update settings.gradle.
Plugin project :cloud_firestore_web not found. Please update settings.gradle.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':device_info:verifyReleaseResources'.
> A failure occurred while executing
com.android.build.gradle.internal.tasks.Workers$ActionFacade
> 1 exception was raised by workers:
com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
/Users/jeshurun/.gradle/caches/transforms-2/files-2.1/8caf43a43008a17794fe6e0dd5ac61b7/core-1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/fontVariationSettings not found.
/Users/jeshurun/.gradle/caches/transforms-2/files-2.1/8caf43a43008a17794fe6e0dd5ac61b7/core-1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/ttcIndex 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
BUILD FAILED in 14s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 15.6s
The built failed likely due to AndroidX incompatibilities in a plugin.
The tool is about to try using Jetfier to solve the incompatibility.
Building plugin agora_rtc_engine...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done 1.7s
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':compileReleaseAidl'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/jeshurun/flutter/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-1.0.12/android/local.properties'.
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 1s
The plugin agora_rtc_engine could not be built due to the issue above.
First, flutter build apk by default uses argument --release.
Next, May be you are using AndroidX packages within your app but your app not migrated to use AndroidX. To ensure that:
In an app or module project, the file android/gradle.properties or .android/gradle.properties must contain:
android.useAndroidX=true
android.enableJetifier=true
Or else maybe because your compileSdkVersion is lower than 28,
Try setting compileSdkVersion 28 or 29 to app/build.gradle. If this not solved your problem may be one of your plugin is the problem. Ofcourse you can edit your plugin build gradle but I do not recommend that.
First, Try upgrading packages that are not updated. If not upgarded those packages, you can follow below by opening flutter root android directory in android studio.
Steps:
Go to External libraries
Locate the library that raised the issue
Open it's app/build.gradle
Update the compileSdkVersion to 28 or 29
Also you can cloned the packages that causes the problem and do aboves and push it to github and in the pubspec.yaml, access from github like below:
dependencies:
#...
repo_name:
git:
url: git://github.com/your_github/repo_name.git
If none of them worked, worth trying below options :D,
Flutter clean / Deleted build folder
Deleted pubspec.lock, .packages, .flutter-plugins
Flutter pub cache repair
Ensured compileSdkVersion is 28 in app/build.gradle
finally, try Deleting flutter/.pub-cache
In android build.gradle file try to change the compileSdkVersion to: compileSdkVersion 28

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.