pubref / rules_kotlin

Bazel rules for Kotlin
Other
159 stars 20 forks source link

kotlin_library can't locate Android SDK #14

Closed aaronj1335 closed 7 years ago

aaronj1335 commented 7 years ago

Thanks for making these cool Kotlin rules for Bazel!

I was playing around with this in my aaronj1335/bazel-kotlin-android repo, but when I build, the kotlin_library can't find any of the Android SDK classes:

aaronstacy∂oɹdʞooqɔɐɯ-ʎɔɐʇsuoɹɐɐ ☠ ~/Downloads/test  10:56:05 May23
§ bazel build --strategy=KotlinCompile=standalone :app
INFO: Found 1 target...
ERROR: /Users/aaronstacy/Downloads/test/BUILD:13:1: null failed: kotlinc failed: error executing command bazel-out/host/bin/external/com_github_jetbrains_kotlin/kotlinc -d bazel-out/android-arm-linux-androideabi-4.9-v7a-gnu-libstdcpp-fastbuild/bin/main.jar main.kt: com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
/private/var/tmp/_bazel_aaronstacy/95464d7f40ee656ba804ea72b90dd3fa/execroot/test/main.kt:3:8: error: unresolved reference: android
import android.app.Activity
       ^
/private/var/tmp/_bazel_aaronstacy/95464d7f40ee656ba804ea72b90dd3fa/execroot/test/main.kt:4:8: error: unresolved reference: android
import android.os.Bundle
       ^
...
Target //:app failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2.452s, Critical Path: 2.28s

If I use and android_library rule and a Java file instead, it works (see the java_main rule).

Any idea how I could get this to correctly use the Android SDK to build kotlin_library's?

Also, my targets are:

§ bazel query //...:all
//:main
//:app
//:java_main
//:main_kt
aaronj1335 commented 7 years ago

UPDATE! I found the target name for the Android SDK is @bazel_tools//tools/android:sdk, but now I'm getting:

aaronstacy∂oɹdʞooqɔɐɯ-ʎɔɐʇsuoɹɐɐ ☠ ~/Downloads/test  11:33:08 May23
§ bazel build --strategy=KotlinCompile=standalone :app
ERROR: /Users/aaronstacy/Downloads/test/BUILD:21:1: in deps attribute of kotlin_compile rule //:main: '@androidsdk//:sdk-25' does not have mandatory provider 'kt'. Since this rule was created by the macro 'kotlin_library', the error might have been caused by the macro implementation in /Users/aaronstacy/Downloads/test/BUILD:21:1.
ERROR: Analysis of target '//:app' failed; build aborted.
INFO: Elapsed time: 0.152s
aaronj1335 commented 7 years ago

OK, latest update aaronj1335/bazel-kotlin-android@ef78498 is I've figured out how to target the Android SDK, but I get a bytecode version error:

aaronstacy∂oɹdʞooqɔɐɯ-ʎɔɐʇsuoɹɐɐ ☠ ~/Downloads/test  11:57:15 May23
§ bazel build --strategy=KotlinCompile=standalone :app
............
INFO: Found 1 target...
ERROR: /Users/aaronstacy/Downloads/test/BUILD:3:1: Converting bazel-out/local-fastbuild/bin/app_deploy.jar to dex format failed: Process exited with status 1 [sandboxed].

PARSE ERROR:
unsupported class file version 52.0
...while parsing android/Manifest.class
1 error; aborting
Use --strategy=AndroidDexer=standalone to disable sandboxing for the failing actions.
Target //:app failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 23.159s, Critical Path: 7.65s

Based on bazelbuild/bazel#2222, it looks like I might be able to build from source to fix this, we'll see.

aaronj1335 commented 7 years ago

I needed neverlink = 1 for the Android SDK java_import: aaronj1335/bazel-kotlin-android@4cc7690

pcj commented 7 years ago

Thanks for documenting it @aaronj1335, hopefully others will be able to learn from this.