juliansteenbakker / mobile_scanner

A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS.
BSD 3-Clause "New" or "Revised" License
812 stars 475 forks source link

Build failed when updating to latest version #729

Closed mhd-ghaith-abtah closed 6 months ago

mhd-ghaith-abtah commented 1 year ago

when I updated to latest version "mobile_scanner 3.4.1" I got this error when trying to run my project: ERROR:D8: com.android.tools.r8.kotlin.H

FAILURE: Build failed with an exception.

BUILD FAILED in 27s

┌─ Flutter Fix ──────────────────────────────────────────────────────────────┐ │ [!] The shrinker may have failed to optimize the Java bytecode. │ │ To disable the shrinker, pass the --no-shrink flag to this command. │ │ To learn more, see: https://developer.android.com/studio/build/shrink-code │ └────────────────────────────────────────────────────────────────────────────┘ Exception: Gradle task assembleDebug failed with exit code 1

I have seen your build.gradle file and you are using ext.kotlin_version = '1.9.0' which is not widely supported yet. could please downgrade to 1.8.0 at least

this is my build.gradle file: buildscript { ext.kotlin_version = '1.8.0' repositories { google() mavenCentral() }

dependencies {
    classpath 'com.android.tools.build:gradle:7.4.2'
    // START: FlutterFire Configuration
    classpath 'com.google.gms:google-services:4.3.15'
    // END: FlutterFire Configuration
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

}

jgarciamccausland commented 1 year ago

Any updates or workarounds?

kgadva commented 1 year ago

For me it worked to update the Kotlin version in the build.gradle file to 1.9.0 ext.kotlin_version = '1.9.0'

jgarciamccausland commented 1 year ago

Yep, that worked in our environment as well. Thanks!

hatch01 commented 1 year ago

It work, but many other packages are incompatible with this Kotlin version, so I can't use it in my project. And I get some warning using it :

e: /var/home/eymeric/tmp/flutter_test/scan/build/mobile_scanner/.transforms/d8c2b2ffdd2df0218a0d2aa7e5cd360e/transformed/out/jars/classes.jar!/META-INF/mobile_scanner_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0.
e: /var/home/eymeric/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0.
e: /var/home/eymeric/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0.
e: /var/home/eymeric/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0.
e: /var/home/eymeric/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.9.0/cd65c21cfd1eec4d44ef09f9f52b6d9f8a720636/kotlin-stdlib-common-1.9.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0.
hatch01 commented 1 year ago

Any other workarounds?

sharsad commented 12 months ago

A problem occurred evaluating project ':app'.

Could not initialize class org.jetbrains.kotlin.gradle.plugin.KotlinGradleBuildServices

mazud21 commented 11 months ago

when I updated to latest version "mobile_scanner 3.4.1" I got this error when trying to run my project: ERROR:D8: com.android.tools.r8.kotlin.H

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:mergeExtDexDebug'.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Failed to transform kotlin-stdlib-1.9.0.jar (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.

Execution failed for DexingWithClasspathTransform: /Users/ghaithabtah/.gradle/caches/transforms-3/a0583c7606e960d1c6435c51b205f3f3/transformed/jetified-kotlin-stdlib-1.9.0.jar. Error while dexing.

  • 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 FAILED in 27s

┌─ Flutter Fix ──────────────────────────────────────────────────────────────┐ │ [!] The shrinker may have failed to optimize the Java bytecode. │ │ To disable the shrinker, pass the --no-shrink flag to this command. │ │ To learn more, see: https://developer.android.com/studio/build/shrink-code │ └────────────────────────────────────────────────────────────────────────────┘ Exception: Gradle task assembleDebug failed with exit code 1

I have seen your build.gradle file and you are using ext.kotlin_version = '1.9.0' which is not widely supported yet. could please downgrade to 1.8.0 at least

this is my build.gradle file: buildscript { ext.kotlin_version = '1.8.0' repositories { google() mavenCentral() }

dependencies {
    classpath 'com.android.tools.build:gradle:7.4.2'
    // START: FlutterFire Configuration
    classpath 'com.google.gms:google-services:4.3.15'
    // END: FlutterFire Configuration
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

}

save my day, thanks

thamaraSenanayake commented 11 months ago

try to update the minSdkVersion

vbuberen commented 11 months ago

It seems to me that the issue is in fact that to use Kotlin 1.9.x project needs to already be on Android Gradle Plugin 8. I have already discovered it in Plus Plugins and this is the reason why I am reverting Kotlin version back to 1.7.22 till AGP 8 is more adopted among Flutter projects.

Error comes from R8 in AGP older than 8.x not supporting Kotlin 1.9.x as it can be seen here: https://developer.android.com/build/kotlin-support

juliansteenbakker commented 11 months ago

Hi all, i'm testing if downgrading the version won't break anything. If not, then ill release a new version with downgraded kotlin version.

KolyaParadiuk commented 10 months ago

Hi! I had the same problem, but managed to run app. I added jcenter() in android/build.gradle in allprojects

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()

    }
}

use ext.kotlin_version = '1.9.0' and classpath 'com.android.tools.build:gradle:7.2.2'

with this configuration app runs without errors

donjordano commented 10 months ago

the only thing that worked for me was adding this to app/build.gradle

configurations.all { resolutionStrategy { eachDependency { if ((requested.group == "org.jetbrains.kotlin") && (requested.name.startsWith("kotlin-stdlib"))) { useVersion("1.7.10") } } } }

navaronbracke commented 10 months ago

@mhd-ghaith-abtah Are you still having this issue when using version 3.5.1? We recently did a downgrade to Kotlin 1.7.x due to an issue with Kotlin 1.9.x

thiagosoaress2 commented 10 months ago

Hi! I had the same problem, but managed to run app. I added jcenter() in android/build.gradle in allprojects

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()

    }
}

use ext.kotlin_version = '1.9.0' and classpath 'com.android.tools.build:gradle:7.2.2'

with this configuration app runs without errors

This worked for me. I was previosloy using classpath 'com.android.tools.build:gradle:7.4.2'

navaronbracke commented 10 months ago

@thiagosoaress2 I advise not using jcenter, as is was sunset a while ago: https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/

Is there a specific reason why you need Kotlin version 1.9.0 ? The plugin was downgraded back to Kotlin 1.7.x due to complaints from other users.

There shouldn't be an issue with the com.android.tools.build:gradle version. The plugin itself is using Gradle 8 even, which works fine on the example app.

Jacqqq commented 10 months ago

After long fight with gradle, eventually ended up with setup

kotlin 1.8.0 classpath 'com.android.tools.build:gradle:7.2.2' classpath 'com.google.gms:google-services:4.3.15' !

IwanPWK commented 10 months ago

delete folder .gradle, go to inside build, delete all folders, or just delete folder build, then setup like this kotlin 1.8.0, 1.9.0 whatever classpath 'com.android.tools.build:gradle:7.2.2' classpath 'com.google.gms:google-services:4.3.15'

just in case (optional) maybe you have to set up Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); runApp(const MyApp());

alexandrim0 commented 9 months ago

deleting of .grade and build solve problem even with kotlin 1.9.0 and gradle 8.1.0

adrianvintu commented 8 months ago

The following configuration worked for me when migrating to AGP8:

build.gradle

buildscript {
    ext.kotlin_version = '1.9.0'
    repositories {
        google()
        jcenter()
        maven { url 'https://developer.huawei.com/repo/' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.1.1'
        classpath 'com.google.gms:google-services:4.3.15'
        classpath 'com.google.firebase:perf-plugin:1.4.2'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.6'
        classpath 'com.huawei.agconnect:agcp:1.5.2.300'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
...

app\build.gradle

...
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
//apply plugin: 'com.huawei.agconnect'

android {
    // Conditional for compatibility with AGP <4.2.
    if (project.android.hasProperty("namespace")) {
      namespace 'my_namespace'
    }

    compileSdkVersion 34
...       

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#https://developer.android.com/studio/releases/gradle-plugin
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip

Forks (if required): https://github.com/adrianvintu/file_saver https://github.com/adrianvintu/flutter_statusbarcolor https://github.com/adrianvintu/hms-flutter-plugin

LuqmaanMohammed commented 8 months ago

Launching lib/main.dart on sdk gphone64 x86 64 in debug mode... Running Gradle task 'assembleDebug'... Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. ERROR:D8: com.android.tools.r8.kotlin.H

FAILURE: Build failed with an exception.

BUILD FAILED in 38s

┌─ Flutter Fix ──────────────────────────────────────────────────────────────┐ │ [!] The shrinker may have failed to optimize the Java bytecode. │ │ To disable the shrinker, pass the --no-shrink flag to this command. │ │ To learn more, see: https://developer.android.com/studio/build/shrink-code │ └────────────────────────────────────────────────────────────────────────────┘ Exception: Gradle task assembleDebug failed with exit code 1

this is the error and this is the build.gradle file 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 FileNotFoundException("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' }

buildscript { repositories { google() jcenter() }

dependencies {
    classpath 'com.android.tools.build:gradle:8.2.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0"
}

}

apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) }

android { compileSdkVersion 34 compileSdk flutter.compileSdkVersion ndkVersion '25.1.8937393'

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
    applicationId "com.pavlenko.Habo"
    minSdkVersion 21
    compileSdk 34
    targetSdkVersion 34
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled true
    ndk { abiFilters "arm64-v8a", "armeabi-v7a", "x86_64" }
}

signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['storePassword']
    }
}

buildTypes {
    release {
        signingConfig signingConfigs.release
    }
}

}

flutter { source '../..' }

dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.0" // ... other dependencies ... }

LuqmaanMohammed commented 8 months ago

please help

navaronbracke commented 8 months ago

The mobile_scanner example application runs fine with Kotlin 1.9.x, however, your combination of dependencies might not be compatible with Kotlin 1.9.x

Does it work if you switch to Kotlin 1.8.x ?

LuqmaanMohammed commented 8 months ago

No it doesn't work

navaronbracke commented 8 months ago

We are going to need the full gradle build log to see what the actual issue is. Could you open the native Android project and run a Gradle build with the --stacktrace and --info options? (--stacktrace and --debug might help too)

I also noticed, you are running Gradle 8, with Java 8. Could you ty to upgrade Java to Java 17? (see the example app for the Java 17 configuration)

LuqmaanMohammed commented 8 months ago

java.lang.RuntimeException: Cannot find service com.android.tools.idea.explainer.IssueExplainer (classloader=PluginClassLoader(plugin=PluginDescriptor(name=Android, id=org.jetbrains.android, descriptorPath=plugin.xml, path=/snap/android-studio/140/plugins/android, version=231.9392.1.2311.11076708, package=null, isBundled=true), packagePrefix=null, instanceId=117, state=active), client=null) at com.android.tools.idea.gradle.actions.ExplainSyncOrBuildOutput.(ExplainSyncOrBuildOutput.kt:71) at com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvokerImpl$MyListener$onStart$buildDescriptor$1.apply(GradleBuildInvokerImpl.kt:431) at com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvokerImpl$MyListener$onStart$buildDescriptor$1.apply(GradleBuildInvokerImpl.kt:429) at com.intellij.build.DefaultBuildDescriptor.lambda$getContextActions$0(DefaultBuildDescriptor.java:147) at com.intellij.util.containers.ContainerUtil.map(ContainerUtil.java:1951) at com.intellij.build.DefaultBuildDescriptor.getContextActions(DefaultBuildDescriptor.java:147) at com.intellij.build.BuildTreeConsoleView$1.invokePopup(BuildTreeConsoleView.java:228) at com.intellij.ui.PopupHandler.mousePressed(PopupHandler.java:47) at java.desktop/java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:288) at java.desktop/java.awt.Component.processMouseEvent(Component.java:6654) at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3385) at com.intellij.ui.treeStructure.Tree.processMouseEvent(Tree.java:424) at java.desktop/java.awt.Component.processEvent(Component.java:6422) at java.desktop/java.awt.Container.processEvent(Container.java:2266) at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5027) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4855) at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4954) at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4578) at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4522) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310) at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2808) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4855) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:791) at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:740) at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:734) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:764) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:762) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:761) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:667) at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.kt:615) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:570) at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:68) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:349) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:348) at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:787) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:348) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:343) at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:995) at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:113) at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:995) at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$4(IdeEventQueue.kt:343) at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:829) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:385) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

navaronbracke commented 8 months ago

The service com.android.tools.idea.explainer.IssueExplainer seems to be IntelliJ related?

Could you run Gradle directly, through Android Studio?

LuqmaanMohammed commented 8 months ago

Sir could you please run the repo on your pc and check it i am will be very grateful to you please i am a beginner so am not able to understand the errors and what to do please could you check it and see

navaronbracke commented 8 months ago

I will have a look at the Gradle error with the mobile_scanner example app.

endruuu commented 7 months ago

Might not be a good idea to everyone, but try to increase the minSdkVersion to 24 - that's all. No need to change the gradle or kotlin version.

Crucialjun commented 6 months ago

Might not be a good idea to everyone, but try to increase the minSdkVersion to 24 - that's all. No need to change the gradle or kotlin version.

This worked for me

ps9310 commented 6 months ago

Might not be a good idea to everyone, but try to increase the minSdkVersion to 24 - that's all. No need to change the gradle or kotlin version.

This worked for me

me too!

KallewMachado commented 6 months ago

Pode não ser uma boa ideia para todos, mas tente aumentar minSdkVersionpara 24 – isso é tudo. Não há necessidade de alterar a versão Gradle ou Kotlin.

This worked for me too

ziqq commented 6 months ago

This case work for me

minSdkVersion 23
plugins {
  id "dev.flutter.flutter-plugin-loader" version "1.0.0"
  id "com.android.application" version "7.2.2" apply false
  id "org.jetbrains.kotlin.android" version "1.9.22" apply false
  id "com.google.gms.google-services" version "4.3.15" apply false
}
saty-a commented 6 months ago

Might not be a good idea to everyone, but try to increase the minSdkVersion to 24 - that's all. No need to change the gradle or kotlin version.

Just updating the minSdkVersion from 21 to 23 worked for me. Thanks @endruuu.

MrCyjaneK commented 6 months ago

@saty-a's suggestion is great but in my case it increased app size by 3x (from 90mb to 280mb) which is somewhat unacceptable, but it did compile and run without problems.

yelyseiruban commented 6 months ago

inside android/build.gradle

buildscript { ext.kotlin_version = '1.9.22' repositories { google() mavenCentral() }

dependencies {
    classpath 'com.android.tools.build:gradle:7.2.2'
    // START: FlutterFire Configuration
    classpath 'com.google.gms:google-services:4.3.15'
    // END: FlutterFire Configuration
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

}

worked for me

navaronbracke commented 6 months ago

Since this issue seems to be resolved by updating the min SDK and or Kotlin version of the Android project, I'm going to close this issue.

aymendn commented 5 months ago

I had a similar problem with Flutter 3.19 and solved it with these versions:

buildscript {
    ext.kotlin_version = '1.9.0' // upgraded to kotlin 1.9
    repositories {
        google()
        mavenCentral()
        jcenter() // added this
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.2' // using 7.2.2
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.15'
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip # <== 7.6

Don't forget to run this command after changes

cd android
./gradlew clean build --no-build-cache
notandyvee commented 5 months ago

In case someone else runs into this issue, don't bump the minSdk to 24. That's likely wrong. Odds are you are running into this because you create a project prior to flutter 3.16. If thats the case, you need to update your build.gradle files using the new declerative plugins {} block. This must be updated manually. The link steps you through the process for the updates. Additionally, you will need to update AGP to at least 8.0+. That part I am not too confident in, but it's what was needed for my build to pass without changing the minSdk version.

sreeramsunkaraa commented 4 months ago

Updating minSDK to 24 works for me but I am wondering what changed between 23 and 24 that fixes this issue?

cartdropdata commented 2 months ago

Facing same issue here, below are the details please assist @navaronbracke - thanks

Flutter version : 3.22.0 Dart version : 3.4.0 Java version : 17 MacOS Sonoma 14.4.1 Apple M1 Pro

Below is android/build.gradle and android/app/build.gradle files

android/build.gradle :

buildscript {
    ext.kotlin_version = '1.8.0'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
        // START: FlutterFire Configuration
        classpath 'com.google.gms:google-services:4.3.15'
        // END: FlutterFire Configuration
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://repo.survicate.com' }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

android/app/build.gradle :

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
    id 'kotlin-android'
}

apply plugin: 'com.android.application'
// START: FlutterFire Configuration
apply plugin: 'com.google.gms.google-services'
// END: FlutterFire Configuration
apply plugin: 'kotlin-android'

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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "shop.cartdrop.cartdropapp"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
    namespace 'shop.cartdrop.cartdropapp'
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'
    implementation platform('com.google.firebase:firebase-bom:32.0.0')
    implementation 'com.google.firebase:firebase-analytics'
}
navaronbracke commented 2 months ago

@cartdropdata What specific error are you getting? To me this seems that your dependencies are outdated (either your Gradle version or some of your third party dependencies)

cartdropdata commented 2 months ago

@navaronbracke Below is the error :

Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
Running Gradle task 'assembleDebug'...
You are applying Flutter's app_plugin_loader Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply

You are applying Flutter's main Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply

ERROR:D8: com.android.tools.r8.kotlin.H
ERROR:D8: com.android.tools.r8.kotlin.H
ERROR:D8: com.android.tools.r8.kotlin.H
ERROR:D8: com.android.tools.r8.kotlin.H
ERROR:D8: com.android.tools.r8.kotlin.H
ERROR:D8: com.android.tools.r8.kotlin.H
ERROR:D8: com.android.tools.r8.kotlin.H
ERROR:D8: com.android.tools.r8.kotlin.H

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeExtDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform survicate-sdk-4.4.0.aar (com.survicate:survicate-sdk:4.4.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: /Users/manankhandelwal/.gradle/caches/transforms-3/34911487d5834dd2681f4357997d7a4f/transformed/jetified-survicate-sdk-4.4.0-runtime.jar.
         > Error while dexing.
   > Failed to transform play-services-measurement-api-21.6.1.aar (com.google.android.gms:play-services-measurement-api:21.6.1) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: /Users/manankhandelwal/.gradle/caches/transforms-3/cec91203b344314a49d0d325e3f994be/transformed/jetified-play-services-measurement-api-21.6.1-runtime.jar.
         > Error while dexing.
   > Failed to transform play-services-location-21.2.0.aar (com.google.android.gms:play-services-location:21.2.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: /Users/manankhandelwal/.gradle/caches/transforms-3/dcd64b519d925e3384ab1eafec6fdef9/transformed/jetified-play-services-location-21.2.0-runtime.jar.
         > Error while dexing.
   > Failed to transform kotlinx-coroutines-android-1.8.0.jar (org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.environment=standard-jvm, org.gradle.jvm.version=8, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=jvm}.
      > Execution failed for DexingWithClasspathTransform: /Users/manankhandelwal/.gradle/caches/transforms-3/e123dda2e3fbd8c8b8254144c7b40ddd/transformed/jetified-kotlinx-coroutines-android-1.8.0.jar.
         > Error while dexing.
   > Failed to transform kotlinx-coroutines-core-jvm-1.8.0.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.8.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=jvm}.
      > Execution failed for DexingWithClasspathTransform: /Users/manankhandelwal/.gradle/caches/transforms-3/867425e0fe1d2c78b8f42a94491417c1/transformed/jetified-kotlinx-coroutines-core-jvm-1.8.0.jar.
         > Error while dexing.
   > Failed to transform kotlinx-coroutines-play-services-1.8.0.jar (org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.8.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.environment=standard-jvm, org.gradle.jvm.version=8, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=jvm}.
      > Execution failed for DexingWithClasspathTransform: /Users/manankhandelwal/.gradle/caches/transforms-3/cb4d4e1f7689863dc237cfa69a971ec0/transformed/jetified-kotlinx-coroutines-play-services-1.8.0.jar.
         > Error while dexing.
   > Failed to transform okio-jvm-3.7.0.jar (com.squareup.okio:okio-jvm:3.7.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=jvm}.
      > Execution failed for DexingWithClasspathTransform: /Users/manankhandelwal/.gradle/caches/transforms-3/3d70257abaab750a4e813b59f665d275/transformed/jetified-okio-jvm-3.7.0.jar.
         > Error while dexing.
   > Failed to transform kotlin-stdlib-1.9.21.jar (org.jetbrains.kotlin:kotlin-stdlib:1.9.21) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.category=library, org.gradle.jvm.environment=standard-jvm, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=jvm}.
      > Execution failed for DexingWithClasspathTransform: /Users/manankhandelwal/.gradle/caches/transforms-3/d22df0169205642a93b2b231a205b02c/transformed/jetified-kotlin-stdlib-1.9.21.jar.
         > Error while dexing.

* 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 10s

┌─ Flutter Fix ──────────────────────────────────────────────────────────────┐
│ [!] The shrinker may have failed to optimize the Java bytecode.            │
│ To disable the shrinker, pass the `--no-shrink` flag to this command.      │
│ To learn more, see: https://developer.android.com/studio/build/shrink-code │
└────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1
navaronbracke commented 2 months ago

This indicates an issue with some of your other dependencies. Perhaps try cleaning your Gradle cache and try again.

Also, from what version of mobile_scanner are you upgrading?