1

I have been getting errors building apk for flutter. But the app works well while I run it.

I have tried so many fixes like migrating to androidX and upgrading my dependencies but none worked. I recently started getting this error after upgrading flutter. What could be the solution to this?

Error

FAILURE: Build completed with 2 failures.                                                                          

1: Task failed with an exception.                                                                                  
-----------                                                                                                        
* What went wrong:                                                                                                 
Execution failed for task ':shared_preferences:verifyReleaseResources'.                                            
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade                  
   > Android resource linking failed                                                                               
     /Users/apple/.gradle/caches/transforms-2/files-2.1/d45c258d5b0086b06365ac1a25df0442/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontVariationSettings not found.

     /Users/apple/.gradle/caches/transforms-2/files-2.1/d45c258d5b0086b06365ac1a25df0442/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/ttcIndex 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.
==============================================================================                                     

2: Task failed with an exception.                                                                                  
-----------                                                                                                        
* What went wrong:                                                                                                 
Execution failed for task ':path_provider:verifyReleaseResources'.                                                 
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade                  
   > Android resource linking failed                                                                               
     /Users/apple/.gradle/caches/transforms-2/files-2.1/d45c258d5b0086b06365ac1a25df0442/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontVariationSettings not found.

     /Users/apple/.gradle/caches/transforms-2/files-2.1/d45c258d5b0086b06365ac1a25df0442/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/ttcIndex 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.

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.miraclecentre.bnotion.ben.maf_mentor"
        minSdkVersion 16
        targetSdkVersion 29
        multiDexEnabled true
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    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'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
1
  • Please update the question with your flutter version. Get it with flutter doctor command Commented Feb 17, 2020 at 16:26

3 Answers 3

1

Try changing your targetSdkVersion to 28.
That's the only fix I've run across. But when I figure out why that is, I'll come back and update.

EDIT:

update your shared_pref version reference to the most recent one. After that's done run

flutter pub cache repair 
Sign up to request clarification or add additional context in comments.

Comments

0

try :

flutter clean

Wait for it to delete older iOS and Android build files.

Then run again:

flutter build apk

2 Comments

same error bro. please review my logCat error again. I updated it
seems like I got some issues with my dependencies but I don't know why. I run the app well and I have properly migrated to androidX too
0

Solved this by changing build.gradle file, Go to,

[project_folder]/external_package/flutter_plugin/[problem_causing_plugin_name]/android/build.gradle/

Change compileSdkVersion 27 to compileSdkVersion 28

then, run Flutter clean and Flutter pub get, and try to create release Apk.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.