ScerIO / packages.flutter

šŸ‘Øā€šŸ’» Plugins and packages for Flutter framework
https://pub.dev/publishers/serge.software/packages
MIT License
462 stars 456 forks source link

Execution failed for task ':native_pdf_renderer:compileDebugKotlin'. #341

Open hydev777 opened 2 years ago

hydev777 commented 2 years ago

I upgraded flutter from version 2 to 3, now the project is unable to build in Android due to an error related to native_pdf_renderer, the specific error shown is this one:

e: C:\flutter\.pub-cache\hosted\pub.dartlang.org\native_pdf_renderer-4.0.1\android\src\main\kotlin\io\scer\native_pdf_renderer\NativePdfRendererPlugin.kt: (124, 29): Type mismatch: inferred type is String? but String was expected
e: C:\flutter\.pub-cache\hosted\pub.dartlang.org\native_pdf_renderer-4.0.1\android\src\main\kotlin\io\scer\native_pdf_renderer\NativePdfRendererPlugin.kt: (138, 25): Type mismatch: inferred type is String? but String was expected

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':native_pdf_renderer:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

Here my android configuration:

android\build.gradle

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

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

task clean(type: Delete) {
    delete rootProject.buildDir
}

app\build.gradle

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 plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {

    compileSdkVersion 33
    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 "com.example.project"
        minSdkVersion 20
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    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
            ndk {
                abiFilters 'armeabi-v7a','arm64-v8a','x86_64', 'x86'
            }
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip

flutter doctor:

[āˆš] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Version 10.0.19044.1889], locale en-US)
[āˆš] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[āˆš] Chrome - develop for the web
[āˆš] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.5)
[āˆš] Android Studio (version 2021.1)
[āˆš] Android Studio (version 2021.2)
[āˆš] VS Code (version 1.66.0)
[āˆš] Connected device (4 available)
[āˆš] HTTP Host Availability
hydev777 commented 2 years ago

Solution in https://github.com/ScerIO/packages.flutter/issues/298