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

Unhelpful error when buildPython autodetection fails #733

Closed
mhsmith opened this issue Oct 31, 2022 · 2 comments
Closed

Unhelpful error when buildPython autodetection fails #733

mhsmith opened this issue Oct 31, 2022 · 2 comments
Labels
Milestone

Comments

@mhsmith
Copy link
Member

mhsmith commented Oct 31, 2022

From https://stackoverflow.com/questions/74154889:


I'm getting a build failure when I try running code from a Flutter Chaquopy tutorial (https://pub.dev/packages/chaquopy). I'm getting the following build failure, but I don't understand what buildPython means, as I can't find it anywhere in the code.

Here is the build failure:

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':app:mergeDebugPythonSources' (type 'DefaultTask').
  - Property 'buildPython' doesn't have a configured value.

    Reason: This property isn't marked as optional and no value has been configured.

    Possible solutions:
      1. Assign a value to 'buildPython'.
      2. Mark property 'buildPython' as optional.

    Please refer to https://docs.gradle.org/7.4/userguide/validation_problems.html#value_not_set for more details about this problem.

* 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 47s
Exception: Gradle task assembleDebug failed with exit code 1

Here is my main build.gradle:

buildscript {
    ext.kotlin_version = '1.6.10'
    repositories {
        google()
        jcenter()
        maven { url "https://chaquo.com/maven" }
    }

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

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

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

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

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

android {
    compileSdkVersion 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 "com.example.untitled4"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
        }
    }

    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 '../..'
}

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

The Flutter code was copied directly from the tutorial, where the buttons were updated from flat buttons to text buttons.

@mhsmith mhsmith added the bug label Oct 31, 2022
@mhsmith mhsmith added this to the 13.1 milestone Oct 31, 2022
@mhsmith
Copy link
Member Author

mhsmith commented Nov 21, 2022

This is probably caused by the detection process failing to find any Python at all, and assigning the property as null. The buildPython detection changed a lot between Chaquopy versions 12 and 13, but this scenario may be a gap in our testing, so the issue probably still exists.

Related: #752.

@mhsmith
Copy link
Member Author

mhsmith commented Dec 29, 2022

The Gradle documentation doesn't make this obvious, but any input property that can have a null value must be marked as optional, otherwise null values will cause this error when the task tries to run.

We had a test for a missing buildPython with the generatePythonRequirements task, but not for the other two tasks that used it (mergePythonSources and generatePythonProxies). The requirements task happens to be the first of the three to run, so that concealed the fact that the sources task was missing the optional marker.

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

No branches or pull requests

1 participant