I am building a basic Calculator app in Android Studio using Kotlin and Jetpack Commpose. for evaluating the expression string, I want to use the exp4j library.
To use it, I added implementation 'net.objecthunter:exp4j:0.4.9'
in my app level gradle file in the dependencies section.
Screenshot of the dependencies section
Now, when I sync my project, the compiler throws the error Unexpected tokens (use ';' to separate expressions on the same line)
when there is no apparent error in the syntax of the line.
This is the whole error:
e: file:///home/-----/AndroidStudioProjects/BasicCalculator/app/build.gradle.kts:54:20: Unexpected tokens (use ';' to separate expressions on the same line)
I am using Manjaro OS, with Gnome DE.
Android Studio version is
Android Studio Koala Feature Drop | 2024.1.2 Patch 1
Build #AI-241.19072.14.2412.12360217, built on September 12, 2024
Runtime version: 17.0.11+0-17.0.11b1207.24-11852314 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 6.9.12-3-manjaro
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 8
Registry:
ide.experimental.ui=true
Current Desktop: GNOME
What am I doing wrong? please help.
I tried Clean and rebuild, invalidating caches and updating Android Studio to the latest version, but nothing seems to work
Ayush Yadav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
My guess is that the file that the screenshot is from is named build.gradle.kts
. This means that you are writing Gradle instructions in Kotlin syntax.
I added implementation ‘net.objecthunter:exp4j:0.4.9’ in my app level gradle file in the dependencies section.
If you were editing build.gradle
, using Groovy syntax, that would have been fine. Groovy supports single-quoted string constants, but Kotlin does not.
Replace implementation 'net.objecthunter:exp4j:0.4.9'
with implementation("net.objecthunter:exp4j:0.4.9")
, to use double-quotes rather than single-quotes as the delimiters for your string constant.
Note that net.objecthunter:exp4j
has not been updated in about seven years, suggesting that it is no longer being maintained. Please be careful about using unmaintained libraries, as they may contain security bugs, compatibility issues, etc.
2