0

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>
6
  • Hi, did you look at this /home/user/src/myapp/build/app/intermediates/packaged_manifests/release/AndroidManifest.xml:34: AAPT: error: attribute android:usesPermissionFlags not found. Commented Oct 15, 2021 at 0:55
  • Please post your Android Manifest also Commented Oct 15, 2021 at 9:49
  • What kind of flutter pub library did you use? Commented Oct 18, 2021 at 21:03
  • I've seen that even comments in Manifest.xml can cause an error to aapt. Commented Oct 19, 2021 at 5:54
  • @Scorb did you try this by adding this line to gradle.properties.org.gradle.jvmargs=-Xmx4608m Commented Oct 21, 2021 at 23:48

4 Answers 4

5
+200

Adjust your android/app/build.gradle so that your app compiles against the latest Android SDK:

android {
  compileSdkVersion 31
}

You don't need to adjust targetSdkVersion just yet.

usesPermissionFlags was added recently and some of your plugins may already support it.

https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location has all the details.

Sign up to request clarification or add additional context in comments.

Comments

0

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

3 Comments

I update initial post with me app/build.gradle. I tried changing the sdk version to 30 and the error persisted. Not sure what permissions I could be missing in AndroidManifest.xml.
You can try adding the internet permission like this in android/app/src/main/AndroidManifest.xml <manifest xlmns:android...> ... <uses-permission android:name="android.permission.INTERNET" /> <application ... </manifest>
Alternatively, you can create a new project with the same package id and copy lib, assets, pubspec.yaml file. Edit the manifest, build.gradle and if you are doing iOS then edit pod file and info.plist too depending on the packages that you used. Add GoogleServices.json and GoogleServicesInfo.plist. That should work.
0

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
}

4 Comments

I already did a clean on the project which deletes the build directory.
It seems you didn't read the answer - and your assumptions might be wrong. If clicking some button would suffice in all cases, I probably would have written "click the button". And most likely the AAPT2 you are using is just hopelessly outdated, when it doesn't know about API level 17 ...we're at 30 meanwhile.
Which assumptions are wrong? That running a clean does not remove the build directory? Because running a clean does remove the build directory. Is there any other action you are suggesting here? I read you answer.....it just does not make much sense.
@Scorb Only because it doesn't make sense to you doesn't mean it does make sense. Posting a bounty of 400 reputation for such a minor issue also makes no sense to me ...have explained it in more detail, but nevertheless I'd stick with my answer, because there's nothing left what it could be.
0

If you are upgrading your gradle build tools to a higher level then you also need to upgrade the wrapper to some stable version from the android/ gradle/wrapper/gradle-wrapper.properties. Example if you update tools to classpath 'com.android.tools.build:gradle:4.2.1' and the wrapper version to 6.8.1. then the app should build.

Your compile and targeted sdk's are absolutely fine. In case the flag issue persists add this into your manifest

    <uses-permission
    android:name="android.permission.BLUETOOTH_SCAN"
    android:usesPermissionFlags="neverForLocation" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.