Can someone point me in the right direction?
# gradle
k
Can someone point me in the right direction?
s
sure thing.
first things first.
you probably don't need to use the buildscript block in the root
unless that's something for android that I'm unaware of.
k
okay. I was just trying to convert what android studio had provided with the groovy gradle files
s
you can probably reduce the root gradle to something like this.
hmm looks like you might need the buildscript.
anyway
Copy code
allprojects {
    repositories {
        google()
        jcenter()
    }
    ext {
        set("kotlinVersion", "1.3.21")
    }
}

tasks.register("clean", Delete::class ) {
    delete(rootProject.buildDir)
}
after the buildscript to get rid of your error.
also, line 30 of the module, you don't need to specify
project
you can just call
extra["kotlinVersion"]
k
is it
ext
or
extra
?
I've read conflicting information about that
s
in kotlin it's
extra
, but the extension method is
ext
.
confusing I know.
k
okay
s
so in your allprojects block use
ext
and then when retrieving it use
extra
I've heard it's better.
k
okay, one thing at a time
still unable to resolve
kotlinVersion
from extra after moving
ext
to
allProjects
s
hmm.
is this a
build.gradle.kts
or
build.gradle
?
k
kts
message has been deleted
s
did you change anything that AS generated?
k
AS generated
settings.gradle
and two
build.gradle
files
I changes all three of those
to
.kts
s
gotcha. what does your
settings.gradle
look like?
k
Copy code
rootProject.buildFileName = "build.gradle.kts"

include(":app")
s
i think it's actually faililng to find the kotlinVersion in the buildscript.
just hard code it there for now.
k
hard coded the kotlin version for now. Still dealing with symbol resolution issues in the build. This is the output when I try to run a build now.
Copy code
Picked up _JAVA_OPTIONS: -Djava.io.tmpdir=/home/kevin/.var/app/com.google.AndroidStudio/cache/tmp/
warning: default scripting plugin is disabled: The provided plugin org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar is not compatible with this version of compiler
build.gradle.kts:3:1: error: unresolved reference: buildscript
buildscript {
^
build.gradle.kts:4:5: error: unresolved reference: repositories
    repositories {
    ^
build.gradle.kts:5:9: error: unresolved reference: google
        google()
        ^
build.gradle.kts:6:9: error: unresolved reference: jcenter
        jcenter()
        ^
build.gradle.kts:9:5: error: unresolved reference: dependencies
    dependencies {
    ^
build.gradle.kts:10:9: error: unresolved reference: classpath
        classpath("com.android.tools.build:gradle:3.4.0")
        ^
build.gradle.kts:11:9: error: unresolved reference: classpath
        classpath(kotlin("gradle-plugin", version = "1.3.21"))
        ^
build.gradle.kts:11:19: error: expression 'kotlin' cannot be invoked as a function. The function 'invoke()' is not found
        classpath(kotlin("gradle-plugin", version = "1.3.21"))
                  ^
build.gradle.kts:11:19: error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public val <T : Any> Class<???>.kotlin: KClass<???> defined in kotlin.jvm
        classpath(kotlin("gradle-plugin", version = "1.3.21"))
                  ^
build.gradle.kts:17:1: error: unresolved reference: allprojects
allprojects {
^
build.gradle.kts:18:5: error: unresolved reference: repositories
    repositories {
    ^
build.gradle.kts:19:9: error: unresolved reference: google
        google()
        ^
build.gradle.kts:20:9: error: unresolved reference: jcenter
        jcenter()
        ^
build.gradle.kts:23:5: error: unresolved reference: ext
    ext {
    ^
build.gradle.kts:24:9: error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
@InlineOnly public inline operator fun <K, V> MutableMap<String, String>.set(key: String, value: String): Unit defined in kotlin.collections
@InlineOnly public inline operator fun kotlin.text.StringBuilder /* = java.lang.StringBuilder */.set(index: Int, value: Char): Unit defined in kotlin.text
        set("kotlinVersion", "1.3.21")
        ^
build.gradle.kts:28:1: error: unresolved reference: tasks
tasks.register("clean", Delete::class ) {
^
build.gradle.kts:28:25: error: unresolved reference: Delete
tasks.register("clean", Delete::class ) {
                        ^
build.gradle.kts:29:5: error: unresolved reference: delete
    delete(rootProject.buildDir)
    ^
build.gradle.kts:29:12: error: unresolved reference: rootProject
    delete(rootProject.buildDir)
s
it's not recognizing it as a kotlin file for some reason. is this from the command line?
k
this is not from the command line, this is from the IDE
s
could you try cli?
k
yes
ran
./gradlew clean && ./gradlew build
looks to be okay so far
s
👏🏽
k
Copy code
> Task :app:compileDebugKotlin
w: /home/kevin/code/android/Saddle/app/src/main/java/com/kevincianfarini/saddle/SaddleApplication.kt: (12, 14): 'appModule(AppModule!): DaggerAppComponent.Builder!' is deprecated. Deprecated in Java

> Task :app:compileReleaseKotlin
w: /home/kevin/code/android/Saddle/app/src/main/java/com/kevincianfarini/saddle/SaddleApplication.kt: (12, 14): 'appModule(AppModule!): DaggerAppComponent.Builder!' is deprecated. Deprecated in Java

> Task :app:lint
Ran lint on variant debug: 2 issues found
Ran lint on variant release: 2 issues found
Wrote HTML report to file:///home/kevin/code/android/Saddle/app/build/reports/lint-results.html
Wrote XML report to file:///home/kevin/code/android/Saddle/app/build/reports/lint-results.xml

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See <https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings>

BUILD SUCCESSFUL in 1m 3s
66 actionable tasks: 64 executed, 2 up-to-date
s
🎉
k
so, I'm still confused
s
go to AS and run a gradle refresh
message has been deleted
k
works, still no dice
s
ok, delete all your build directories. you can run clean inside AS or you can manually delete them.
k
should I be worried about this?
Copy code
warning: default scripting plugin is disabled: The provided plugin org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar is not compatible with this version of compiler
s
your kotlin plugin might be out of date?
k
hmmm
s
what version of gradle are you using?
k
kotlin plugin
v1.3.21-release-Studio3.4-1
not quite sure how to check gradle version
is this relevant?
com.android.tools.build:gradle:3.4.0"
thanks for the help, this is my first time doing something non trivial with gradle
s
gradle version will be in your gradle folder
gradle/wrapper/gradle-wrapper.properties
👍 1
I haven't done any android stuff so this is a first for me as well.
k
using 5.1.1
also, I invalidated caches and restarted AS
works now
but I still can't just run the kotlin script
I have to do a full build, which is fine I guess?
s
what do you mean you can't 'just run the kotlin script'?
k
nevermind, it's still not downloading dependencies I add
and
s
AS isn't?
or cli isn't?
k
right clicking in the editor of the gradle file and clicking "run"
s
that's not how gradle works.
k
works fine via the CLI with gradle wrapper
figured it wasn't lol
s
the gradle file isn't 'runnable'
you can use the tasks window in the Gradle panel
message has been deleted
or you can click the elephant at the top there and type in the commands you want to run
do you have AS set to delegate to gradle?
k
right okay, I was also doing that
It's still not resolving a dependency I just added to my module build.gradle
s
not*?
k
yes lol
s
ok
you can run with
--refresh-dependencies
or you can hit the refresh button
you might need to turn on
auto import
k
🤦‍♂️
duh
s
so did that work?
k
nope
just finished. Looked like the build was importing the dependencies but they're not showing up in the IDE
s
like you're getting red text?
or you don't see them in the
external dependencies
section?
k
I do they're there
what the heck is going on
Invalidated caches and it appeared
s
yeah it just sounds like you're having environment issues. nothing is wrong with your build.gradle.kts
k
yeah
thanks for all the help dude, I know that was super dumb lol
s
haha, no problem. didn't take much away from my time so you're all good.
good luck!
k
thanks
683 Views