Could not find method compileSdkVersion() - flutter

I am trying to build an android app bundle release but am getting an error that says ''Could not find method compileSdkVersion() for arguments [21] on project ':app' of type org.gradle.api.Project.'' I have tried reading about it but all in vain. The terminal specifically says that line 36 has the issue. The code block is just above the compileOptions{} code block. I have tried putting the code block in braces but does not work. I also tried flutter clean then the
flutter build appbundle but the same error kept coming up.Here is how my android/app/build.gradle looks like
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"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android //this is the line 36 in my code
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.eduself"
// 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 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
apply plugin: 'com.google.gms.google-services'
Then this is the error my terminal throws after I run the flutter build appbundle.
PS C:\final> flutter build appbundle
Building with sound null safety
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\final\android\app\build.gradle' line: 36
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method compileSdkVersion() for arguments [21] on project ':app' of type org.gradle.api.Project.
* 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
Running Gradle task 'bundleRelease'... 9.1s
Gradle task bundleRelease failed with exit code 1
PS C:\final>

Use like this:
compileSdkVersion 21
without any parentheses, its because you used some features or packages that are not available for current compile sdk and need to upgrade
i suggest to read this answer

Related

Flutter Running error in mobile environment

When I try to run a project in a mobile environment, the following 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
1.I updated the Android studio using File->setting->update order.
2. I tried to apply the latest version of gradle. (I don't know if it worked.)
3. I updated the flutter pub.
This is my 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 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.example.app"
// 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
}
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"
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
If you have a problem with my questioning method or code, please feel free to tell me.

A problem occurred evaluating project ':app' . No signature of method

Recently, I studied using firebase in a flutter project. I followed the step but also got an error.
I searched and guess it is a app\build.gradle getting a problem. But also didn't know what the problem is.
No signature of method: build_5viubdggwtiixi0imz59oppqn.android() is applicable for argument types: (build_5viubdggwtiixi0imz59oppqn$_run_closure2) values: [build_5viubdggwtiixi0imz59oppqn$_run_closure2#71088475]
Here are the "relevant codes and error:
Error:
FAILURE: Build failed with an exception.
* Where:
Build file 'E:\firebase\android\app\build.gradle' line: 29
* What went wrong:
A problem occurred evaluating project ':app'.
> No signature of method: build_5viubdggwtiixi0imz59oppqn.android() is applicable for argument types: (build_5viubdggwtiixi0imz59oppqn$_run_closure2) values: [build_5viubdggwtiixi0imz59oppqn$_run_closure2#71088475]
* 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
Exception: Gradle task assembleDebug failed with exit code 1
Code:
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.google.gms.google-services'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
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.getx.app.db.firebaseApp"
// 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
MultiDexEnable 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'
}
#lousea, We get such kind of error when we use any undefined attribute in the gradle file.
In your case, in the default config, you have misspelled the multidex attribute. Just change MultiDexEnable to multiDexEnabled then it will work properly.
or just replace the defaultConfig from below
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.getx.app.db.firebaseApp"
// 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
multiDexEnabled true
}

No signature of method error after running flutter build appbundle

I'm trying to build an app bundle for a flutter project, and ran "flutter build appbundle." However, I get the following error:
FAILURE: Build failed with an exception.
Where:
Build file '/Users/noah/Documents/wildtrack_app/android/app/build.gradle' line: 36
What went wrong:
A problem occurred evaluating project ':app'.
No signature of method: build_5nfu1zfyvrlq5vvix8fftxpa7.android() is applicable for argument types: (build_5nfu1zfyvrlq5vvix8fftxpa7$_run_closure2) values: [build_5nfu1zfyvrlq5vvix8fftxpa7$_run_closure2#59991e25]
This is the android block of the build.gradle file (line 36, where it says the error was):
android {
compileSdkVersion 33
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.wildtrack.WildTrackAI"
minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName 1
manifestPlaceholders = ['appAuthRedirectScheme': 'com.example.wildtrackapp']
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
Try running flutter clean && flutter pub get after making sure that you are in the project's root directory
If this doesn't work, make sure you've the following code before your android { } block
Example :
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 33
...
}
And then run the flutter clean && flutter pub get again
If the issue still exists, check the path of the keystore.jks file

D8: Program type already present: com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream

I am getting the following errors in my flutter project and getting no clue how to resolve it
error:
D8: Program type already present: com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list:
Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream
* 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.
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'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.tajicEasy"
minSdkVersion 18
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled 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:2.0.1'
}
apply plugin: 'com.google.gms.google-services'
I have tried upgrading everything.
also have tried solving it through existing available related answers but nothing worked for me.
also checked that there are no two classes for protobuf.
tried deleting build, .gradle files
ok so I resolved this issue if anyone is facing the same then you have to check the following
All the dependencies are updated
multiDexEnabled true
if above doesn't solve the issues then check if any dependency is repeated if you can't find any repeated dependency then try removing the dependencies one by one then run the application again it will take time but your application will run once the error causing dependency is removed
Thanks, Hope that it is useful

flutter build gradle failed ':firebase_core:compileDebugJavaWithJavac'

I reset my pc recently, So the path of my project have changed, I don't know if it has to anything with this error.
I tried changing minSdkversion, compile SDK version, upgraded and downgraded all the firebase plugins, but no luck.
Here is my Complete error log
Launching lib\main.dart on Android SDK built for x86 in debug mode...
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-
1.0.3\android\src\main\java\io\flutter\plugins\firebase\core\FlutterFirebaseCorePlugin.java:92:
error: cannot find symbol
() -> {
^
symbol: method metafactory(Lookup,String,MethodType,MethodType,MethodHandle,MethodType)
location: interface LambdaMetafactory
Fatal Error: Unable to find method metafactory
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':firebase_core: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 32s
Here is my 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 new 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"
android {
compileSdkVersion 30
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.orangesprout.wlyk"
buildToolsVersion = "28.0.3"
minSdkVersion 23
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled 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 platform('com.google.firebase:firebase-bom:26.5.0')
implementation 'com.google.firebase:firebase-analytics'
}
apply plugin: 'com.google.gms.google-services'
From the error log it looks like theres a syntax error on line 92 at this location
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-1.0.3\android\src\main\java\io\flutter\plugins\firebase\core\FlutterFirebaseCorePlugin.java
So you could either go to that location and edit the file and fix the error or I would suggest you to
remove the
firebase_core: ^1.0.3
from your pubspec.yaml and also delete pubspec.lock then run
flutter packages get
and then re-add the
firebase_core: ^1.0.3
and then run
flutter packages get
so as to refetch the files related to this package