Skip to navigation
Build an apk with bazel
21.06.24
# Install Bazel == ```console sudo apt install curl gnupg curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list sudo apt update && sudo apt install bazel sudo apt update && sudo apt full-upgrade ``` # Download the Bazel Tutorialsample ```console git clone https://github.com/bazelbuild/examples ``` # Enter the project and create the WORKSPACE file and add your SDK path variable ```console cd examples/android/tutorial/ touch WORKSPACE echo 'android_sdk_repository(name = "androidsdk")' > WORKSPACE ``` # Create the first BUILD file examples/android/tutorial/src/main/BUILD ```console cd src/main touch BUILD ``` ## the BUILD content for examples/android/tutorial/src/main/BUILD ```java android_binary( name = "app", manifest = "AndroidManifest.xml", deps = ["//src/main/java/com/example/bazel:greeter_activity"], ) ``` # Create another BUILD file examples/android/tutorial/src/main/java/com/example/bazel/BUILD ``` java package( default_visibility = ["//src:__subpackages__"], ) android_library( name = "greeter_activity", srcs = [ "Greeter.java", "MainActivity.java", ], manifest = "AndroidManifest.xml", resource_files = glob(["res/**"]), ) ``` # In your folder where the WORKSPACE file is located run: ```console bazel build //src/main:app ``` # In your folder examples/android/tutorial/bazel-bin/src/main/ you will find the APK file ```console file examples/android/tutorial/bazel-bin/src/main/app.apk ``` # Install it to your phone ```console adb install bazel-bin/src/main/app.apk ```
https://bazel.build/start/android-app
Reply
Anonymous
Information Epoch 1738775073
You can always add complexity.
Home
Notebook
Contact us