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

App Don't Run in android #371

Open
hugolemos11 opened this issue Jan 8, 2025 · 2 comments
Open

App Don't Run in android #371

hugolemos11 opened this issue Jan 8, 2025 · 2 comments

Comments

@hugolemos11
Copy link

Add flutter_barcode_scanner: ^2.0.0 to pubspec.yaml

Run the app

this log appears: "FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':flutter_barcode_scanner'.

Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

 If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.
  • 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.
Get more help at https://help.gradle.org.

BUILD FAILED in 1s
Error: Gradle task assembleDebug failed with exit code 1"

@tapaswi-v-s
Copy link

Adding the following line in the android block of package's android\build.gradle solved the error for me

namespace "com.amolg.flutterbarcodescanner"

@dwinugdev
Copy link

Add flutter_barcode_scanner: ^2.0.0 to pubspec.yaml

Run the app

this log appears: "FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':flutter_barcode_scanner'.

Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

 If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.
  • 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.
Get more help at https://help.gradle.org.

BUILD FAILED in 1s Error: Gradle task assembleDebug failed with exit code 1"

Got the same problem, recently the error occured when running
flutter build apk --release

Running on Mac os 15.1.1 (24B91) and Flutter Version below

❯ flutter --version
Flutter 3.27.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 17025dd882 (4 weeks ago) • 2024-12-17 03:23:09 +0900
Engine • revision cb4b5fff73
Tools • Dart 3.6.0 • DevTools 2.40.2

My solutions :
Check the Dependencies in pubspec.yaml Open the pubspec.yaml file in your Flutter project and make sure flutter_barcode_scanner is listed as a dependency:

dependencies:
  flutter:
    sdk: flutter
  flutter_barcode_scanner: ^2.0.0  # Or another version

Find the flutter_barcode_scanner Folder in ~/.pub-cache The packages downloaded by Flutter are usually stored in the pub-cache folder in your home directory. You can find it at the following path:

Mac/Linux: ~/.pub-cache/hosted/pub.dev/flutter_barcode_scanner
Windows: C:\Users\<YourUsername>\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_barcode_scanner

Inside this folder, you'll find the directory containing the source code of the package, including the build.gradle Android file.

Navigate to the Android Folder If you need to add or change the namespace configuration, navigate to the android/ folder inside the flutter_barcode_scanner package directory. The folder structure usually looks like this:

~/.pub-cache/hosted/pub.dev/flutter_barcode_scanner/<version>/android/

In the android/ folder, you will find the build.gradle file that you need to modify (add namespace "com.amolg.flutterbarcodescanner" inside the android block).

this is the build.gradle flutter_barcode_scanner version 2.0.0

group 'com.amolg.flutterbarcodescanner'
version '1.0-SNAPSHOT'

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'
    }
}

rootProject.allprojects {
    repositories {
        google()
        jcenter()
    }
}

apply plugin: 'com.android.library'

android {
    namespace 'com.amolg.flutterbarcodescanner' // added this line and change compileSdkVersion to 35 for my project
    compileSdkVersion 35

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 35
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    lintOptions {
        disable 'InvalidPackage'
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'com.google.android.gms:play-services-vision:20.1.3'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants