rules_kotlin
rules_kotlin copied to clipboard
Can't build an aar
Running bazel build //lib:lib.aar for the android example produces this error:
AndroidManifest.xml:2: error: attribute 'package' in <manifest> tag is not a valid Android package name: 'lib'.
It seems like the package name is derived from the folder name and not from the custom_package attribute.
I tested it on legacy-1.3.0, legacy-1.4.0-rc3 and 1.5.0-alpha2. All of them finish with this error.
When I changed the folder name to sth containing a dot, e.g. lib.a then it worked but the result aar file was empty, i.e. it didn't contain any compiled classes or resources.
An empty jar file (without any compiled code) is also created when running bazel build //lib:lib.
Using android_library() instead of kt_android_library() (without any Kotlin code) produces correct results. It can be tested with Android-Bazel-Starter-Kotlin when you create a Java version of MainActivity.
halo @jin can u help to get around this issue? as aar is empty.
@bartek-wesolowski Can I ask what version of IntelliJ/Android Studio (AS) you are using? Asking because I haven't been able to build anything using Bazel on versions of AS > than 4.0.2.
@bohsen I was in fact using AS 4.0.2 for the Bazel plugin to work. In this case, however, I was running builds from the command line.
I've actually ran into this issue (at least the empty jar part) for my project. I had to implement a workaround to achieve a kotlin based aar library.
From my understanding, kt_android_library creates a few underlying targets which end up being a transitive dependency on the top level android_binary target (for creating my aar). The android_binary kind of just drops these transitive dependencies and results in the classes.jar within the aar to be empty.
To get around this issue, I created a genrule which manually stitches all these artifacts together appropriately and I was able to get things to work. However, it would be great if we can get better support here. An issue I was unable to work around is writing android unit tests with kotlin. This issue is still a problem for that use case as well but I'm not experienced enough (and not creative enough) to find a work around :(