pr0gramista / charset_converter

Flutter platform charset converter
BSD 3-Clause "New" or "Revised" License
33 stars 22 forks source link

Flutter build apk doesn't work #40

Closed MustafaAhmed20 closed 3 months ago

MustafaAhmed20 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 3 months ago

I have the same problem on 3.24.0

Bilonik commented 3 months ago

Same problem with 3.24.0

pr0gramista commented 3 months ago

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 commented 3 months ago

Same issue causing with "flutter_barcode_scanner" this plugin ,

Screenshot 2024-08-18 at 2 35 15 PM
dickverweij commented 3 months ago

@ilyasarafath see this for the solution

pr0gramista commented 3 months ago

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 commented 3 months ago

Using: charset_converter: ^2.2.1

I got this error when Build APK immagine

And96 commented 3 months ago

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 commented 3 months ago

Works perfectly now. With latest 3.24.1 If someone need all configuration files, I posted here https://github.com/amake/flutter_charset_detector/issues/9#issuecomment-2309795010