0

I added a library project which is provided as a maven package to my Android app. However this library's one of methods causes an error on devices lower than Android 6.0 (above 7.0 devices there's no error).

 Process: com.myapp.app.debug, PID: 2829
    java.lang.NoSuchMethodError: java.io.BufferedReader.lines
        at zemberek.core.text.TextIO.loadLinesFromResource(TextIO.java:103)
        at zemberek.core.text.TextIO.loadLinesFromResource(TextIO.java:79)
        at zemberek.core.turkish.hyphenation.TurkishSyllableExtractor.<clinit>(TurkishSyllableExtractor.java:34)
        at zemberek.morphology.analysis.tr.PronunciationGuesser.<clinit>(PronunciationGuesser.java:104)
        at zemberek.morphology.lexicon.tr.TurkishDictionaryLoader$TextLexiconProcessor.<init>(TurkishDictionaryLoader.java:302)
        at zemberek.morphology.lexicon.tr.TurkishDictionaryLoader.load(TurkishDictionaryLoader.java:103)
        at zemberek.morphology.lexicon.RootLexicon$Builder.addDictionaryLines(RootLexicon.java:247)
        at com.myapp.app.LugatDosyaIslemleri.lambda$initNLPWordAnalyzer$0$myapp-app-LugatDosyaIslemleri(LugatDosyaIslemleri.java:82)
        at com.myapp.app.LugatDosyaIslemleri$$ExternalSyntheticLambda0.run(D8$$SyntheticClass)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:841)

I use Gradle version 7.3.3:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip

My main build.gradle file uses Android gradle plugin 7.2.2:

classpath 'com.android.tools.build:gradle:7.2.2'

In my app's build.gradle file I declared to use Java 8:

    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }

and I added the dependency like:

implementation group: 'zemberek-nlp', name: 'zemberek-morphology', version: '0.17.1'

Although I use Java 8 in my project, how is it possible not finding BufferedReader's lines() method and why does it only happen on devices below Android 6.0?

Thanks in advance.

alierdogan7
  • 600
  • 7
  • 14
  • 3
    If I read this here correctly, Android 6 means Java 7. The fact that you build against Java 8 doesn't mean that the Java runtime within Android 6 supports Java 8 APIs: https://stackoverflow.com/questions/54129834/which-android-versions-run-which-java-versions – GhostCat Aug 15 '22 at 13:44
  • 1
    You have to understand that your build setup "working" doesn't mean the env you are running the app on some specific android version will work. – GhostCat Aug 15 '22 at 13:45
  • 1
    Java8 was only added in 6.0. Below that, the framework doesn't have those functions in it. So that library can't be used below 6.0. However only 3.8% of all devices worldwide don't support 6.0 or higher right now, and its dropping all the time. If your target market is the US or Europe, its far less than 1%. Given the number of incompatibilities and problems that old devices will cause you, I'd highly suggest dropping them. In fact if I was writing a new app I'd be looking at supporting only 24+ or 26+, which would still give me 90% of the world market. – Gabe Sechan Aug 15 '22 at 14:39
  • Thanks for comments. It means that I should avoid using that library under 6.0 devices with an additional SDK if-check. – alierdogan7 Aug 15 '22 at 15:30

1 Answers1

1

enter image description here

After I checked via Android Studio, it says this method requires at least API level 24. Extra information is here. Therefore, I solved my problem by putting an extra if statement checking API level and avoiding the use of that method.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
   Stream<String> lines = bufferReader.lines();
} else {
   // do a workaround...
}
alierdogan7
  • 600
  • 7
  • 14