@@ -148,6 +148,115 @@ Includes all `kotlin_library` attributes as well as:
148148| ` main_class ` | ` string ` | Main class to run with the ` kotlin_binary ` rule |
149149
150150
151+ ### kotlin_android_library
152+
153+ A ` kotlin_android_library ` macro takes mostly the same arguments as a
154+ ` kotlin_library ` ,
155+ plus some Android specific arguments like
156+ ` aar_deps ` , ` resource_files ` , ` custom_package ` , ` manifest ` , etc.
157+ An example with combined source and resource:
158+
159+ ``` python
160+ PACKAGE = " com.company.app"
161+ MANIFEST = " AndroidManifest.xml"
162+
163+ kotlin_android_library(
164+ name = " src" ,
165+ srcs = glob([" src/**/*.kt" ]),
166+ custom_package = PACKAGE ,
167+ manifest = MANIFEST ,
168+ resource_files = glob([" res/**/*" ]),
169+ java_deps = [
170+ " @com_squareup_okhttp3_okhttp//jar" ,
171+ " @com_squareup_okio_okio//jar" ,
172+ ],
173+ aar_deps = [
174+ " @androidsdk//com.android.support:appcompat-v7-25.3.1" ,
175+ " @androidsdk//com.android.support:cardview-v7-25.3.1" ,
176+ " @androidsdk//com.android.support:recyclerview-v7-25.3.1" ,
177+ ],
178+ )
179+
180+ android_binary(
181+ name = " app" ,
182+ custom_package = PACKAGE ,
183+ manifest = MANIFEST ,
184+ deps = [
185+ " :src" ,
186+ ],
187+ )
188+ ```
189+
190+ If you prefer to separate your source files and resource files in
191+ different Bazel rules (for example the resource files are also used
192+ by java ` android_library ` rules), you can do so as example:
193+
194+ ``` python
195+ PACKAGE = " com.company.app"
196+ MANIFEST = " AndroidManifest.xml"
197+
198+ android_library(
199+ name = " res" ,
200+ custom_package = PACKAGE ,
201+ manifest = MANIFEST ,
202+ resource_files = glob([" res/**/*" ]),
203+ aar_deps = [
204+ " @androidsdk//com.android.support:appcompat-v7-25.3.1" ,
205+ " @androidsdk//com.android.support:cardview-v7-25.3.1" ,
206+ " @androidsdk//com.android.support:recyclerview-v7-25.3.1" ,
207+ ],
208+ )
209+
210+ android_library(
211+ name = " java" ,
212+ srcs = glob([" src/**/*.java" ]),
213+ deps = [
214+ " :res" ,
215+ # And other depedencies
216+ ]
217+ )
218+
219+ kotlin_android_library(
220+ name = " kt" ,
221+ srcs = glob([" src/**/*.kt" ]),
222+ aar_deps = [
223+ " @androidsdk//com.android.support:appcompat-v7-25.3.1" ,
224+ " @androidsdk//com.android.support:cardview-v7-25.3.1" ,
225+ " @androidsdk//com.android.support:recyclerview-v7-25.3.1" ,
226+ ],
227+ android_deps = [
228+ " :res" ,
229+ ]
230+ )
231+
232+ android_binary(
233+ name = " app" ,
234+ custom_package = PACKAGE ,
235+ manifest = MANIFEST ,
236+ deps = [
237+ " :java" ,
238+ " :kt" ,
239+ " :res" ,
240+ ],
241+ )
242+ ```
243+
244+ Please note that if you want to use ` R ` class in your Kotlin code,
245+ your ` kotlin_android_library ` rule need to either have the
246+ ` resource_files ` and related arguments,
247+ or have the resource rule in ` android_deps ` .
248+
249+ #### kotlin_android_library attributes
250+
251+ Includes all ` kotlin_library ` attributes as well as:
252+
253+ | Name | Type | Description |
254+ | --- | --- | --- |
255+ | ` aar_deps ` | ` label_list ` | List of AAR library targets |
256+
257+ And also [ ` android_library ` arguments] ( android_library ) .
258+
259+
151260### kotlin_test
152261
153262The ` kotlin_test ` rule is nearly identical the ` kotlin_binary ` rule
@@ -218,3 +327,4 @@ $ bazel test examples/helloworld:main_kt_test
218327
219328[ bazel ] : http://www.bazel.io
220329[ kotlin ] : http://www.kotlinlang.org
330+ [ android_library ] : https://docs.bazel.build/versions/master/be/android.html#android_library_args
0 commit comments