diff --git a/WORKSPACE b/WORKSPACE index 2d07384aba8..b63c57dc6a4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -4,6 +4,7 @@ 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 @@ -11,7 +12,6 @@ load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external") 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 @@ -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" @@ -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() @@ -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", + ], +) diff --git a/app/BUILD.bazel b/app/BUILD.bazel new file mode 100644 index 00000000000..f1e3fcf6d51 --- /dev/null +++ b/app/BUILD.bazel @@ -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"), + ], +) diff --git a/utility/BUILD.bazel b/utility/BUILD.bazel new file mode 100644 index 00000000000..b511f7fc1de --- /dev/null +++ b/utility/BUILD.bazel @@ -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() diff --git a/utility/src/main/AndroidManifest.xml b/utility/src/main/AndroidManifest.xml index 5a2a48aa161..0e527c3295d 100644 --- a/utility/src/main/AndroidManifest.xml +++ b/utility/src/main/AndroidManifest.xml @@ -1 +1,5 @@ - + + + diff --git a/utility/src/test/AndroidManifest.xml b/utility/src/test/AndroidManifest.xml new file mode 100644 index 00000000000..0e527c3295d --- /dev/null +++ b/utility/src/test/AndroidManifest.xml @@ -0,0 +1,5 @@ + + +