Home > OS >  Flutter android build fails with "Execution failed for task ':app:processReleaseResources&
Flutter android build fails with "Execution failed for task ':app:processReleaseResources&

Time:10-18

I am building a flutter app for android.

I updated the gradle build tool version from...

classpath 'com.android.tools.build:gradle:3.5.0'

To

classpath 'com.android.tools.build:gradle:4.1.3'

Now I am getting the build error...

Execution failed for task ':app:processReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     /home/user/src/myapp/build/app/intermediates/packaged_manifests/release/AndroidManifest.xml:34: AAPT: error: attribute android:usesPermissionFlags not found.

My build.gradle is as follows...

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.5'

    }
}

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
}

My 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 plugin: 'com.google.gms.google-services'  // Google Services plugin
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.me.myapp"
        minSdkVersion 21
        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"
    implementation 'com.google.firebase:firebase-analytics:17.2.2'
}

My gradle-wrapper.properties is as follows...

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-all.zip

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="tenera_provision"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

CodePudding user response:

check build.gradle in android/app

compileSdkVersion 30 minSdkVersion 16 targetSdkVersion 30

If this doesn't fix then probably you are missing a permission in android manifest in android/app/src/main/AndroidManifest.xml

CodePudding user response:

The error message generally comes from AAPT2.
As one can see, this attribute exists since API level 17.

For debug purposes, the merged AndroidManifest.xml @line 34 would rather be interesting, because the question where android:usesPermissionFlags even comes from, still remains, since the AndroidManifest.xml within module :app doesn't have this line and the merged version needs to obtain it from somewhere - which can only be another one module or some AAR library.

buildToolsVersion "30.0.3" should work, but since nothing else had been declared, this still should be something alike ...nevertheless the version of Android Studio (archive) also plays a role (it needs to match the version of the Gradle plugin, which is 4.1.3, with Gradle 4.4)... or for the current "Arctic Fox", this would be 7.0.3, with Gradle 7.2 (you are building a legacy project).

aapt2 version should return:

Android Asset Packaging Tool (aapt) 2.19-6966805

And this would be the table with the versions to use.
There's actually also a small chance Gradle is too new.


And by the way... I can even proof that it WAS an assumption (besides the :clean task usually resides in the root build.gradle and not the module build.gradle, which is a potential issue):

task clean(type: Delete) {
    delete rootProject.buildDir
}

This states, that ./build is being deleted, but not ./app/build. I'd even go further and not only delete ./build, but also ~/.gradle/cache. And if there should be further Java/Kotlin modules present, make sure that not one of them is being built with an outdated buildToolsVersion.

When keeping it within the module build.gradle, it should remove them all:

task clean(type: Delete) {
    delete rootProject.buildDir
    delete project.buildDir
}
  • Related