Skip to content

Commit

Permalink
Fixes part of #59: Utility module source files build with both Bazel …
Browse files Browse the repository at this point in the history
…+ Gradle [BLOCKED: #1481] (#1482)

* Working on having one module build with bazel

* Created initial app-level WORKSPACE file

* Added proto_library rule to build model app module

* Added newline at end of WORKSPACE file

* Created macro to process proto files

* Both Bazel and Gradle now build /model successfully

* Fixed typo in BUILD

* Added missing end of file empty lines

* Added Robolectric dependencies and general build rule

* Source files building in both systems - added a TODO for test files

* Turned two kt_android_library rules into one

* Added dependencies for test files

* Added a test manifest for android_local_test()

* Added Firebase dependencies and git_repository for tools_android

* Refactored google-services.json, imported new dependencies

* Fixed Bens nits

* Fixed space in WORKSPACE comment

* Got a demo test working in both Java and Kotlin

* Added rules_java dependencies for protocol buffers

* Added java_proto_library rules, each proto file now has its own rule

* Remove unnecessary srcs attribute for android_library

* Rename bzl file macro

* Changed to java_lite

* Each library now has its own build rule

* Utility is now one rule

* Changed visibility for utility_lib

* Added duplicate google-services.json file to please Gradle

* Changed event_logger.proto to oppia_logger.proto

* Added missing EOF newlines

* Fixed bug in import statements for exploration.proto, topic.proto, and question.proto

* Deleted DemoJava

* CHanged rules_kotlin version

* Added Firebase dependencies

* Removed AsyncResultTest example

* Removed unnecessary comments in WORKSPACE and moved rules_kotlin

* Added re-naming TODOs

* Renamed java_proto rules java_proto_lite

* Added doc comments to model/BUILD.bazel and format_import_proto_library

* Added comments to WORKSPACE file

* Fixed nits

* Added comment to kt_android_library() rule

* Fixed more nits

* Added Firebase comment

* Changed library name to model

* Formatted WORKSPACE comment

* Formatted TODO statement

* Changed format_import_proto_library comment

* Added EOF newline

* Created Issue and linked TODO in WORKSPACE

* Edited model BUILD file top comment

* Addressed nits

* Fixed nits and added comments

* Fixing nits

* Deleted unnecessary dependencies and testing example file

* Fixed manifest issues

* Move google json file

* Restore app version of json

* Edit TODO

* Deleted TODO

* Changed Firebase comment

* Added targetSDK to manifests

* Changed crashlytics_lib to crashlytics

* Fixed nits and added TODOs

* Changed targetSDK to 29

* Formatted TODO

* Moved google-services.json

* Added gogle-services.json back to app

* Formatted dependencies and removed unused dependency

* Updated dependency list

* Fixed the duplicate google-services.json issue

* Created Issue and added TODO

* Changed targetSdk to 28
  • Loading branch information
miaboloix authored Aug 9, 2020
1 parent 6b057d4 commit cf32435
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 4 deletions.
70 changes: 67 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ This file lists and imports all external dependencies needed to build Oppia Andr

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

# Android SDK configuration. For more details, see:
# https://docs.bazel.build/versions/master/be/android.html#android_sdk_repository
# TODO(#1542): Sync Android SDK version with the manifest.
android_sdk_repository(
name = "androidsdk",
api_level = 28,
build_tools_version = "28.0.2",
)

# Add support for JVM rules: https://github.com/bazelbuild/rules_jvm_external
Expand All @@ -24,8 +24,6 @@ http_archive(
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)

load("@rules_jvm_external//:defs.bzl", "maven_install")

# Add support for Kotlin: https://github.com/bazelbuild/rules_kotlin.
RULES_KOTLIN_VERSION = "legacy-1.4.0-rcx-oppia-exclusive-rc01"
RULES_KOTLIN_SHA = "600f3d916eda5531dd70614ec96dc92b4ac24da0e1d815eb94559976e9bea8aa"
Expand All @@ -36,6 +34,7 @@ http_archive(
strip_prefix = "rules_kotlin-%s" % RULES_KOTLIN_VERSION,
sha256 = RULES_KOTLIN_SHA,
)

# TODO(#1535): Remove once rules_kotlin is released because these lines become unnecessary
load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
kt_download_local_dev_dependencies()
Expand Down Expand Up @@ -73,3 +72,68 @@ http_archive(
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
rules_java_dependencies()
rules_java_toolchains()

# Add support for Dagger
DAGGER_TAG = "2.28.1"
DAGGER_SHA = "9e69ab2f9a47e0f74e71fe49098bea908c528aa02fa0c5995334447b310d0cdd"
http_archive(
name = "dagger",
strip_prefix = "dagger-dagger-%s" % DAGGER_TAG,
sha256 = DAGGER_SHA,
urls = ["https://github.com/google/dagger/archive/dagger-%s.zip" % DAGGER_TAG],
)

load("@dagger//:workspace_defs.bzl", "DAGGER_ARTIFACTS", "DAGGER_REPOSITORIES")

# Add support for Robolectric: https://github.com/robolectric/robolectric-bazel
http_archive(
name = "robolectric",
urls = ["https://github.com/oppia/robolectric-bazel/archive/4.x-oppia-exclusive-rc02.tar.gz"],
strip_prefix = "robolectric-bazel-4.x-oppia-exclusive-rc02",
)
load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")
robolectric_repositories()

# Add support for Firebase Crashlytics
git_repository(
name = "tools_android",
commit = "00e6f4b7bdd75911e33c618a9bc57bab7a6e8930",
remote = "https://github.com/bazelbuild/tools_android",
)

load("@tools_android//tools/googleservices:defs.bzl", "google_services_workspace_dependencies")
google_services_workspace_dependencies()

load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
artifacts = DAGGER_ARTIFACTS + [
"org.robolectric:robolectric:4.3",
"org.robolectric:annotations:4.3",
"androidx.appcompat:appcompat:1.0.2",
"androidx.core:core-ktx:1.0.1",
"androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha03",
"androidx.test.ext:junit:1.1.1",
"com.android.support:support-annotations:28.0.0",
"org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2",
"org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.2",
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:1.3.72",
"org.jetbrains.kotlin:kotlin-test-junit:1.3.72",
"com.google.truth:truth:0.43",
"com.google.firebase:firebase-analytics:17.4.4",
"com.google.firebase:firebase-crashlytics:17.1.1",
"com.crashlytics.sdk.android:crashlytics:2.9.8",
"io.fabric.sdk.android:fabric:1.4.7",
"com.github.bumptech.glide:glide:4.11.0",
"com.caverock:androidsvg-aar:1.4",
"org.mockito:mockito-core:2.19.0",
"junit:junit:4.12",
],
repositories = DAGGER_REPOSITORIES + [
"https://maven.google.com",
"https://repo1.maven.org/maven2",
"https://jcenter.bintray.com/",
"https://bintray.com/bintray/jcenter",
"https://maven.fabric.io/public",
],
)
35 changes: 35 additions & 0 deletions app/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# TODO(#1532): Rename file to 'BUILD' post-Gradle.
'''
Package for all Firebase dependencies.
To reference these dependencies, add '//app:crashlytics' and '//app:crashlytics_deps'
to your build rule's dependency list.
'''
load("@rules_jvm_external//:defs.bzl", "artifact")
load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@tools_android//tools/crashlytics:defs.bzl", "crashlytics_android_library")
load("@tools_android//tools/googleservices:defs.bzl", "google_services_xml")

package(default_visibility = ["//visibility:public"])

# TODO(#1566): Move Firebase rules to their own package
GOOGLE_SERVICES_RESOURCES = google_services_xml(
package_name = "org.oppia.app",
google_services_json = "google-services.json",
)

crashlytics_android_library(
name = "crashlytics",
package_name = "org.oppia.app",
build_id = "48fc9d17-e102-444c-8e0d-638d75ec0942",
resource_files = GOOGLE_SERVICES_RESOURCES,
)

android_library(
name = "crashlytics_deps",
exports = [
artifact("com.crashlytics.sdk.android:crashlytics"),
artifact("io.fabric.sdk.android:fabric"),
artifact("com.google.firebase:firebase-analytics"),
artifact("com.google.firebase:firebase-crashlytics"),
],
)
40 changes: 40 additions & 0 deletions utility/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# TODO(#1532): Rename file to 'BUILD' post-Gradle.
'''
This library contains utilities that all other modules, minus model, depend on.
It also contains Robolectric and JUnit tests for it's utilities.
In Bazel, Kotlin source files are built into a library using the kt_android_library() rule.
Kotlin test files must be built in their own kt_android_library() rule and added as a dependency to
an android_local_test() rule which configures instrumentation tests in Bazel.
'''

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
load("@rules_jvm_external//:defs.bzl", "artifact")
load("@dagger//:workspace_defs.bzl", "dagger_rules")

# Library for general-purpose utilities.
kt_android_library(
name = "utility",
custom_package = "org.oppia.util",
srcs = glob(["src/main/java/org/oppia/util/**/*.kt"]),
resource_files = glob(["src/main/res/**/*.xml"]),
manifest = "src/main/AndroidManifest.xml",
deps = [
":dagger",
"//model",
"//app:crashlytics",
"//app:crashlytics_deps",
artifact("org.jetbrains.kotlinx:kotlinx-coroutines-core"),
artifact("androidx.appcompat:appcompat"),
artifact("com.github.bumptech.glide:glide"),
artifact("com.caverock:androidsvg-aar"),
],
visibility = ["//visibility:public"],
)

# TODO(#59): Write a kt_android_library() rule to build test files and an android_local_test() rule.
'''
Because test files depend on the testing module source files being built, these rules have been left
for a later PR.
'''

dagger_rules()
6 changes: 5 additions & 1 deletion utility/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<manifest package="org.oppia.util"/>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.oppia.util">
<uses-sdk android:minSdkVersion="19"
android:targetSdkVersion="28" />
</manifest>
5 changes: 5 additions & 0 deletions utility/src/test/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.oppia.util">
<uses-sdk android:minSdkVersion="19"
android:targetSdkVersion="28" />
</manifest>

0 comments on commit cf32435

Please sign in to comment.