-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop passing source jars in kt_jvm_import() to the DefaultInfo(files=…
…) attribute. (#221) * Don't include the source jar in the default info's files= attribute, which gets used in places to imply the compile deps, not all the files produced by the rule (such as source jars). This gets fed into the incremental dexing inputs in the android rules, resuling in #208 (which this commit should fix). * Add in an android application example with a `build_test()` and a CI pipeline to build/test it. Also normalize examples naming in CI. * Use the preferred form for kt_jvm_import in the core bits
- Loading branch information
Showing
14 changed files
with
229 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# Some examples have their own WORKSPACE. Ignore as part of this root WORKSPACE so | ||
# we don't break trying to build separate workspaces using wildcards like //... | ||
examples/trivial | ||
# examples/dagger doesn't have its own workspace, so don't do all of examples. | ||
examples/android | ||
examples/node | ||
examples/trivial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
RULES_JVM_EXTERNAL_TAG = "2.8" | ||
|
||
RULES_JVM_EXTERNAL_SHA = "79c9850690d7614ecdb72d68394f994fef7534b292c4867ce5e7dec0aa7bdfad" | ||
|
||
http_archive( | ||
name = "rules_jvm_external", | ||
sha256 = RULES_JVM_EXTERNAL_SHA, | ||
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, | ||
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, | ||
) | ||
|
||
load("@rules_jvm_external//:defs.bzl", "maven_install") | ||
|
||
maven_install( | ||
artifacts = [ | ||
"androidx.appcompat:appcompat:1.0.0", | ||
"junit:junit:4.12", | ||
"androidx.test.espresso:espresso-core:3.1.1", | ||
"org.hamcrest:hamcrest-library:1.3", | ||
], | ||
repositories = [ | ||
"https://jcenter.bintray.com/", | ||
"https://maven.google.com", | ||
"https://repo1.maven.org/maven2", | ||
], | ||
) | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "build_bazel_rules_android", | ||
sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806", | ||
strip_prefix = "rules_android-0.1.1", | ||
urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"], | ||
) | ||
|
||
load( | ||
"@build_bazel_rules_android//android:rules.bzl", | ||
"android_ndk_repository", | ||
"android_sdk_repository", | ||
) | ||
|
||
android_sdk_repository(name = "androidsdk") | ||
|
||
android_ndk_repository(name = "androidndk") # Required. Name *must* be "androidndk". | ||
|
||
# Directly load the kotlin rules from the parent repo. | ||
local_repository( | ||
name = "io_bazel_rules_kotlin", | ||
path = "../..", | ||
) | ||
|
||
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") | ||
|
||
kotlin_repositories() | ||
|
||
kt_register_toolchains() | ||
|
||
# Skylib, for build_test, so don't bother initializing the unit test infrastructure. | ||
http_archive( | ||
name = "bazel_skylib", | ||
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", | ||
urls = [ | ||
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
load("@build_bazel_rules_android//android:rules.bzl", "android_binary") | ||
load("@bazel_skylib//rules:build_test.bzl", "build_test") | ||
|
||
# An app that consumes android-kt deps | ||
android_binary( | ||
name = "app", | ||
custom_package = "examples.android.app", | ||
incremental_dexing = 0, | ||
manifest = "src/main/AndroidManifest.xml", | ||
multidex = "native", | ||
deps = [ | ||
"//lib", | ||
], | ||
) | ||
|
||
# An app that consumes jvm-kt libs | ||
android_binary( | ||
name = "app2", | ||
custom_package = "examples.android.app", | ||
incremental_dexing = 0, | ||
manifest = "src/main/AndroidManifest.xml", | ||
multidex = "native", | ||
deps = [ | ||
"//lib2", | ||
], | ||
) | ||
|
||
# An app that consumes android-kt deps, and does incremental dexing. | ||
android_binary( | ||
name = "app3", | ||
custom_package = "examples.android.app", | ||
incremental_dexing = 1, | ||
manifest = "src/main/AndroidManifest.xml", | ||
multidex = "native", | ||
deps = [ | ||
"//lib", | ||
], | ||
) | ||
|
||
build_test( | ||
name = "force_build_apks_test", | ||
targets = [ | ||
":app.apk", | ||
":app2.apk", | ||
":app3.apk", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="examples.android.app"> | ||
<uses-sdk android:minSdkVersion="23" | ||
android:targetSdkVersion="23" | ||
android:maxSdkVersion="29" /> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library") | ||
|
||
kt_android_library( | ||
name = "lib", | ||
srcs = glob(["src/main/kotlin/**/*.kt"]), | ||
custom_package = "examples.android.lib", | ||
manifest = "src/main/AndroidManifest.xml", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@maven//:androidx_appcompat_appcompat", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="examples.android.lib"/> |
22 changes: 22 additions & 0 deletions
22
examples/android/lib/src/main/kotlin/examples/android/lib/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package examples.android.lib | ||
|
||
import android.app.Activity | ||
import android.os.Bundle | ||
import android.widget.Button | ||
import android.widget.LinearLayout | ||
import android.widget.LinearLayout.LayoutParams | ||
import androidx.appcompat.app.AlertDialog | ||
|
||
class MainActivity : Activity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val parent = LinearLayout(this).apply { | ||
orientation = LinearLayout.VERTICAL | ||
}.also { it.addView(Button(this).apply { text = "Foo!" }) } | ||
setContentView(parent, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)) | ||
AlertDialog.Builder(this) | ||
.setTitle("Blah") | ||
.setMessage("Blah blah blah?") | ||
.show() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") | ||
load("@build_bazel_rules_android//android:rules.bzl", "android_library") | ||
|
||
android_library( | ||
name = "lib2", | ||
srcs = glob(["src/main/java/**/*.java"]), | ||
custom_package = "examples.android.lib2", | ||
manifest = "src/main/AndroidManifest.xml", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":util", | ||
"@maven//:androidx_appcompat_appcompat", | ||
], | ||
) | ||
|
||
kt_jvm_library( | ||
name = "util", | ||
srcs = glob(["src/main/kotlin/**/*.kt"]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="examples.android.lib2"/> |
25 changes: 25 additions & 0 deletions
25
examples/android/lib2/src/main/java/examples/android/lib2/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package examples.android.lib2; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.widget.Button; | ||
import android.widget.LinearLayout; | ||
import android.widget.LinearLayout.LayoutParams; | ||
import androidx.appcompat.app.AlertDialog; | ||
|
||
public class MainActivity extends Activity { | ||
@Override protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
LinearLayout parent = new LinearLayout(this); | ||
parent.setOrientation(LinearLayout.VERTICAL); | ||
Button button = new Button(this); | ||
button.setText("Foo!"); | ||
parent.addView(button); | ||
setContentView(parent, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); | ||
|
||
new AlertDialog.Builder(this) | ||
.setTitle("Blah") | ||
.setMessage("Blah blah blah?") | ||
.show(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
examples/android/lib2/src/main/kotlin/examples/android/lib2/Utils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package examples.android.lib2 | ||
|
||
class Blargh | ||
|
||
fun doStuff() { | ||
println("yay!") | ||
Blargh() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters