Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter build apk doesn't work #40

Closed
MustafaAhmed20 opened this issue Jul 23, 2024 · 12 comments
Closed

Flutter build apk doesn't work #40

MustafaAhmed20 opened this issue Jul 23, 2024 · 12 comments
Labels
Android bug Something isn't working

Comments

@MustafaAhmed20
Copy link

When adding the package charset_converter: ^2.2.0 to a new flutter project. The flutter run works but flutter build apk doesn't

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':charset_converter:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.tasks.VerifyLibraryResourcesTask$Action
   > Android resource linking failed
     ERROR:D:\WorkSpace\mobile-flutter\wajen\test_project\build\charset_converter\intermediates\merged_res\release\values\values.xml:194: AAPT: error: re
source android:attr/lStar not found.

flutter doctor

[√] Flutter (Channel master, 3.24.0-1.0.pre.221, on Microsoft Windows [Version 10.0.19045.4651], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.38)
[√] Android Studio (version 2023.3)
[√] VS Code (version 1.91.1)
[√] Connected device (4 available)
[√] Network resources

• No issues found!

app/build.gradle

plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

android {
    namespace = "com.example.test_project"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8

    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.example.test_project"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = 23
        compileSdkVersion = 34
        targetSdk = 34

        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    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 = "../.."
}

settings.gradle

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.7.20" apply false

}

include ":app"

@pr0gramista pr0gramista added bug Something isn't working Android labels Jul 23, 2024
@pr0gramista
Copy link
Owner

Hey, thanks for the detailed report 💙
Unfortunately, I am about to travel for vacation, so I won't have time to take a look at this, but I'll make sure to prioritize it afterward. It would be really useful for me if you would provide a whole repository for me where you can reproduce the error. I predict this is something due to new versions, which might not have effect on my quite old setup.

If you find a workaround, or some details, please post it here - it would be super useful!
Sorry for the inconvenience.

@MustafaAhmed20
Copy link
Author

Hi there!
Happy vacation man, I hope you enjoy it.

I've created a repository for you with the sample code.
I will keep the project on my machine so if you need me to help in any way it will be my pleasure.

Cheers!

@MustafaAhmed20
Copy link
Author

Hi again!
I've noticed (understandably very late) that my Flutter channel is "Master" not Stable. And the current version is 3.24.0-1.0.pre.221.
After I switched back to stable version 3.22.3 everything seems fine!
So the problem may appear later when flutter team release 3.24.0 version, But for now everything seems OK.

I am terribly sorry for the inconvenience I've caused😌.
Cheers!

@dickverweij
Copy link

I have the same problem on 3.24.0

@Bilonik
Copy link

Bilonik commented Aug 9, 2024

Same problem with 3.24.0

@pr0gramista
Copy link
Owner

Thank you all for reporting the issue 💙

Seems like it was an easy fix, just bumping Android compile SDK version. Fix (provided via #41 🫡) is released as 2.2.1. Please upgrade and report if this was not enough.

@ilyasarafath
Copy link

Same issue
causing with "flutter_barcode_scanner" this plugin ,
Screenshot 2024-08-18 at 2 35 15 PM

@dickverweij
Copy link

@ilyasarafath see this for the solution

@pr0gramista
Copy link
Owner

Yep, you can override compileSdk for plugins that did not update.
Seems like this issue is resolved. Let me close it to avoid unnecessary comments.

Thanks 💙

@And96
Copy link

And96 commented Aug 26, 2024

Using: charset_converter: ^2.2.1

I got this error when Build APK
immagine

@And96
Copy link

And96 commented Aug 26, 2024

Upgrading build.gradle in Android directoty fixed the issue.

Full content of the file of my configuration:
https://pastebin.com/2AQ3rcgR

I added this part
`subprojects {
afterEvaluate { project ->
if (project.hasProperty("android")) {
project.android {
compileSdkVersion 34
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
//compileSdkVersion 34
}
}

        project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }
}

}`

I added the "subprojects" part to force charset_converter to use 1.8 version like other packages, it seems it use the old 1.7 when build your package or do not use sdk 34 by default. I am not sure. But it should be the compatibility issue. Correct me if I am wrong

@And96
Copy link

And96 commented Aug 26, 2024

Works perfectly now. With latest 3.24.1
If someone need all configuration files, I posted here
amake/flutter_charset_detector#9 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants