I am new in Android developtment usign Bazel.

I have put the @Keep annotation to prevent the obfuscation. To use it we need to import the library

import androidx.annotation.Keep;

In the project we've the following BUILD file located in

platform/android/car/src/main

After main folder we have these packages

  • java/com/company/car/engine
  • java/com/company/car/wheels
  • java/com/company/car/gearbox

The BUILD content is

    android_library(
     name = 'car',
     srcs = glob(["java/**/*.java"]),
     manifest = "AndroidManifest.xml",
     resource_files = glob(['res/**']),
     custom_package = android_package,
     deps = [
        ':jni_bindings',
        '@maven//:androidx_annotation_annotation',
     ],
     visibility = ["//visibility:public"],
     tags = ['maven_coordinates=%s:car-lite:{pom_version}' % android_package ],
    )

By default I've visibility = ["//car:__subpackages__"], changed to visibility = ["//visibility:public"], the problem persist.


ERROR: /workspace/platform/android/car/src/main/BUILD:24:16: in android_library rule //car/src/main:car: target '@maven//:androidx_annotation_annotation' is not visible from target '//car/src/main:car'. Check the visibility declaration of the former target if you think the dependency is legitimate
ERROR: /workspace/platform/android/car/src/main/BUILD:24:16: Analysis of target '//car/src/main:car' failed

Any idea about solve it?

Thanks


SOLUTION

In platform/android/WORKSPACE file I've

maven_install(
    artifacts = [
        "androidx.core:core-ktx:1.5.0",
        "androidx.appcompat:appcompat:1.2.0",
        "androidx.annotation:annotation:1.6.0"
    ],
    ...

Changing annotation from 1.6.0 to 1.5.0 the same has core-ktx solve my problem

1

There are 1 best solutions below

2
Pavan Singh On

Once you set visibility = ["//car:__subpackages__"], target will only be visible within the car package and its direct and indirect subpackages. However, changing "//visibility:public", grants access to all packages and its correct implementation.

If you can add the sample repo/error logs of the issue it would be easy to answer. Without error log its hard to comment. But am guessing you are missing some Java Rules but can be sure once you share error log.
You can also refer Android Rules and its implementation.

Thanks!