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

jsonpickle and Chaquopy - One project works well, but the other is fail. #276

Closed
valiantwarrior opened this issue May 2, 2020 · 3 comments
Closed
Labels

Comments

@valiantwarrior
Copy link

@valiantwarrior valiantwarrior commented May 2, 2020

Hi ! I'm trying to import 'jsonpickle', but there are some issues.

At my experimental project, which is for testing chaquopy and jsonpickle, it does not show error.

But, in my original project, it shows error.

Experimental project's gradle script is like this -

apply plugin: 'com.android.application'

apply plugin: 'com.chaquo.python'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "kr.pocoach.chaquopytest"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        python {
            buildPython "C:/Users/W/AppData/Local/Programs/Python/Python37/python.exe"
            pip {
                install "jsonpickle"
            }
        }
        sourceSets {
            main {
                python {
                   srcDirs = ["src/main/python"]
                }
            }
        }
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

And, python code is like this
prebuild.py

import jsonpickle def helloworld() : return "hello world"

When I import this module in Android,
val python = Python.getInstance()
val pythonFile = python.getModule("prebuild")
val helloWorldString = pythonFile.callAttr("helloworld")

It works well!


And, original project's gradle script is here.

apply plugin: 'com.android.application'

apply plugin: 'com.chaquo.python'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "kr.pocoach.bal_android"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"


        python {
            buildPython "C:/Users/W/AppData/Local/Programs/Python/Python37/python.exe"
            pip {
                install "jsonpickle"
            }
        }

        sourceSets {
            main {
                python {
                    srcDirs = ["src/main/python"]
                }
            }
        }


        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    dataBinding {
        enabled = true
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
    implementation 'androidx.navigation:navigation-fragment:2.0.0'
    implementation 'androidx.navigation:navigation-ui:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'

    implementation "androidx.room:room-runtime:$room_version"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    kapt "androidx.room:room-compiler:$room_version"
    implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"

    // Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version"

    implementation "javax.xml.bind:jaxb-api:2.3.0"
}

And tried same with experimental project, it shows error. Logcat says,

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: kr.pocoach.bal_android, PID: 3968
    java.lang.RuntimeException: Unable to start activity ComponentInfo{kr.pocoach.bal_android/kr.pocoach.bal_android.SplashActivity}: com.chaquo.python.PyException: AttributeError: 'Context' object has no attribute 'pattern'
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: com.chaquo.python.PyException: AttributeError: 'Context' object has no attribute 'pattern'
        at <python>.importlib.metadata.find_distributions(metadata.py:400)
        at <python>.importlib_metadata.from_name(__init__.py:200)
        at <python>.importlib_metadata.distribution(__init__.py:537)
        at <python>.importlib_metadata.version(__init__.py:564)
        at <python>.importlib_metadata.<module>(__init__.py:602)
        at <python>.java.chaquopy.import_override(import.pxi:26)
        at <python>.jsonpickle.version.<module>(version.py:2)
        at <python>.java.chaquopy.import_override(import.pxi:26)
        at <python>.jsonpickle.<module>(__init__.py:64)
        at <python>.java.chaquopy.import_override(import.pxi:26)
        at <python>.prebuild.<module>(**prebuild.py:5**)
        at <python>.importlib._bootstrap._call_with_frames_removed(<frozen importlib._bootstrap>:219)
        at <python>.importlib._bootstrap_external.exec_module(<frozen importlib._bootstrap_external>:783)
        at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:671)
        at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:975)
        at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:991)
        at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:1014)
        at <python>.importlib.import_module(__init__.py:127)
        at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModule(chaquopy_java.pyx:153)
        at com.chaquo.python.Python.getModule(Native Method)
        at kr.pocoach.bal_android.SplashActivity.onCreate(SplashActivity.kt:39)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

Where, prebuild.py:5 is import jsonpickle

I can't figure out why this is happen... I'll waiting for your response. Thank you.

@mhsmith
Copy link
Member

@mhsmith mhsmith commented May 3, 2020

Thanks for the report. Are your two projects using the same version of Chaquopy? It looks like this bug occurs in version 7.0.2, but not in version 6.3.0.

We'll fix this in the next version of Chaquopy. Meanwhile, try downgrading to version 6.3.0.

Related: #198

@valiantwarrior
Copy link
Author

@valiantwarrior valiantwarrior commented May 4, 2020

Both projects using the same version of Chaquopy - 7.0.2

I really wondering why this situation happens... same version but one is error...?

Meanwhile, as you commented, I tried 6.3.0 on my original projects, it works well!

Thank you for your comment!

+) It was first time to open the issue on github, sorry for bad-looking code attachment and thank you for your edit!

@mhsmith mhsmith added the bug label May 6, 2020
@mhsmith
Copy link
Member

@mhsmith mhsmith commented May 11, 2020

This issue is fixed in Chaquopy version 7.0.3.

@mhsmith mhsmith closed this as completed May 11, 2020
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

2 participants