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

R8 error while building #251

Open
AhsanSarwar45 opened this issue Apr 12, 2024 · 3 comments
Open

R8 error while building #251

AhsanSarwar45 opened this issue Apr 12, 2024 · 3 comments
Labels
p:Android Android Home Screen Widgets

Comments

@AhsanSarwar45
Copy link

AhsanSarwar45 commented Apr 12, 2024

After installing this package, running my project gives the following error:

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

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeExtDexDevDebug'.
> Could not resolve all files for configuration ':app:devDebugRuntimeClasspath'.
   > 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-d
esugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexin
g-min-sdk=21, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status
=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: /home/ahsan/.gradle/caches/transf
orms-3/3b2f4188171f5e3ee96dda626b21c510/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.

* Get more help at https://help.gradle.org

BUILD FAILED in 12s
Running Gradle task 'assembleDevDebug'...                          13.3s

┌─ 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 assembleDevDebug failed with exit code 1

android/build.gradle:

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

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

ext.kotlin_version = "1.8.0"

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

android/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.4.2" apply false
    id "org.jetbrains.kotlin.android" version "1.8.0" apply false
}

include ":app"

android/src/build.gradle:

import com.android.build.OutputFile

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}


def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

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

android {
    // namespace "com.vicolo.chrono"

    compileSdkVersion 34
    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 {
        applicationId "com.vicolo.chrono"
        minSdkVersion 21
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()  
        versionName flutterVersionName
        multiDexEnabled true
    }
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile = file('release-key.jks')
            storePassword keystoreProperties['storePassword']        
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release

            minifyEnabled true
            shrinkResources true
        }
    }

    applicationVariants.all { variant ->
    variant.outputs.each { output ->
        // For each separate APK per architecture, set a unique version code as described here:
        // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
        def versionCodes = ["armeabi-v7a":1, "arm64-v8a":2, x86_64:3]
        def abi = output.getFilter(OutputFile.ABI)
        if (abi != null) {  // null for the universal-debug, universal-release variants
            output.versionCodeOverride =
                    variant.versionCode * 10 + versionCodes.get(abi)}
      }
    }

    flavorDimensions "app"

    productFlavors {
      prod {
        dimension "app"
        resValue "string", "app_name", "Chrono"
      }

      dev {
        dimension "app"
        resValue "string", "app_name", "Chrono Dev"
        // versionNameSuffix "-dev",
        applicationIdSuffix ".dev"
      }
    }

    dependenciesInfo {
        // Disables dependency metadata when building APKs.
        // This is for the signed .apk that we post to GitHub, so the dependency metadata isn't relevant.
        includeInApk false
        // Enable dependency metadata when building Android App Bundles.
        // This is for the Google Play Store, so we'll want the metadata.
        includeInBundle true
    }
}

flutter {
    source '../..'
}

Tried with kotlin 1.9.0 too, no luck.

@ABausG
Copy link
Owner

ABausG commented Jul 15, 2024

Does this error still persist?

@ABausG ABausG added the p:Android Android Home Screen Widgets label Jul 15, 2024
@hamishjohnson
Copy link

When I update my old project from Gradle 7.3.0 I'm receiving this issue.

However, it also gives errors on new projects, even though new projects are on Gradle 7.3.0

@v0ker
Copy link

v0ker commented Aug 26, 2024

You can try updating the minSdk version. After I set minSdk = 24, the error no longer occurred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p:Android Android Home Screen Widgets
Projects
None yet
Development

No branches or pull requests

4 participants