Scarlet icon indicating copy to clipboard operation
Scarlet copied to clipboard

Runtime errors after adding Scarlet as dependency

Open daniel-abramov opened this issue 6 years ago • 4 comments

Not sure if it's an appropriate place to ask this, but it's always reproducible with Scarlet.

I created a simple empty proejct for Android in the latest Android Studio with Kotlin support. Just a simple hello world application. It worked fine, I only added some test code tp onCreate():

val text = "test string"
val newtext = text.replace("string", "replaced")

Then I simply added Scarlet as dependency as suggested in the README, after doing that the application crashes on android immediately when trying to work with strings (val text = "test string" produces a crash), telling that the java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/text/StringsKt;

If I remove Scarlet from dependencies, it starts working again. What's the problem with it?

buildscript {
    ext.kotlin_version = '1.3.11'
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    signingConfigs {
    }
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

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

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.1.0-alpha03'
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    implementation 'com.github.tinder:scarlet:0.1.7'
}

I may assume that the issue arises from the fact, that the library and my project use slightly different kotlin versions (they're different only in the patch version and should be compatible though), so I'm not sure if it is the problem.

Also there is a warning in Android Studio:

    /home/daniel/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.2.10/85fe1811f3e586d0cc53aba1394d8089f1862215/kotlin-stdlib-jdk8-1.2.10.jar (version 1.2)
    /home/daniel/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.0/683e04a4e7f17437d7e1390480f312e122e42e9e/kotlin-stdlib-jdk7-1.3.0.jar (version 1.3)
    /home/daniel/.gradle/caches/transforms-1/files-1.1/kotlin-reflect-1.3.0.jar/1763cf1efecf987258647674f6df6b16/jetified-kotlin-reflect-1.3.0.jar (version 1.3)
    /home/daniel/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.0/a134b0cfe9bb44f98b0b3e889cda07923eea9428/kotlin-stdlib-1.3.0.jar (version 1.3)
    /home/daniel/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.0/84a2e0288dc17cd64d692eb1e5e0de8cd5ff0846/kotlin-stdlib-common-1.3.0.jar (version 1.3)

Not sure where this jdk8 dependency (version 1.2) comes from.

daniel-abramov avatar Jan 25 '19 17:01 daniel-abramov

Hi @application-developer-DA, thanks for reporting! I have never experienced this before. Can you produce it in the demo app (by pointing its scarlet dependencies to jitpack)?

zhxnlai avatar Jan 30 '19 22:01 zhxnlai

Hi @zhxnlai , is this demo app compatible with Android Studio 3.3? I've just tried to open it and it gives me the following error:

Unable to get Gradle wrapper properties from:
/home/daniel/Development/Android/Scarlet/demo/gradle/wrapper/gradle-wrapper.properties

Would you like to recreate the wrapper using the latest supported Gradle version?

Click 'OK' to recreate files, or 'Cancel' to manually set the path of a local Gradle distribution.

Pressing 'OK' also does not help as then the compilation fails with the following error:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':demo'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

This did not happen with other projects I tried to open with Android Studio. Perhaps the problem is that the gradle.properties file is missing.

daniel-abramov avatar Feb 01 '19 16:02 daniel-abramov

@application-developer-DA i am not able to reproduce. It could be different kotlin version causing that. maybe try excluding kotlin stdlib from scarlet? do you mind setting up a demo project on github?

And regarding the demo app, i am guessing you were trying to open the build.gradle in demo directory? try open the root project's build.gradle.

aaronweihe avatar Feb 20 '19 23:02 aaronweihe

Yes, please: https://github.com/application-developer-DA/ScarletTestDemo

The first commit simply creates a new Android Studio project with an Empty Activity. The second commit just add "some action" (simply a Toast with some message) The third commit adds Scarlet dependency and some dummy activity (just replace part of the string).

After the third commit the whole thing crashes. Commenting the scarlet dependency out solves the issue. That's really looks very weird to me.

daniel-abramov avatar Feb 25 '19 15:02 daniel-abramov