Search code examples
fluttergradlebundlereleasesignature

Flutter: error Plugin with id 'com.android.application' not found


I am trying to make my first Flutter Android bundle and it is not going well....

I created my project using Android Studio, then made my app. I now need to get it setup on firebase app deployment. Creating the ios IPA was super easy. Now times to make the Android bundle :(

Edit: Initial error from Android Studio was caused by not using the right build appbundle commande. it is giving me the same error are the flutter build appbundle.

I try the terminal command "flutter build appbundle" in the terminal. And I got the same error "Error Plugin with id 'com.android.application' not found"

Error from terminal

 💪 Building with sound null safety 💪


FAILURE: Build failed with an exception.

* Where:
Build file '/Users/user/AndroidStudioProjects/PrjName/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.

* Get more help at https://help.gradle.org

BUILD FAILED in 345ms
Running Gradle task 'bundleRelease'...                           1 037ms
Gradle task bundleRelease failed with exit code 1

EDIT: Below is my build.gradel 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 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'
// START: FlutterFire Configuration
apply plugin: 'com.google.gms.google-services'
// END: FlutterFire Configuration
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 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 "***********************"
        // 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"
}

I checked google and here for an answer and found outdated "answers" that don't work where 98% are related to regular android project and not flutter project. Tried some but did not change any thing.

oh and Android studio was re-installed 2 weeks ago. And I deleted my ~/.gradle and also did not change a thing. I did ask ./gradlew to update and this did not change any thing. Tried to install gradle from hombrew but seams that flutter and Android Studio don't care about letting me change the gradle directory.

So what can I do?

found a related question but no answer sadly. :(


Solution

  • Found my problem. it was stupid really. my root build.gradle was empty. Somehow adding firebase using the firebase tools accidently clear all content from the root build.gradle.

    I had to create a new flutter project to copy the content to my current project. works now.