flutter Build Error - Error when running on virtual mobile device - flutter

When building in a mobile environment, an error occurs.
Google Chrome does it right. However, when running on Pixel 4 api 30 (mobile), an error occurs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':path_provider_android:parseDebugLocalResources'.
> Could not resolve all files for configuration ':path_provider_android:androidApis'.
> Failed to transform android.jar to match attributes {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for PlatformAttrTransform: C:\Users\user\AppData\Local\Android\Sdk\platforms\android-31\android.jar.
> C:\Users\user\AppData\Local\Android\Sdk\platforms\android-31\android.jar
* 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 6s
Exception: Gradle task assembleDebug failed with exit code 1
jdk version
app build.gralde
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 33
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
build.gralde
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I updated Android Studio to the latest version.
I installed jdk and added sdk 11.
I have created a project in a new folder.
I've been thinking about this door for two days, but I couldn't solve it.
If you have a problem with my questioning method or code, please feel free to let me know.

Try this solution
in build.gradle <project-file/android/app/build.gradle> (app level)
compileSdkVersion 31
and
defaultConfig {
minSdkVersion 16
targetSdkVersion 31
...
}
in build.gradle <project-file/android/build.gradle> (project level) :
dependencies {
classpath 'com.android.tools.build:gradle:7.0.1'
}

Related

How to solve Flutter error with gradle 1151

After an upgrade of my flutter , i am having this issue on all my projects :
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
* Where:
Script '/home/nunyalab/snap/flutter/common/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1151
here are my gradle files
buildscript {
ext.kotlin_version = '1.8.0'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.14'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
and
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 33
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.pikipikiafrica.pikirider"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName '1.0.0'
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:26.6.0')
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.mercadopago.android.px:checkout:4.+'
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The error code 1151 in Gradle in Flutter typically occurs when a conflict arises between different versions of the same library. This can happen when multiple packages depend on different versions of the same library. To resolve this error, you can try the following steps:
Run flutter clean command in terminal
Update Gradle to the latest version by updating the Gradle version in the gradle/wrapper/gradle-wrapper.properties file.
Manually resolve the dependency conflict by specifying the correct version of the library in your pubspec.yaml file.
If all else fails, try removing the conflicting library and re-adding it.
If none of the above steps solve the problem, it's best to consult the library's documentation or seek help from the library's support forums.

Error: No signature of method: build_6qwmin29m799y0qlbujwiy59g.android() is applicable for argument types while building Flutter project

I am trying to build my Flutter project but it gives me the 'no signature of method' error.
I had created and configured my project on a MacBook Air. I am now trying to build it on my Windows 11 machine.
App level build.gradle file:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.marinet"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
mutliDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.3'
}
The error:
Build file 'E:\Marinet\marinet-files\android\app\build.gradle' line: 29
A problem occurred evaluating project ':app'.
> No signature of method: build_6qwmin29m799y0qlbujwiy59g.android() is applicable for argument types: (build_6qwmin29m799y0qlbujwiy59g$_run_closure2) values: [build_6qwmin29m799y0qlbujwiy59g$_run_closure2#4239747b]
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'
at build_2052ezqw7g4scayly7h77uk88$_run_closure3.doCall(E:\Marinet\marinet-files\android\build.gradle:27)
at build_2052ezqw7g4scayly7h77uk88.run(E:\Marinet\marinet-files\android\build.gradle:26)
at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:116)
at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:42)
Caused by: groovy.lang.MissingMethodException: No signature of method: build_6qwmin29m799y0qlbujwiy59g.android() is applicable for argument types: (build_6qwmin29m799y0qlbujwiy59g$_run_closure2) values: [build_6qwmin29m799y0qlbujwiy59g$_run_closure2#4239747b]
at build_6qwmin29m799y0qlbujwiy59g.run(E:\Marinet\marinet-files\android\app\build.gradle:29)
Project level build.gradle file:
buildscript {
ext.kotlin_version = '1.7.0'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have tried all solutions given online but none worked for me. I changed my Kotlin version and renamed the GradleException method to FileNotFoundException, but it still gives me this error.
How can I solve this error?

FAILURE: Build failed with an exception. not that typicaly

I want to debug my code on my Device, but I got this problem.
I am using IntelliJ
Googled it, but doesn´t get a answer for this problem.
Don´t know where the Problem can be.
SDK Version of Android is 30. Don´t know what Version my Phone has.But it have Android 10
Exeption:
* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module #424d75a1
* 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 6s
Exception: Gradle task assembleDebug failed with exit code 1
build.gradle in android
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle in android/app
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion flutter.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "de.justlutz.todoapp"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
minSdkVersion 19
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
apply plugin: 'com.google.gms.google-services'
implementation platform('com.google.firebase:firebase-bom:29.0.3')
}
don´t know what the problem is here
solved!
first in gradle-wrapper.properties (root/android/gradle/wrapper)
i changed the distribuitonURL to distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip for a newer Version of gradle.
then I go into the build.gradle in the app path (root/android/app)
there I addded minSdkVersion 19 to defaultConfig (class android)
The last thing I do, was going into the build.gradle in android (root/android)
there I upgraded the andorid gradle dependency (in buildscript Class) to classpath 'com.android.tools.build:gradle:7.0.2' (the newest Version).
and in repositories in class buildscript and allprojects I added the google maven repository
maven {
url 'https://maven.google.com/'
name 'Google'}
Finaly I reloaded the gradle settings and all works fine.

FAILURE: Build failed with an exception. * Where: Build file 'D:\AProjects\flutter_app\android\app\build.gradle' line: 24

Hey I am trying to compile my flutter project on my real device, but this is the error or issue I am currently facing. Does anyone have a solution for this.
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\AProjects\flutter_app\android\app\build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> Plugin with id 'com.android.application' 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.
I am currently using latest version of flutter. And I am getting this error in my every project.
This is what I have in android\app\build.gradle:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.flutter_app"
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
& This is what I have in android\build.gradle :
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
You mixed up where you have to add apply plugin 'com.android.application'.
You added it in the wrong build gradle.
It should go in:
'D:\AProjects\snd_app\android\build.gradle'.
You will most likely have another error arise after fixing this, because of a switch also. Move those from android\build.gradle to android\app\build.gradle.
I had also face this problem, when i used to change kotlin version in /android/build.gradle to ext.kotlin_version = '1.7.0'
possible to have some additional {} or other in build.gradle file
in my case, I just missed some } to comment

Exception: The plugin firebase_admob could not be built due to the issue above

i have a problems
this bug appears when i add the plugin " firebase_admob: ^0.11.0+1" in pubspec.yaml
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:processDebugResources'.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
Android resource linking failed
/home/mohamed/.gradle/caches/transforms-2/files-2.1/804bb16bf16b5e91bc08a39b6997ce12/play-services-ads-lite-19.6.0/AndroidManifest.xml:27:5-38:15:
AAPT: error: unexpected element found in . 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 10s 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 firebase_admob...
Exception: The plugin firebase_admob could not be built due to the
issue above. Exited (sigterm)
enter image description here
gradle.proprieties
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
build.gradle :
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 29
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.admob10"
minSdkVersion 16
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
I too solved the issue by upgrading build gradle version.
previous setting in build.gradle file of project was:
classpath("com.android.tools.build:gradle:3.5.0")
current setting:
classpath("com.android.tools.build:gradle:3.5.4")
The issue was gone immediately. :)